From 77a5501f6413aff2f2a626b929dfda486fa9a3e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 6 Sep 2017 16:35:40 +0200 Subject: Fix tests and user quota --- server/controllers/api/users.ts | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 6922661ae..1ecaaf93f 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -8,6 +8,7 @@ import { ensureIsAdmin, ensureUserRegistrationAllowed, usersAddValidator, + usersRegisterValidator, usersUpdateValidator, usersUpdateMeValidator, usersRemoveValidator, @@ -25,6 +26,7 @@ import { UserUpdate, UserUpdateMe } from '../../../shared' +import { UserInstance } from '../../models' const usersRouter = express.Router() @@ -61,8 +63,8 @@ usersRouter.post('/', usersRouter.post('/register', ensureUserRegistrationAllowed, - usersAddValidator, - createUser + usersRegisterValidator, + registerUser ) usersRouter.put('/me', @@ -99,11 +101,6 @@ export { function createUser (req: express.Request, res: express.Response, next: express.NextFunction) { const body: UserCreate = req.body - // On registration, we set the user video quota - if (body.videoQuota === undefined) { - body.videoQuota = CONFIG.USER.VIDEO_QUOTA - } - const user = db.User.build({ username: body.username, password: body.password, @@ -118,6 +115,23 @@ function createUser (req: express.Request, res: express.Response, next: express. .catch(err => next(err)) } +function registerUser (req: express.Request, res: express.Response, next: express.NextFunction) { + const body: UserCreate = req.body + + const user = db.User.build({ + username: body.username, + password: body.password, + email: body.email, + displayNSFW: false, + role: USER_ROLES.USER, + videoQuota: CONFIG.USER.VIDEO_QUOTA + }) + + user.save() + .then(() => res.type('json').status(204).end()) + .catch(err => next(err)) +} + function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { db.User.loadByUsername(res.locals.oauth.token.user.username) .then(user => res.json(user.toFormattedJSON())) @@ -180,7 +194,7 @@ function updateMe (req: express.Request, res: express.Response, next: express.Ne function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) { const body: UserUpdate = req.body - const user = res.locals.user + const user: UserInstance = res.locals.user if (body.email !== undefined) user.email = body.email if (body.videoQuota !== undefined) user.videoQuota = body.videoQuota -- cgit v1.2.3