|
|
@ -5,7 +5,7 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import { Router, Request, Response, NextFunction } from 'express';
|
|
|
|
import { Router, Request, Response, NextFunction } from 'express';
|
|
|
|
import { findFromToken, setUserPassword, users, createNewUser, deleteUser, setUserMeta, deleteUserMeta, verifyCliKey } from '../auth';
|
|
|
|
import { findFromToken, setUserPassword, users, createNewUser, deleteUser, setUserMeta, deleteUserMeta, setUsername, verifyCliKey } from '../auth';
|
|
|
|
import { log } from '../utils';
|
|
|
|
import { log } from '../utils';
|
|
|
|
import { data } from '../data';
|
|
|
|
import { data } from '../data';
|
|
|
|
import { User } from '../types/auth';
|
|
|
|
import { User } from '../types/auth';
|
|
|
@ -124,6 +124,20 @@ function buildUserRouter() {
|
|
|
|
.catch((err) => errorHandler(res, err));
|
|
|
|
.catch((err) => errorHandler(res, err));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sets a username
|
|
|
|
|
|
|
|
// Admin only
|
|
|
|
|
|
|
|
userRouter.put('/username/:id', adminAuthMiddleware, (req: Request, res: Response) => {
|
|
|
|
|
|
|
|
const id = req.params.id;
|
|
|
|
|
|
|
|
const username: string | undefined = req.body.username;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (username == null || username.length === 0)
|
|
|
|
|
|
|
|
return res.sendStatus(400);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setUsername(id, username)
|
|
|
|
|
|
|
|
.then(() => res.sendStatus(200))
|
|
|
|
|
|
|
|
.catch((err) => errorHandler(res, err));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Delete a user meta key
|
|
|
|
// Delete a user meta key
|
|
|
|
// Admin only
|
|
|
|
// Admin only
|
|
|
|
userRouter.delete('/meta/:id', adminAuthMiddleware, (req: Request, res: Response) => {
|
|
|
|
userRouter.delete('/meta/:id', adminAuthMiddleware, (req: Request, res: Response) => {
|
|
|
|