2
0
jam411 3 жил өмнө
parent
commit
2bc22f7dd7

+ 8 - 4
packages/app/src/components/InvitedForm.tsx

@@ -7,6 +7,7 @@ import { apiv3Post } from '~/client/util/apiv3-client';
 
 import { useCsrfToken, useCurrentUser } from '../stores/context';
 
+
 export type InvitedFormProps = {
   invitedFormUsername: string,
   invitedFormName: string,
@@ -16,7 +17,7 @@ export const InvitedForm = (props: InvitedFormProps): JSX.Element => {
   const { t } = useTranslation();
   // const { data: csrfToken } = useCsrfToken();
   const { data: user } = useCurrentUser();
-  const router = useRouter();
+  // const router = useRouter();
 
   const { invitedFormUsername, invitedFormName } = props;
 
@@ -29,22 +30,25 @@ export const InvitedForm = (props: InvitedFormProps): JSX.Element => {
     e.preventDefault();
 
     const invitedUserInfo = {
+      email: 'ryoji.s0411@gmail.com',
       username: usernameForInvited,
       name: userForInvited,
       password: passwordForInvited,
     };
-
+    console.log('test');
     try {
       const res = await apiv3Post('/invited/activateInvited', { invitedUserInfo });
+      console.log(invitedUserInfo);
       const { redirectTo } = res.data;
-      router.push(redirectTo);
+      console.log(redirectTo);
+      // router.push(redirectTo);
     }
     catch (err) {
       setLoginErrors(err);
     }
     return;
 
-  }, [usernameForInvited, userForInvited, passwordForInvited, router]);
+  }, [usernameForInvited, userForInvited, passwordForInvited]);
 
   if (user == null) {
     return <></>;

+ 10 - 9
packages/app/src/server/middlewares/login-form-validator.ts

@@ -5,19 +5,19 @@ export const inviteRules = () => {
   return [
     body('invitedForm.username')
       .matches(/^[\da-zA-Z\-_.]+$/)
-      .withMessage('Username has invalid characters')
+      .withMessage('message.Username has invalid characters')
       .not()
       .isEmpty()
-      .withMessage('Username field is required'),
-    body('invitedForm.name').not().isEmpty().withMessage('Name field is required'),
+      .withMessage('message.Username field is required'),
+    body('invitedForm.name').not().isEmpty().withMessage('message.Name field is required'),
     body('invitedForm.password')
       .matches(/^[\x20-\x7F]*$/)
-      .withMessage('Password has invalid character')
+      .withMessage('message.Password has invalid character')
       .isLength({ min: 6 })
-      .withMessage('Password minimum character should be more than 6 characters')
+      .withMessage('message.Password minimum character should be more than 6 characters')
       .not()
       .isEmpty()
-      .withMessage('Password field is required'),
+      .withMessage('message.Password field is required'),
   ];
 };
 
@@ -35,9 +35,10 @@ export const inviteValidation = (req, res, next) => {
   const extractedErrors: string[] = [];
   errors.array().map(err => extractedErrors.push(err.msg));
 
-  req.flash('errorMessages', extractedErrors);
-
-  Object.assign(form, { isValid: false });
+  Object.assign(form, {
+    isValid: false,
+    errors: extractedErrors,
+  });
   req.form = form;
 
   return next();

+ 1 - 1
packages/app/src/server/routes/apiv3/index.js

@@ -50,7 +50,7 @@ module.exports = (crowi, app) => {
   routerForAuth.post('/register',
     applicationInstalled, registerFormValidator.registerRules(), registerFormValidator.registerValidation, addActivity, login.register);
 
-  routerForAuth.post('/refister/activated',
+  routerForAuth.post('/invited/activateInvited',
     applicationInstalled, loginFormValidator.inviteRules(), loginFormValidator.inviteValidation, login.invited);
 
   router.use('/in-app-notification', require('./in-app-notification')(crowi));