|
|
@@ -3,6 +3,10 @@ import path from 'path';
|
|
|
import { ErrorV3 } from '@growi/core';
|
|
|
import { body, validationResult } from 'express-validator';
|
|
|
|
|
|
+import loggerFactory from '~/utils/logger';
|
|
|
+
|
|
|
+const logger = loggerFactory('growi:routes:apiv3:user-activation');
|
|
|
+
|
|
|
const PASSOWRD_MINIMUM_NUMBER = 8;
|
|
|
|
|
|
// validation rules for complete registration form
|
|
|
@@ -70,11 +74,16 @@ export const completeRegistrationAction = (crowi) => {
|
|
|
return res.apiv3Err(new ErrorV3('You have been logged in', 'registration-failed'), 403);
|
|
|
}
|
|
|
|
|
|
- // config で closed ならさよなら
|
|
|
+ // error when registration is not allowed
|
|
|
if (configManager.getConfig('crowi', 'security:registrationMode') === aclService.labels.SECURITY_REGISTRATION_MODE_CLOSED) {
|
|
|
return res.apiv3Err(new ErrorV3('Registration closed', 'registration-failed'), 403);
|
|
|
}
|
|
|
|
|
|
+ // error when email authentication is disabled
|
|
|
+ if (configManager.getConfig('crowi', 'security:passport-local:isEmailAuthenticationEnabled') !== true) {
|
|
|
+ return res.apiv3Err(new ErrorV3('Email authentication configuration is disabled', 'registration-failed'), 403);
|
|
|
+ }
|
|
|
+
|
|
|
const { userRegistrationOrder } = req;
|
|
|
const registerForm = req.body;
|
|
|
|
|
|
@@ -105,17 +114,6 @@ export const completeRegistrationAction = (crowi) => {
|
|
|
return res.apiv3Err(new ErrorV3(errorMessage, 'registration-failed'), 403);
|
|
|
}
|
|
|
|
|
|
- if (configManager.getConfig('crowi', 'security:passport-local:isEmailAuthenticationEnabled') !== true) {
|
|
|
- return res.apiv3Err(new ErrorV3('Email authentication configuration is disabled', 'registration-failed'), 403);
|
|
|
- }
|
|
|
-
|
|
|
- const registrationMode = configManager.getConfig('crowi', 'security:registrationMode');
|
|
|
- const isMailerSetup = mailService.isMailerSetup ?? false;
|
|
|
-
|
|
|
- if (!isMailerSetup && registrationMode === aclService.labels.SECURITY_REGISTRATION_MODE_RESTRICTED) {
|
|
|
- return res.apiv3Err(new ErrorV3('E-mail Settings must be set up.', 'registration-failed'), 403);
|
|
|
- }
|
|
|
-
|
|
|
User.createUserByEmailAndPassword(name, username, email, password, undefined, async(err, userData) => {
|
|
|
if (err) {
|
|
|
if (err.name === 'UserUpperLimitException') {
|
|
|
@@ -129,13 +127,22 @@ export const completeRegistrationAction = (crowi) => {
|
|
|
|
|
|
userRegistrationOrder.revokeOneTimeToken();
|
|
|
|
|
|
- if (registrationMode === aclService.labels.SECURITY_REGISTRATION_MODE_RESTRICTED) {
|
|
|
- const admins = await User.findAdmins();
|
|
|
- const appTitle = appService.getAppTitle();
|
|
|
- const template = path.join(crowi.localeDir, 'en_US/admin/userWaitingActivation.txt');
|
|
|
- const url = appService.getSiteUrl();
|
|
|
+ if (configManager.getConfig('crowi', 'security:registrationMode') === aclService.labels.SECURITY_REGISTRATION_MODE_RESTRICTED) {
|
|
|
+ const isMailerSetup = mailService.isMailerSetup ?? false;
|
|
|
+
|
|
|
+ if (isMailerSetup) {
|
|
|
+ const admins = await User.findAdmins();
|
|
|
+ const appTitle = appService.getAppTitle();
|
|
|
+ const template = path.join(crowi.localeDir, 'en_US/admin/userWaitingActivation.txt');
|
|
|
+ const url = appService.getSiteUrl();
|
|
|
|
|
|
- sendEmailToAllAdmins(userData, admins, appTitle, mailService, template, url);
|
|
|
+ sendEmailToAllAdmins(userData, admins, appTitle, mailService, template, url);
|
|
|
+ }
|
|
|
+ // This 'completeRegistrationAction' should not be able to be called if the email settings is not set up in the first place.
|
|
|
+ // So this method dows not stop processing as an error, but only displays a warning. -- 2022.11.01 Yuki Takei
|
|
|
+ else {
|
|
|
+ logger.warn('E-mail Settings must be set up.');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
req.flash('successMessage', req.t('message.successfully_created', { username }));
|