-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
imprv: Behavior when creating first user fails #8801
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,16 +1,16 @@ | ||||||||||
import { ErrorV3 } from '@growi/core/dist/models'; | ||||||||||
import express, { Request, Router } from 'express'; | ||||||||||
import type { Request, Router } from 'express'; | ||||||||||
import express from 'express'; | ||||||||||
|
||||||||||
import { SupportedAction } from '~/interfaces/activity'; | ||||||||||
import loggerFactory from '~/utils/logger'; | ||||||||||
|
||||||||||
import Crowi from '../../crowi'; | ||||||||||
import type Crowi from '../../crowi'; | ||||||||||
import { generateAddActivityMiddleware } from '../../middlewares/add-activity'; | ||||||||||
import { apiV3FormValidator } from '../../middlewares/apiv3-form-validator'; | ||||||||||
import { registerRules } from '../../middlewares/register-form-validator'; | ||||||||||
import { registerRules, registerValidation } from '../../middlewares/register-form-validator'; | ||||||||||
import { InstallerService, FailedToCreateAdminUserError } from '../../service/installer'; | ||||||||||
|
||||||||||
import { ApiV3Response } from './interfaces/apiv3-response'; | ||||||||||
import type { ApiV3Response } from './interfaces/apiv3-response'; | ||||||||||
|
||||||||||
|
||||||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||||||||||
|
@@ -27,51 +27,57 @@ | |||||||||
const router = express.Router(); | ||||||||||
|
||||||||||
// eslint-disable-next-line max-len | ||||||||||
router.post('/', registerRules(), apiV3FormValidator, addActivity, async(req: FormRequest, res: ApiV3Response) => { | ||||||||||
router.post('/', registerRules(), registerValidation, addActivity, async(req: FormRequest, res: ApiV3Response) => { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. apiV3FormValidator middleware ではなく registerRules() に対応する registerValidation middleware を利用するように変更。 |
||||||||||
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; | ||||||||||
return res.apiv3Err(errors, 400); | ||||||||||
} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /register にならって追記。Validation に失敗したらここでエラーを返却する。 growi/apps/app/src/server/routes/login.js Lines 137 to 140 in d92b768
|
||||||||||
|
||||||||||
const registerForm = req.body.registerForm || {}; | ||||||||||
|
||||||||||
const name = registerForm.name; | ||||||||||
const username = registerForm.username; | ||||||||||
const email = registerForm.email; | ||||||||||
const password = registerForm.password; | ||||||||||
const language = registerForm['app:globalLang'] || 'en_US'; | ||||||||||
|
||||||||||
const installerService = new InstallerService(crowi); | ||||||||||
|
||||||||||
let adminUser; | ||||||||||
try { | ||||||||||
adminUser = await installerService.install({ | ||||||||||
name, | ||||||||||
username, | ||||||||||
email, | ||||||||||
password, | ||||||||||
}, language); | ||||||||||
} | ||||||||||
catch (err) { | ||||||||||
if (err instanceof FailedToCreateAdminUserError) { | ||||||||||
return res.apiv3Err(new ErrorV3(err.message, 'failed_to_create_admin_user')); | ||||||||||
} | ||||||||||
return res.apiv3Err(new ErrorV3(err, 'failed_to_install')); | ||||||||||
} | ||||||||||
|
||||||||||
await appService.setupAfterInstall(); | ||||||||||
|
||||||||||
const parameters = { action: SupportedAction.ACTION_USER_REGISTRATION_SUCCESS }; | ||||||||||
activityEvent.emit('update', res.locals.activity._id, parameters); | ||||||||||
|
||||||||||
// login with passport | ||||||||||
req.logIn(adminUser, (err) => { | ||||||||||
if (err != null) { | ||||||||||
return res.apiv3Err(new ErrorV3(err, 'failed_to_login_after_install')); | ||||||||||
} | ||||||||||
|
||||||||||
return res.apiv3({ message: 'Installation completed (Logged in as an admin user)' }); | ||||||||||
}); | ||||||||||
}); | ||||||||||
Check failure Code scanning / CodeQL Missing rate limiting High
This route handler performs
authorization Error loading related location Loading |
||||||||||
|
||||||||||
return router; | ||||||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LoginForm.tsx にならってサーバーからのエラー結果を form 上部のアラートに表示するようにした
growi/apps/app/src/components/LoginForm/LoginForm.tsx
Lines 356 to 366 in d92b768