代码功能更新
This commit is contained in:
Executable
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\validate\api\member;
|
||||
|
||||
//邮箱密码登录验证器
|
||||
use app\model\Member;
|
||||
use laytp\library\Str;
|
||||
use think\Validate;
|
||||
|
||||
class EmailLogin extends Validate
|
||||
{
|
||||
//数组顺序就是检测的顺序,比如这里,会先检测code验证码的正确性
|
||||
protected $rule = [
|
||||
'email' => 'require|email',
|
||||
'password' => 'require|length:6,26|checkPassword:',
|
||||
];
|
||||
|
||||
//定义内置方法检验失败后返回的字符
|
||||
protected $message = [
|
||||
'email.require' => '邮箱不能为空',
|
||||
'email.email' => '邮箱格式不正确',
|
||||
'password.require' => '密码不能为空',
|
||||
'password.length' => '密码长度需要6到26个字符',
|
||||
];
|
||||
|
||||
//自定义密码检验方法
|
||||
protected function checkPassword($password, $rule, $data)
|
||||
{
|
||||
$email = $data['email'];
|
||||
$user = new Member();
|
||||
$passwordHash = $user->getFieldByEmail($email, 'password');
|
||||
return (!Str::checkPassword($password, $passwordHash)) ? '账户信息错误' : true;
|
||||
}
|
||||
}
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace app\validate\api\member;
|
||||
|
||||
//邮箱密码注册验证器
|
||||
use app\model\Member;
|
||||
use think\Validate;
|
||||
|
||||
class EmailReg extends Validate
|
||||
{
|
||||
//数组顺序就是检测的顺序,比如这里,会先检测code验证码的正确性
|
||||
protected $rule = [
|
||||
'email' => 'require|email|checkEmail:',
|
||||
'password' => 'require|length:6,26|confirm:repassword',
|
||||
'repassword' => 'require|length:6,26',
|
||||
];
|
||||
|
||||
//定义内置方法检验失败后返回的字符
|
||||
protected $message = [
|
||||
'email.require' => '邮箱不能为空',
|
||||
'email.email' => '邮箱格式不正确',
|
||||
'password.require' => '密码不能为空',
|
||||
'password.length' => '密码长度需要6到26个字符',
|
||||
'password.confirm' => '两次密码输入不相同',
|
||||
'repassword.require' => '重复密码不能为空',
|
||||
'repassword.length' => '重复密码长度需要6到26个字符',
|
||||
];
|
||||
|
||||
protected function checkEmail($email, $rule, $data){
|
||||
$exist = Member::getFieldByEmail($email,'id');
|
||||
if($exist){
|
||||
return '邮箱已存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user