|
|
@@ -8,6 +8,7 @@ import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
import type Crowi from '../../crowi';
|
|
|
import { generateAddActivityMiddleware } from '../../middlewares/add-activity';
|
|
|
+import * as applicationNotInstalled from '../../middlewares/application-not-installed';
|
|
|
import { registerRules, registerValidation } from '../../middlewares/register-form-validator';
|
|
|
import { InstallerService, FailedToCreateAdminUserError } from '../../service/installer';
|
|
|
|
|
|
@@ -27,6 +28,12 @@ module.exports = (crowi: Crowi): Router => {
|
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
|
+ // check application is not installed yet
|
|
|
+ router.use(
|
|
|
+ applicationNotInstalled.generateCheckerMiddleware(crowi),
|
|
|
+ applicationNotInstalled.handleAsApiError,
|
|
|
+ );
|
|
|
+
|
|
|
const minPasswordLength = configManager.getConfig('app:minPasswordLength');
|
|
|
|
|
|
/**
|
|
|
@@ -73,10 +80,6 @@ module.exports = (crowi: Crowi): Router => {
|
|
|
*/
|
|
|
// eslint-disable-next-line max-len
|
|
|
router.post('/', registerRules(minPasswordLength), registerValidation, addActivity, async(req: FormRequest, res: ApiV3Response) => {
|
|
|
- const appService = crowi.appService;
|
|
|
- if (appService == null) {
|
|
|
- return res.apiv3Err(new ErrorV3('GROWI cannot be installed due to an internal error', 'app_service_not_setup'), 500);
|
|
|
- }
|
|
|
|
|
|
if (!req.form.isValid) {
|
|
|
const errors = req.form.errors;
|
|
|
@@ -109,7 +112,7 @@ module.exports = (crowi: Crowi): Router => {
|
|
|
return res.apiv3Err(new ErrorV3(err, 'failed_to_install'));
|
|
|
}
|
|
|
|
|
|
- await appService.setupAfterInstall();
|
|
|
+ await crowi.appService.setupAfterInstall();
|
|
|
|
|
|
const parameters = { action: SupportedAction.ACTION_USER_REGISTRATION_SUCCESS };
|
|
|
activityEvent.emit('update', res.locals.activity._id, parameters);
|