98 lines
3.2 KiB
PHP
98 lines
3.2 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Requests;
|
||
|
||
use Illuminate\Foundation\Http\FormRequest;
|
||
use Illuminate\Validation\Rule;
|
||
use Illuminate\Validation\Rules\Password;
|
||
|
||
class ChangePasswordRequest extends FormRequest
|
||
{
|
||
/**
|
||
* リクエストを処理することを認可するか判定
|
||
*
|
||
* @return bool
|
||
*/
|
||
public function authorize(): bool
|
||
{
|
||
return auth()->check();
|
||
}
|
||
|
||
/**
|
||
* 入力値の検証ルール
|
||
*
|
||
* クライアント側:必填(3項目)、長度 8-64、新密码仅半角英数字+记号、新/确认一致
|
||
* サーバー側:当前密码认证(hash check)、新密码不能等于旧密码(CustomRulesで実装)
|
||
*
|
||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||
*/
|
||
public function rules(): array
|
||
{
|
||
return [
|
||
// 当前パスワード:必填、8-64文字
|
||
'current_password' => [
|
||
'required',
|
||
'string',
|
||
'min:8',
|
||
'max:64',
|
||
],
|
||
|
||
// 新パスワード:必填、8-64文字、英数字+記号のみ
|
||
'password' => [
|
||
'required',
|
||
'string',
|
||
'min:8',
|
||
'max:64',
|
||
'regex:/^[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};:\'",.<>?\/\\|`~]+$/', // 半角英数字+記号のみ
|
||
],
|
||
|
||
// 新パスワード確認:必填、新パスワードと一致
|
||
'password_confirmation' => [
|
||
'required',
|
||
'string',
|
||
'same:password',
|
||
],
|
||
|
||
// hidden フィールド(フォーム側で出力)
|
||
'updated_at' => 'nullable|date_format:Y-m-d H:i:s',
|
||
'ope_pass_changed_at' => 'nullable|date_format:Y-m-d H:i:s',
|
||
];
|
||
}
|
||
|
||
/**
|
||
* 属性の表示名
|
||
*
|
||
* @return array<string, string>
|
||
*/
|
||
public function attributes(): array
|
||
{
|
||
return [
|
||
'current_password' => '当前パスワード',
|
||
'password' => '新パスワード',
|
||
'password_confirmation' => '新パスワード確認',
|
||
];
|
||
}
|
||
|
||
/**
|
||
* 検証エラーメッセージのカスタマイズ
|
||
*
|
||
* @return array<string, string>
|
||
*/
|
||
public function messages(): array
|
||
{
|
||
return [
|
||
'current_password.required' => '当前パスワードを入力してください。',
|
||
'current_password.min' => '当前パスワードは8文字以上です。',
|
||
'current_password.max' => '当前パスワードは64文字以下です。',
|
||
|
||
'password.required' => '新パスワードを入力してください。',
|
||
'password.min' => '新パスワードは8文字以上です。',
|
||
'password.max' => '新パスワードは64文字以下です。',
|
||
'password.regex' => '新パスワードは英数字と記号のみ使用できます。',
|
||
|
||
'password_confirmation.required' => '新パスワード確認を入力してください。',
|
||
'password_confirmation.same' => '新パスワードと新パスワード確認は一致する必要があります。',
|
||
];
|
||
}
|
||
}
|