diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/users.ts | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 41ffb64cb..ac7c87517 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -70,7 +70,7 @@ usersRouter.post('/', | |||
70 | usersRouter.post('/register', | 70 | usersRouter.post('/register', |
71 | ensureUserRegistrationAllowed, | 71 | ensureUserRegistrationAllowed, |
72 | usersRegisterValidator, | 72 | usersRegisterValidator, |
73 | asyncMiddleware(registerUser) | 73 | asyncMiddleware(registerUserRetryWrapper) |
74 | ) | 74 | ) |
75 | 75 | ||
76 | usersRouter.put('/me', | 76 | usersRouter.put('/me', |
@@ -113,7 +113,7 @@ async function getUserVideos (req: express.Request, res: express.Response, next: | |||
113 | 113 | ||
114 | async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { | 114 | async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { |
115 | const options = { | 115 | const options = { |
116 | arguments: [ req, res ], | 116 | arguments: [ req ], |
117 | errorMessage: 'Cannot insert the user with many retries.' | 117 | errorMessage: 'Cannot insert the user with many retries.' |
118 | } | 118 | } |
119 | 119 | ||
@@ -123,7 +123,7 @@ async function createUserRetryWrapper (req: express.Request, res: express.Respon | |||
123 | return res.type('json').status(204).end() | 123 | return res.type('json').status(204).end() |
124 | } | 124 | } |
125 | 125 | ||
126 | async function createUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 126 | async function createUser (req: express.Request) { |
127 | const body: UserCreate = req.body | 127 | const body: UserCreate = req.body |
128 | const user = db.User.build({ | 128 | const user = db.User.build({ |
129 | username: body.username, | 129 | username: body.username, |
@@ -139,7 +139,18 @@ async function createUser (req: express.Request, res: express.Response, next: ex | |||
139 | logger.info('User %s with its channel and account created.', body.username) | 139 | logger.info('User %s with its channel and account created.', body.username) |
140 | } | 140 | } |
141 | 141 | ||
142 | async function registerUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 142 | async function registerUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { |
143 | const options = { | ||
144 | arguments: [ req ], | ||
145 | errorMessage: 'Cannot insert the user with many retries.' | ||
146 | } | ||
147 | |||
148 | await retryTransactionWrapper(registerUser, options) | ||
149 | |||
150 | return res.type('json').status(204).end() | ||
151 | } | ||
152 | |||
153 | async function registerUser (req: express.Request) { | ||
143 | const body: UserCreate = req.body | 154 | const body: UserCreate = req.body |
144 | 155 | ||
145 | const user = db.User.build({ | 156 | const user = db.User.build({ |
@@ -152,7 +163,8 @@ async function registerUser (req: express.Request, res: express.Response, next: | |||
152 | }) | 163 | }) |
153 | 164 | ||
154 | await createUserAccountAndChannel(user) | 165 | await createUserAccountAndChannel(user) |
155 | return res.type('json').status(204).end() | 166 | |
167 | logger.info('User %s with its channel and account registered.', body.username) | ||
156 | } | 168 | } |
157 | 169 | ||
158 | async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { | 170 | async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { |