aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/users.ts')
-rw-r--r--server/controllers/api/users.ts30
1 files changed, 22 insertions, 8 deletions
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 {
8 ensureIsAdmin, 8 ensureIsAdmin,
9 ensureUserRegistrationAllowed, 9 ensureUserRegistrationAllowed,
10 usersAddValidator, 10 usersAddValidator,
11 usersRegisterValidator,
11 usersUpdateValidator, 12 usersUpdateValidator,
12 usersUpdateMeValidator, 13 usersUpdateMeValidator,
13 usersRemoveValidator, 14 usersRemoveValidator,
@@ -25,6 +26,7 @@ import {
25 UserUpdate, 26 UserUpdate,
26 UserUpdateMe 27 UserUpdateMe
27} from '../../../shared' 28} from '../../../shared'
29import { UserInstance } from '../../models'
28 30
29const usersRouter = express.Router() 31const usersRouter = express.Router()
30 32
@@ -61,8 +63,8 @@ usersRouter.post('/',
61 63
62usersRouter.post('/register', 64usersRouter.post('/register',
63 ensureUserRegistrationAllowed, 65 ensureUserRegistrationAllowed,
64 usersAddValidator, 66 usersRegisterValidator,
65 createUser 67 registerUser
66) 68)
67 69
68usersRouter.put('/me', 70usersRouter.put('/me',
@@ -99,11 +101,6 @@ export {
99function createUser (req: express.Request, res: express.Response, next: express.NextFunction) { 101function createUser (req: express.Request, res: express.Response, next: express.NextFunction) {
100 const body: UserCreate = req.body 102 const body: UserCreate = req.body
101 103
102 // On registration, we set the user video quota
103 if (body.videoQuota === undefined) {
104 body.videoQuota = CONFIG.USER.VIDEO_QUOTA
105 }
106
107 const user = db.User.build({ 104 const user = db.User.build({
108 username: body.username, 105 username: body.username,
109 password: body.password, 106 password: body.password,
@@ -118,6 +115,23 @@ function createUser (req: express.Request, res: express.Response, next: express.
118 .catch(err => next(err)) 115 .catch(err => next(err))
119} 116}
120 117
118function registerUser (req: express.Request, res: express.Response, next: express.NextFunction) {
119 const body: UserCreate = req.body
120
121 const user = db.User.build({
122 username: body.username,
123 password: body.password,
124 email: body.email,
125 displayNSFW: false,
126 role: USER_ROLES.USER,
127 videoQuota: CONFIG.USER.VIDEO_QUOTA
128 })
129
130 user.save()
131 .then(() => res.type('json').status(204).end())
132 .catch(err => next(err))
133}
134
121function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { 135function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {
122 db.User.loadByUsername(res.locals.oauth.token.user.username) 136 db.User.loadByUsername(res.locals.oauth.token.user.username)
123 .then(user => res.json(user.toFormattedJSON())) 137 .then(user => res.json(user.toFormattedJSON()))
@@ -180,7 +194,7 @@ function updateMe (req: express.Request, res: express.Response, next: express.Ne
180 194
181function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) { 195function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) {
182 const body: UserUpdate = req.body 196 const body: UserUpdate = req.body
183 const user = res.locals.user 197 const user: UserInstance = res.locals.user
184 198
185 if (body.email !== undefined) user.email = body.email 199 if (body.email !== undefined) user.email = body.email
186 if (body.videoQuota !== undefined) user.videoQuota = body.videoQuota 200 if (body.videoQuota !== undefined) user.videoQuota = body.videoQuota