-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
サインアップ、ユーザー登録、ログインページで入力エラーを表示できるようにした。
- Loading branch information
1 parent
ec0a8c0
commit c3d916d
Showing
29 changed files
with
519 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import systemMessages from "../../messages/system-messages"; | ||
|
||
/** | ||
* 認証のバリデーションを行うクラス。 | ||
*/ | ||
export default class AuthenticationValidator { | ||
/** | ||
* メールアドレスのバリデーションを行う。 | ||
* @param mailAddress メールアドレス。 | ||
* @returns エラーメッセージ。 | ||
*/ | ||
protected static validateMailAddress(mailAddress: string): string[] { | ||
const mailAddressErrors: string[] = []; | ||
if (!mailAddress.match(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/)) mailAddressErrors.push(systemMessages.error.invalidMailAddress); | ||
return mailAddressErrors; | ||
} | ||
|
||
/** | ||
* パスワードのバリデーションを行う。 | ||
* @param password パスワード。 | ||
* @returns エラーメッセージ。 | ||
*/ | ||
protected static validatePassword(password: string): string[] { | ||
const passwordErrors: string[] = []; | ||
if (password.length < 8 || !password.match(/^(?=.*?[a-z])(?=.*?\d)[a-z\d]{8,100}$/i)) passwordErrors.push(systemMessages.error.invalidPasswordOnSetting); | ||
return passwordErrors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import AuthenticationValidator from './authentication-validator'; | ||
import LoginInputErrors from '../../messages/authentication/login-input-errors'; | ||
|
||
/** | ||
* ログインのバリデーションを行うクラス。 | ||
*/ | ||
export default class LoginValidator extends AuthenticationValidator { | ||
/** | ||
* ログインのバリデーションを行う。 | ||
* @param mailAddress メールアドレス。 | ||
* @param password パスワード。 | ||
* @returns バリデーション結果。 | ||
*/ | ||
public static validate(mailAddress: string, password: string): LoginInputErrors | null { | ||
// 無効なメールアドレスの場合、エラーメッセージを保持する。 | ||
const mailAddressErrors: string[] = AuthenticationValidator.validateMailAddress(mailAddress); | ||
|
||
// パスワードの長さが8文字未満、英数字が含まれていない場合、エラーメッセージを保持する。 | ||
const passwordErrors: string[] = AuthenticationValidator.validatePassword(password); | ||
|
||
// エラーがない場合、nullを返す。 | ||
if (mailAddressErrors.length === 0 && passwordErrors.length === 0) return null; | ||
|
||
// エラーがある場合、エラーメッセージを返す。 | ||
const loginInputErrors: LoginInputErrors = { | ||
mailAddress: mailAddressErrors, | ||
password: passwordErrors, | ||
}; | ||
return loginInputErrors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
import systemMessages from "../../messages/system-messages"; | ||
import AuthenticationUserRegistrationInputErrors from "../../messages/authentication/authentication-user-registration-input-errors"; | ||
import AuthenticationValidator from "./authentication-validator"; | ||
|
||
/** | ||
* サインアップのバリデーションを行うクラス。 | ||
*/ | ||
export default class SignUpValidator { | ||
export default class SignUpValidator extends AuthenticationValidator { | ||
/** | ||
* サインアップのバリデーションを行う。 | ||
* @param mailAddress メールアドレス。 | ||
* @param password パスワード。 | ||
* @param confirmPassword 再確認パスワード。 | ||
* @returns バリデーション結果。 | ||
* @throws バリデーションに失敗した場合、エラーを投げる。 | ||
*/ | ||
public static validate(password: string, confirmPassword: string): boolean { | ||
// パスワードの長さが8文字未満、英数字が含まれていない場合、エラーを投げる。 | ||
if (password.length < 8 || !password.match(/^(?=.*?[a-z])(?=.*?\d)[a-z\d]{8,100}$/i)) throw new Error(systemMessages.error.invalidPasswordOnSetting); | ||
public static validate(mailAddress: string, password: string, confirmPassword: string): AuthenticationUserRegistrationInputErrors | null { | ||
// 無効なメールアドレスの場合、エラーメッセージを保持する。 | ||
const mailAddressErrors: string[] = AuthenticationValidator.validateMailAddress(mailAddress); | ||
|
||
// パスワードと再確認パスワードが一致しない場合、エラーを返す。 | ||
if (password !== confirmPassword) throw new Error(systemMessages.error.passwordMismatch); | ||
return true; | ||
// パスワードの長さが8文字未満、英数字が含まれていない場合、エラーメッセージを保持する。 | ||
const passwordErrors: string[] = AuthenticationValidator.validatePassword(password); | ||
|
||
// パスワードと再確認パスワードが一致しない場合、エラーメッセージを保持する。 | ||
if (password !== confirmPassword) passwordErrors.push(systemMessages.error.passwordMismatch); | ||
|
||
// エラーがない場合、nullを返す。 | ||
if (mailAddressErrors.length === 0 && passwordErrors.length === 0) return null; | ||
|
||
// エラーがある場合、エラーメッセージを返す。 | ||
const userRegistrationInputErrors: AuthenticationUserRegistrationInputErrors = { | ||
mailAddress: mailAddressErrors, | ||
password: passwordErrors, | ||
}; | ||
return userRegistrationInputErrors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/messages/authentication/authentication-user-registration-input-errors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* 認証ユーザー登録の入力エラーを保持するインターフェース。 | ||
*/ | ||
export default interface AuthenticationUserRegistrationInputErrors { | ||
/** | ||
* メールアドレスのエラーメッセージ。 | ||
*/ | ||
mailAddress: string[]; | ||
|
||
/** | ||
* パスワードのエラーメッセージ。 | ||
*/ | ||
password: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* ログイン入力エラーを保持するインターフェース。 | ||
*/ | ||
export default interface LoginInputErrors { | ||
/** | ||
* メールアドレスのエラーメッセージ。 | ||
*/ | ||
mailAddress: string[]; | ||
|
||
/** | ||
* パスワードのエラーメッセージ。 | ||
*/ | ||
password: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* ユーザー登録の入力エラーを保持するインターフェース。 | ||
*/ | ||
export default interface ClientUserRegistrationInputErrors { | ||
/** | ||
* ユーザー名。 | ||
*/ | ||
userName: string[]; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.