first commit
This commit is contained in:
98
app/api/validate/RegisterValidate.php
Normal file
98
app/api/validate/RegisterValidate.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\validate;
|
||||
|
||||
|
||||
use app\common\model\user\User;
|
||||
use app\common\validate\BaseValidate;
|
||||
use app\common\enum\user\UserTerminalEnum;
|
||||
use app\common\cache\UserAccountSafeCache;
|
||||
|
||||
/**
|
||||
* 注册验证器
|
||||
* Class RegisterValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class RegisterValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $regex = [
|
||||
'password' => '/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-z]|[A-Z]|[0-9]){6,20}$/'
|
||||
];
|
||||
|
||||
protected $rule = [
|
||||
'channel' => 'require|in:' . UserTerminalEnum::WECHAT_MMP . ',' . UserTerminalEnum::WECHAT_OA . ','
|
||||
. UserTerminalEnum::H5 . ',' . UserTerminalEnum::PC . ',' . UserTerminalEnum::IOS .
|
||||
',' . UserTerminalEnum::ANDROID,
|
||||
'account' => 'require|checkAccount',
|
||||
'password' => 'require|length:6,20|regex:password',
|
||||
// 'password_confirm' => 'require|confirm'
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'channel.require' => 'network.parameterAbnormality',//注册来源参数缺失
|
||||
'channel.in' => 'network.parameterAbnormality',//终端参数状态值不正确
|
||||
'account.require' => 'network.parameterAbnormality',
|
||||
'password.require' => 'login.passwordEmpty',//请输入密码
|
||||
'password.length' => 'login.passwordLimit',//密码须在6-20位之间
|
||||
'password.regex' => 'login.passwordFormatError',//密码须为字母数字组合
|
||||
'password_confirm.require' => 'login.passwordConfirmEmpty',//请输入确认密码
|
||||
'password_confirm.confirm' => 'login.twoPasswordError'//两次输入的密码不一致
|
||||
];
|
||||
|
||||
/**
|
||||
* @notes 校验注册
|
||||
* @param $buy
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
protected function checkAccount($account, $rule, $data)
|
||||
{
|
||||
//账号安全机制,连续输错后锁定
|
||||
$userAccountSafeCache = new UserAccountSafeCache();
|
||||
if (!$userAccountSafeCache->isSafe()) {
|
||||
return 'network.pwdErrorLimit';
|
||||
}
|
||||
|
||||
$login_way = $data['login_way'];//0邮箱1手机号
|
||||
|
||||
$mobile_pattern = '/^\d{6,20}$/';
|
||||
|
||||
if($login_way == 0){
|
||||
if(!filter_var($data['account'], FILTER_VALIDATE_EMAIL)){
|
||||
return 'login.emailError';
|
||||
}
|
||||
}elseif($login_way == 1){
|
||||
if(!preg_match($mobile_pattern, $data['account'])){
|
||||
return 'login.mobileError';
|
||||
}
|
||||
}else{
|
||||
return 'network.parameterAbnormality';
|
||||
}
|
||||
|
||||
$user = User::where(['account' => $data['account']])->findOrEmpty();
|
||||
|
||||
if (!$user->isEmpty()) {
|
||||
$userAccountSafeCache->record();
|
||||
return 'login.accountExist';
|
||||
}
|
||||
|
||||
$userAccountSafeCache->relieve();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user