aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/users.ts22
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('/',
70usersRouter.post('/register', 70usersRouter.post('/register',
71 ensureUserRegistrationAllowed, 71 ensureUserRegistrationAllowed,
72 usersRegisterValidator, 72 usersRegisterValidator,
73 asyncMiddleware(registerUser) 73 asyncMiddleware(registerUserRetryWrapper)
74) 74)
75 75
76usersRouter.put('/me', 76usersRouter.put('/me',
@@ -113,7 +113,7 @@ async function getUserVideos (req: express.Request, res: express.Response, next:
113 113
114async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { 114async 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
126async function createUser (req: express.Request, res: express.Response, next: express.NextFunction) { 126async 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
142async function registerUser (req: express.Request, res: express.Response, next: express.NextFunction) { 142async 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
153async 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
158async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { 170async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {