Просмотр исходного кода

Change error messages by Error object

Shun Miyazawa 1 год назад
Родитель
Сommit
55b62bd025

+ 1 - 1
apps/app/public/static/locales/en_US/translation.json

@@ -671,7 +671,7 @@
     "Email format is invalid": "Email format is invalid.",
     "Email format is invalid": "Email format is invalid.",
     "Email field is required": "Email field is required.",
     "Email field is required": "Email field is required.",
     "Password has invalid character": "Password has invalid character.",
     "Password has invalid character": "Password has invalid character.",
-    "Password minimum character should be more than 8 characters": "Password minimum character should be more than 8 characters.",
+    "Password minimum character should be more than n characters": "Password minimum character should be more than {{number}} characters.",
     "Password field is required": "Password field is required.",
     "Password field is required": "Password field is required.",
     "Username or E-mail has invalid characters": "Username or E-mail has invalid characters.",
     "Username or E-mail has invalid characters": "Username or E-mail has invalid characters.",
     "Password minimum character should be more than 6 characters": "Password minimum character should be more than 6 characters.",
     "Password minimum character should be more than 6 characters": "Password minimum character should be more than 6 characters.",

+ 1 - 1
apps/app/public/static/locales/fr_FR/translation.json

@@ -665,7 +665,7 @@
     "Email format is invalid": "Format d'adresse courriel invalide.",
     "Email format is invalid": "Format d'adresse courriel invalide.",
     "Email field is required": "Adresse courriel requise.",
     "Email field is required": "Adresse courriel requise.",
     "Password has invalid character": "Le mot de passe contient des caractères invalides",
     "Password has invalid character": "Le mot de passe contient des caractères invalides",
-    "Password minimum character should be more than 8 characters": "Le mot de passe doit contenir plus de 8 caractères.",
+    "Password minimum character should be more than n characters": "Le mot de passe doit contenir plus de {{number}} caractères.",
     "Password field is required": "Mot de passe requis.",
     "Password field is required": "Mot de passe requis.",
     "Username or E-mail has invalid characters": "Le nom d'utilisateur ou l'adresse courriel contient des caractères invalides",
     "Username or E-mail has invalid characters": "Le nom d'utilisateur ou l'adresse courriel contient des caractères invalides",
     "Password minimum character should be more than 6 characters": "Le mot de passe doit contenir au moins 6 caractères.",
     "Password minimum character should be more than 6 characters": "Le mot de passe doit contenir au moins 6 caractères.",

+ 1 - 1
apps/app/public/static/locales/ja_JP/translation.json

@@ -704,7 +704,7 @@
     "Email format is invalid": "メールアドレスのフォーマットが無効です",
     "Email format is invalid": "メールアドレスのフォーマットが無効です",
     "Email field is required": "メールアドレスは必須項目です",
     "Email field is required": "メールアドレスは必須項目です",
     "Password has invalid character": "パスワードに無効な文字があります",
     "Password has invalid character": "パスワードに無効な文字があります",
-    "Password minimum character should be more than 8 characters": "パスワードの最小文字数は8文字以上です",
+    "Password minimum character should be more than n characters": "パスワードの最小文字数は {{number}} 文字以上です",
     "Password field is required": "パスワードの欄は必ず入力してください",
     "Password field is required": "パスワードの欄は必ず入力してください",
     "Username or E-mail has invalid characters": "ユーザー名または、メールアドレスに無効な文字があります",
     "Username or E-mail has invalid characters": "ユーザー名または、メールアドレスに無効な文字があります",
     "Password minimum character should be more than 6 characters": "パスワードの最小文字数は6文字以上です",
     "Password minimum character should be more than 6 characters": "パスワードの最小文字数は6文字以上です",

+ 1 - 1
apps/app/public/static/locales/zh_CN/translation.json

