- 登录表单的性别选择(bSex)在注册时保存到数据库(男/女/保密) - 新增 question/answer 密保字段迁移(hasColumn 安全检查) - User 模型 fillable 增加 sign/question/answer - UpdateProfileRequest 增加 email/question/answer 验证 - 聊天室工具栏新增设置按钮 - 设置弹窗包含:修改密码、性别、邮箱、密保问题
66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
||
|
||
/**
|
||
* 文件功能:登录/注册请求验证器
|
||
*
|
||
* @author ChatRoom Laravel
|
||
*
|
||
* @version 1.0.0
|
||
*/
|
||
|
||
namespace App\Http\Requests;
|
||
|
||
use Illuminate\Foundation\Http\FormRequest;
|
||
|
||
class LoginRequest extends FormRequest
|
||
{
|
||
/**
|
||
* Determine if the user is authorized to make this request.
|
||
*/
|
||
public function authorize(): bool
|
||
{
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* Get the validation rules that apply to the request.
|
||
*
|
||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||
*/
|
||
public function rules(): array
|
||
{
|
||
return [
|
||
'username' => [
|
||
'required',
|
||
'string',
|
||
'min:2',
|
||
'max:12',
|
||
// 允许中英文数字及常见符号,但严格过滤可能引起XSS/SQL注入的危险字符:< > ' "
|
||
'regex:/^[^<>\'"]+$/u',
|
||
],
|
||
'password' => ['required', 'string', 'min:1'],
|
||
'bSex' => ['nullable', 'in:1,2'],
|
||
'captcha' => ['required', 'captcha'],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* 获取已定义验证规则的错误消息。
|
||
*
|
||
* @return array<string, string>
|
||
*/
|
||
public function messages(): array
|
||
{
|
||
return [
|
||
'username.required' => '必须填写用户名。',
|
||
'username.min' => '用户名长度不得少于 2 个字符。',
|
||
'username.max' => '用户名长度不得超过 12 个字符。',
|
||
'username.regex' => '用户名包含非法字符(不允许使用尖括号或引号)。',
|
||
'password.required' => '必须填写密码。',
|
||
'password.min' => '密码长度不得少于 1 个字符。',
|
||
'captcha.required' => '必须填写验证码。',
|
||
'captcha.captcha' => '验证码不正确。',
|
||
];
|
||
}
|
||
}
|