diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/users.ts | 30 |
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' |
29 | import { UserInstance } from '../../models' | ||
28 | 30 | ||
29 | const usersRouter = express.Router() | 31 | const usersRouter = express.Router() |
30 | 32 | ||
@@ -61,8 +63,8 @@ usersRouter.post('/', | |||
61 | 63 | ||
62 | usersRouter.post('/register', | 64 | usersRouter.post('/register', |
63 | ensureUserRegistrationAllowed, | 65 | ensureUserRegistrationAllowed, |
64 | usersAddValidator, | 66 | usersRegisterValidator, |
65 | createUser | 67 | registerUser |
66 | ) | 68 | ) |
67 | 69 | ||
68 | usersRouter.put('/me', | 70 | usersRouter.put('/me', |
@@ -99,11 +101,6 @@ export { | |||
99 | function createUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 101 | function 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 | ||
118 | function 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 | |||
121 | function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { | 135 | function 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 | ||
181 | function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 195 | function 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 |