-function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {
- db.User.loadByUsername(res.locals.oauth.token.user.username)
- .then(user => res.json(user.toFormatedJSON()))
- .catch(err => next(err))
+async function registerUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const options = {
+ arguments: [ req ],
+ errorMessage: 'Cannot insert the user with many retries.'
+ }
+
+ await retryTransactionWrapper(registerUser, options)
+
+ return res.type('json').status(204).end()
+}
+
+async function registerUser (req: express.Request) {
+ const body: UserCreate = req.body
+
+ const user = db.User.build({
+ username: body.username,
+ password: body.password,
+ email: body.email,
+ displayNSFW: false,
+ role: UserRole.USER,
+ videoQuota: CONFIG.USER.VIDEO_QUOTA
+ })
+
+ await createUserAccountAndChannel(user)
+
+ logger.info('User %s with its channel and account registered.', body.username)
+}
+
+async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {
+ // We did not load channels in res.locals.user
+ const user = await db.User.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username)
+
+ return res.json(user.toFormattedJSON())
+}
+
+function getUser (req: express.Request, res: express.Response, next: express.NextFunction) {
+ return res.json(res.locals.user.toFormattedJSON())