diff options
Diffstat (limited to 'server/controllers/api/users.ts')
-rw-r--r-- | server/controllers/api/users.ts | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 0ca9b337a..aced4639e 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -13,7 +13,7 @@ import { sendUpdateUser } from '../../lib/activitypub/send' | |||
13 | import { createUserAccountAndChannel } from '../../lib/user' | 13 | import { createUserAccountAndChannel } from '../../lib/user' |
14 | import { | 14 | import { |
15 | asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setDefaultSort, | 15 | asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setDefaultSort, |
16 | setPagination, token, usersAddValidator, usersGetValidator, usersRegisterValidator, usersRemoveValidator, usersSortValidator, | 16 | setDefaultPagination, token, usersAddValidator, usersGetValidator, usersRegisterValidator, usersRemoveValidator, usersSortValidator, |
17 | usersUpdateMeValidator, usersUpdateValidator, usersVideoRatingValidator | 17 | usersUpdateMeValidator, usersUpdateValidator, usersVideoRatingValidator |
18 | } from '../../middlewares' | 18 | } from '../../middlewares' |
19 | import { usersUpdateMyAvatarValidator, videosSortValidator } from '../../middlewares/validators' | 19 | import { usersUpdateMyAvatarValidator, videosSortValidator } from '../../middlewares/validators' |
@@ -40,7 +40,7 @@ usersRouter.get('/me/videos', | |||
40 | paginationValidator, | 40 | paginationValidator, |
41 | videosSortValidator, | 41 | videosSortValidator, |
42 | setDefaultSort, | 42 | setDefaultSort, |
43 | setPagination, | 43 | setDefaultPagination, |
44 | asyncMiddleware(getUserVideos) | 44 | asyncMiddleware(getUserVideos) |
45 | ) | 45 | ) |
46 | 46 | ||
@@ -56,7 +56,7 @@ usersRouter.get('/', | |||
56 | paginationValidator, | 56 | paginationValidator, |
57 | usersSortValidator, | 57 | usersSortValidator, |
58 | setDefaultSort, | 58 | setDefaultSort, |
59 | setPagination, | 59 | setDefaultPagination, |
60 | asyncMiddleware(listUsers) | 60 | asyncMiddleware(listUsers) |
61 | ) | 61 | ) |
62 | 62 | ||
@@ -129,15 +129,19 @@ async function createUserRetryWrapper (req: express.Request, res: express.Respon | |||
129 | errorMessage: 'Cannot insert the user with many retries.' | 129 | errorMessage: 'Cannot insert the user with many retries.' |
130 | } | 130 | } |
131 | 131 | ||
132 | await retryTransactionWrapper(createUser, options) | 132 | const { user, account } = await retryTransactionWrapper(createUser, options) |
133 | 133 | ||
134 | // TODO : include Location of the new user -> 201 | 134 | return res.json({ |
135 | return res.type('json').status(204).end() | 135 | user: { |
136 | id: user.id, | ||
137 | uuid: account.uuid | ||
138 | } | ||
139 | }).end() | ||
136 | } | 140 | } |
137 | 141 | ||
138 | async function createUser (req: express.Request) { | 142 | async function createUser (req: express.Request) { |
139 | const body: UserCreate = req.body | 143 | const body: UserCreate = req.body |
140 | const user = new UserModel({ | 144 | const userToCreate = new UserModel({ |
141 | username: body.username, | 145 | username: body.username, |
142 | password: body.password, | 146 | password: body.password, |
143 | email: body.email, | 147 | email: body.email, |
@@ -147,9 +151,11 @@ async function createUser (req: express.Request) { | |||
147 | videoQuota: body.videoQuota | 151 | videoQuota: body.videoQuota |
148 | }) | 152 | }) |
149 | 153 | ||
150 | await createUserAccountAndChannel(user) | 154 | const { user, account } = await createUserAccountAndChannel(userToCreate) |
151 | 155 | ||
152 | logger.info('User %s with its channel and account created.', body.username) | 156 | logger.info('User %s with its channel and account created.', body.username) |
157 | |||
158 | return { user, account } | ||
153 | } | 159 | } |
154 | 160 | ||
155 | async function registerUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { | 161 | async function registerUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { |