first commit

This commit is contained in:
Your Name
2026-01-19 14:19:22 +08:00
commit fe2d9c1868
4777 changed files with 665503 additions and 0 deletions

View File

@@ -0,0 +1,197 @@
<?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\validate\BaseValidate;
use app\common\model\user\{User,UserInfo};
use app\common\service\{ConfigService,UtilsService};
use app\common\model\notice\EmailRecord;
use app\common\cache\UserAccountSafeCache;
/**
* 密码校验
* Class PasswordValidate
* @package app\api\validate
*/
class PasswordValidate extends BaseValidate
{
protected $rule = [
'mobile' => 'require|length:6,20|integer',
'code' => 'require|length:6|integer',
'password' => 'require|length:6,20|alphaNum',
'password_confirm' => 'require|confirm',
'password_pay' => 'require|length:6|integer',
'password_pay_confirm' => 'require|confirm',
'type' => 'require|checkReset',
];
protected $message = [
'mobile.require' => 'pwd.mobileEmpty',//请输入手机号
'mobile.length' => 'pwd.mobileError',//请输入正确的手机号
'mobile.integer' => 'pwd',//请输入正确的手机号
'code.require' => 'captcha.captchaEmpty',//请输入验证码
'code.length' => 'captcha.captchaError',//请输入正确的验证码
'code.integer' => 'captcha.captchaError',//请输入正确的验证码
'password.require' => 'pwd.newPwdEmpty',//请输入新密码
'password.length' => 'pwd.newPwdLengthError',//密码须在6-20位之间
'password.alphaNum' => 'pwd.newPwdFormatError',//密码须为字母数字组合
'password_confirm.require' => 'pwd.confirmPwdEmpty',//请输入确认密码
'password_confirm.confirm' => 'pwd.twoPwdError',//两次输入的密码不一致
'password_pay.require' => 'pwd.newPwdEmpty',//请输入新密码
'password_pay.length' => 'pwd.payPwdFormatError',//密码格式不正确
'password_pay.integer' => 'pwd.payPwdFormatError',//密码格式不正确
'password_pay_confirm.require' => 'pwd.confirmPwdEmpty',//请输入确认密码
'password_pay_confirm.confirm' => 'pwd.twoPwdError',//两次输入的密码不一致
'type.require' => 'network.parameterAbnormality',//验证方式异常
];
/**
* @notes 重置登录密码
* @return PasswordValidate
* @author 段誉
* @date 2022/9/16 18:11
*/
public function sceneResetPassword()
{
return $this->only(['mobile', 'code', 'password', 'password_confirm','type']);
}
/**
* @notes 修改密码场景
* @return PasswordValidate
* @author 段誉
* @date 2022/9/20 19:14
*/
public function sceneChangePassword()
{
return $this->only(['password', 'password_confirm']);
}
/**
* @notes 修改支付密码场景
* @return PasswordValidate
* @author 段誉
* @date 2022/9/20 19:14
*/
public function sceneChangePayPassword()
{
return $this->only(['password_pay', 'password_pay_confirm']);
}
/**
* @notes 设置支付密码场景
* @return PasswordValidate
* @author 段誉
* @date 2022/9/20 19:14
*/
public function sceneSetPayPassword()
{
return $this->only(['password_pay', 'password_pay_confirm']);
}
/**
* @notes 校验忘记密码
* @param $money
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2023/2/24 10:42
*/
protected function checkReset($type, $rule, $data)
{
//账号安全机制,连续输错后锁定,防止账号密码暴力破解
$userAccountSafeCache = new UserAccountSafeCache();
if (!$userAccountSafeCache->isSafe()) {
return 'network.frequentOperation';
//密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试
}
$type = $data['type'];
$types = array(0,1);//0谷歌验证 1邮箱验证
if(!in_array($type, $types)) {
return 'network.parameterAbnormality';
}
$user = User::where(['mobile' => $data['mobile'],'country_code' => $data['country_code']])->findOrEmpty();
if($user->isEmpty()) {
$userAccountSafeCache->record();
return 'login.userNoExist';//用户不存在
}
$userInfo = UserInfo::where(['user_id' => $user['id']])->findOrEmpty();
if($userInfo->isEmpty()) {
return 'network.parameterAbnormality';
}
switch ($type) {
case 0:
if($userInfo['auth_google'] == 0) {
$userAccountSafeCache->record();
return 'pwd.bindGoogleFirst';//请先绑定您的Google Authenticator
}
$valid = UtilsService::get_google_verify($userInfo['google_key'],$data['code']);
if(!$valid) {
$userAccountSafeCache->record();
return 'captcha.captchaError';//验证码错误
}
break;
case 1:
if($userInfo['auth_email'] == 0) {
$userAccountSafeCache->record();
return 'pwd.bindEmailFirst';//请先绑定您的电子邮箱
}
if(!filter_var($data['email'], FILTER_VALIDATE_EMAIL)){
$userAccountSafeCache->record();
return 'auth.emailError';//请输入正确的邮箱地址
}
if($userInfo['email'] != $data['email']){
$userAccountSafeCache->record();
return 'auth.emailError';//请输入正确的邮箱地址
}
$time = time() - 5*60;//5分钟内有效
$email = EmailRecord::where(['user_id' => $user['id'],'is_verify' => 0])->where("create_time > $time")->order('id desc')->findOrEmpty();
if($email->isEmpty()) {
$userAccountSafeCache->record();
return 'captcha.captchaError';//验证码错误
}
if($email['code'] != $data['code']) {
$userAccountSafeCache->record();
return 'captcha.captchaError';//验证码错误
}
break;
}
$userAccountSafeCache->relieve();
return true;
}
}