2022-03-11 17:29:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\admin\validate;
|
|
|
|
|
|
|
|
use think\Validate;
|
|
|
|
|
|
|
|
class Admin extends Validate
|
|
|
|
{
|
2022-03-19 20:16:46 +00:00
|
|
|
protected $failException = true;
|
|
|
|
|
2022-03-11 17:29:06 +00:00
|
|
|
protected $rule = [
|
2022-03-23 11:56:44 +00:00
|
|
|
'username' => 'require|regex:^[a-zA-Z][a-zA-Z0-9_]{2,15}$|unique:admin',
|
|
|
|
'nickname' => 'require',
|
|
|
|
'password' => 'require|regex:^[a-zA-Z0-9_]{6,32}$',
|
|
|
|
'email' => 'email|unique:admin',
|
|
|
|
'mobile' => 'mobile|unique:admin',
|
|
|
|
'group_name_arr' => 'require|array',
|
2022-03-11 17:29:06 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 验证提示信息
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $message = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 字段描述
|
|
|
|
*/
|
|
|
|
protected $field = [
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 验证场景
|
|
|
|
*/
|
|
|
|
protected $scene = [
|
2022-03-23 11:56:44 +00:00
|
|
|
'add' => ['username', 'nickname', 'password', 'email', 'mobile', 'group_name_arr'],
|
2022-03-11 17:29:06 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 验证场景-前台自己修改自己资料
|
|
|
|
*/
|
|
|
|
public function sceneInfo()
|
|
|
|
{
|
|
|
|
return $this->only(['nickname', 'password', 'email', 'mobile'])
|
|
|
|
->remove('password', 'require');
|
|
|
|
}
|
|
|
|
|
2022-03-19 20:16:46 +00:00
|
|
|
/**
|
|
|
|
* 验证场景-编辑资料
|
|
|
|
*/
|
|
|
|
public function sceneEdit()
|
|
|
|
{
|
2022-03-23 11:56:44 +00:00
|
|
|
return $this->only(['username', 'nickname', 'password', 'email', 'mobile', 'group_name_arr'])
|
2022-03-19 20:16:46 +00:00
|
|
|
->remove('password', 'require');
|
|
|
|
}
|
|
|
|
|
2022-03-11 17:29:06 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->field = [
|
2022-03-23 11:56:44 +00:00
|
|
|
'username' => __('Username'),
|
|
|
|
'nickname' => __('Nickname'),
|
|
|
|
'password' => __('Password'),
|
|
|
|
'email' => __('Email'),
|
|
|
|
'mobile' => __('Mobile'),
|
|
|
|
'group_name_arr' => __('Group Name Arr'),
|
2022-03-11 17:29:06 +00:00
|
|
|
];
|
|
|
|
$this->message = array_merge($this->message, [
|
|
|
|
'username.regex' => __('Please input correct username'),
|
|
|
|
'password.regex' => __('Please input correct password')
|
|
|
|
]);
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
}
|