@@ -674,7 +674,7 @@
     "Email format is invalid": "电子邮件的格式是无效的",
     "Email format is invalid": "电子邮件的格式是无效的",
     "Email field is required": "电子邮件字段是必需的",
     "Email field is required": "电子邮件字段是必需的",
     "Password has invalid character": "密码有无效字符",
     "Password has invalid character": "密码有无效字符",
-    "Password minimum character should be more than 8 characters": "密码最小字符应超过8个字符",
+    "Password minimum character should be more than n characters": "密码最小字符应超过{{number}}个字符",
     "Password field is required": "密码字段是必需的",
     "Password field is required": "密码字段是必需的",
     "Username or E-mail has invalid characters": "用户名或电子邮件有无效的字符",
     "Username or E-mail has invalid characters": "用户名或电子邮件有无效的字符",
     "Password minimum character should be more than 6 characters": "密码最小字符应超过6个字符",
     "Password minimum character should be more than 6 characters": "密码最小字符应超过6个字符",

+ 7 - 5
apps/app/src/components/LoginForm/LoginForm.tsx

@@ -38,6 +38,7 @@ type LoginFormProps = {
   enabledExternalAuthType?: IExternalAuthProviderType[],
   enabledExternalAuthType?: IExternalAuthProviderType[],
   isMailerSetup?: boolean,
   isMailerSetup?: boolean,
   externalAccountLoginError?: IExternalAccountLoginError,
   externalAccountLoginError?: IExternalAccountLoginError,
+  minPasswordLength?: number,
 }
 }
 export const LoginForm = (props: LoginFormProps): JSX.Element => {
 export const LoginForm = (props: LoginFormProps): JSX.Element => {
   const { t } = useTranslation();
   const { t } = useTranslation();
@@ -46,8 +47,9 @@ export const LoginForm = (props: LoginFormProps): JSX.Element => {
 
 
   const {
   const {
     isLocalStrategySetup, isLdapStrategySetup, isLdapSetupFailed, isPasswordResetEnabled,
     isLocalStrategySetup, isLdapStrategySetup, isLdapSetupFailed, isPasswordResetEnabled,
-    isEmailAuthenticationEnabled, registrationMode, registrationWhitelist, isMailerSetup, enabledExternalAuthType,
+    isEmailAuthenticationEnabled, registrationMode, registrationWhitelist, isMailerSetup, enabledExternalAuthType, minPasswordLength,
   } = props;
   } = props;
+
   const isLocalOrLdapStrategiesEnabled = isLocalStrategySetup || isLdapStrategySetup;
   const isLocalOrLdapStrategiesEnabled = isLocalStrategySetup || isLdapStrategySetup;
   const isSomeExternalAuthEnabled = enabledExternalAuthType != null && enabledExternalAuthType.length > 0;
   const isSomeExternalAuthEnabled = enabledExternalAuthType != null && enabledExternalAuthType.length > 0;
 
 
@@ -360,7 +362,7 @@ export const LoginForm = (props: LoginFormProps): JSX.Element => {
             <p className="alert alert-danger">
             <p className="alert alert-danger">
               {registerErrors.map(err => (
               {registerErrors.map(err => (
                 <span>
                 <span>
-                  {t(err.message)}<br />
+                  {tWithOpt(err.message, err.args)}<br />
                 </span>
                 </span>
               ))}
               ))}
             </p>
             </p>
@@ -455,6 +457,7 @@ export const LoginForm = (props: LoginFormProps): JSX.Element => {
                 </span>
                 </span>
                 {/* Password */}
                 {/* Password */}
                 <input
                 <input
+                  minLength={minPasswordLength}
                   type="password"
                   type="password"
                   className="form-control rounded ms-2"
                   className="form-control rounded ms-2"
                   onChange={(e) => { setPasswordForRegister(e.target.value) }}
                   onChange={(e) => { setPasswordForRegister(e.target.value) }}
@@ -501,9 +504,8 @@ export const LoginForm = (props: LoginFormProps): JSX.Element => {
       </React.Fragment>
       </React.Fragment>
     );
     );
   }, [
   }, [
-    t, isEmailAuthenticationEnabled, registrationMode, isMailerSetup, registerErrors, isSuccessToRagistration,
-    emailForRegistrationOrder, props.username, props.name, props.email, registrationWhitelist, switchForm, handleRegisterFormSubmit, isLoading,
-  ]);
+    t, isEmailAuthenticationEnabled, registrationMode, isMailerSetup, registerErrors, isSuccessToRagistration, emailForRegistrationOrder,
+    props.username, props.name, props.email, registrationWhitelist, isLoading, switchForm, tWithOpt, handleRegisterFormSubmit]);
 
 
   if (registrationMode === RegistrationMode.RESTRICTED && isSuccessToRagistration && !isEmailAuthenticationEnabled) {
   if (registrationMode === RegistrationMode.RESTRICTED && isSuccessToRagistration && !isEmailAuthenticationEnabled) {
     return <CompleteUserRegistration />;
     return <CompleteUserRegistration />;

+ 4 - 0
apps/app/src/pages/login/index.page.tsx

@@ -36,6 +36,7 @@ type Props = CommonProps & {
   isPasswordResetEnabled: boolean,
   isPasswordResetEnabled: boolean,
   isEmailAuthenticationEnabled: boolean,
   isEmailAuthenticationEnabled: boolean,
   externalAccountLoginError?: IExternalAccountLoginError,
   externalAccountLoginError?: IExternalAccountLoginError,
+  minPasswordLength?: number,
 };
 };
 
 
 const LoginPage: NextPage<Props> = (props: Props) => {
 const LoginPage: NextPage<Props> = (props: Props) => {
@@ -66,6 +67,7 @@ const LoginPage: NextPage<Props> = (props: Props) => {
         isMailerSetup={props.isMailerSetup}
         isMailerSetup={props.isMailerSetup}
         registrationMode={props.registrationMode}
         registrationMode={props.registrationMode}
         externalAccountLoginError={props.externalAccountLoginError}
         externalAccountLoginError={props.externalAccountLoginError}
+        minPasswordLength={props.minPasswordLength}
       />
       />
     </NoLoginLayout>
     </NoLoginLayout>
   );
   );
@@ -117,6 +119,8 @@ async function injectServerConfigurations(context: GetServerSidePropsContext, pr
   props.registrationWhitelist = configManager.getConfig('crowi', 'security:registrationWhitelist');
   props.registrationWhitelist = configManager.getConfig('crowi', 'security:registrationWhitelist');
   props.isEmailAuthenticationEnabled = configManager.getConfig('crowi', 'security:passport-local:isEmailAuthenticationEnabled');
   props.isEmailAuthenticationEnabled = configManager.getConfig('crowi', 'security:passport-local:isEmailAuthenticationEnabled');
   props.registrationMode = configManager.getConfig('crowi', 'security:registrationMode');
   props.registrationMode = configManager.getConfig('crowi', 'security:registrationMode');
+  props.minPasswordLength = configManager.getConfig('crowi', 'app:minPasswordLength');
+
 }
 }
 
 
 export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {
 export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {

+ 1 - 1
apps/app/src/server/middlewares/register-form-validator.ts

@@ -24,7 +24,7 @@ export const registerRules = (minPasswordLength?: number): ValidationChain[] =>
       .matches(/^[\x20-\x7F]*$/)
       .matches(/^[\x20-\x7F]*$/)
       .withMessage('message.Password has invalid character')
       .withMessage('message.Password has invalid character')
       .isLength({ min: fixedMinPasswordLength })
       .isLength({ min: fixedMinPasswordLength })
-      .withMessage(new ErrorV3('message.Password minimum character should be more than 8 characters', undefined, undefined, fixedMinPasswordLength))
+      .withMessage(new ErrorV3('message.Password minimum character should be more than n characters', undefined, undefined, { number: fixedMinPasswordLength }))
       .not()
       .not()
       .isEmpty()
       .isEmpty()
       .withMessage('message.Password field is required'),
       .withMessage('message.Password field is required'),