Files
chatroom/app/Http/Requests/LoginRequest.php
lkddi c38a53fa74 功能:注册保存性别 + 聊天室个人设置弹窗
- 登录表单的性别选择(bSex)在注册时保存到数据库(男/女/保密)
- 新增 question/answer 密保字段迁移(hasColumn 安全检查)
- User 模型 fillable 增加 sign/question/answer
- UpdateProfileRequest 增加 email/question/answer 验证
- 聊天室工具栏新增设置按钮
- 设置弹窗包含:修改密码、性别、邮箱、密保问题
2026-02-26 22:50:35 +08:00

66 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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' => '验证码不正确。',
];
}
}