|
|
@@ -1,8 +1,12 @@
|
|
|
import { Request, Response, NextFunction } from 'express';
|
|
|
import createError from 'http-errors';
|
|
|
|
|
|
+import loggerFactory from '~/utils/logger';
|
|
|
+
|
|
|
import UserRegistrationOrder, { IUserRegistrationOrder } from '../models/user-registration-order';
|
|
|
|
|
|
+const logger = loggerFactory('growi:routes:user-activation');
|
|
|
+
|
|
|
export type ReqWithUserRegistrationOrder = Request & {
|
|
|
userRegistrationOrder: IUserRegistrationOrder
|
|
|
};
|
|
|
@@ -12,14 +16,18 @@ export default async(req: ReqWithUserRegistrationOrder, res: Response, next: Nex
|
|
|
const token = req.params.token || req.body.token;
|
|
|
|
|
|
if (token == null) {
|
|
|
- return next(createError(400, 'Token not found', { code: 'token-not-found' }));
|
|
|
+ const msg = 'Token not found';
|
|
|
+ logger.error(msg);
|
|
|
+ return next(createError(400, msg, { code: 'token-not-found' }));
|
|
|
}
|
|
|
|
|
|
const userRegistrationOrder = await UserRegistrationOrder.findOne({ token });
|
|
|
|
|
|
// check if the token is valid
|
|
|
if (userRegistrationOrder == null || userRegistrationOrder.isExpired() || userRegistrationOrder.isRevoked) {
|
|
|
- return next(createError(400, 'userRegistrationOrder is null or expired or revoked', { code: 'user-registration-order-is-not-appropriate' }));
|
|
|
+ const msg = 'userRegistrationOrder is null or expired or revoked';
|
|
|
+ logger.error(msg);
|
|
|
+ return next(createError(400, msg, { code: 'user-registration-order-is-not-appropriate' }));
|
|
|
}
|
|
|
|
|
|
req.userRegistrationOrder = userRegistrationOrder;
|