|
|
|
@ -5,6 +5,7 @@ namespace app\controller; |
|
|
|
use app\BaseController; |
|
|
|
use app\common\lib\sms\AliSms\AliSms; |
|
|
|
use app\model\AdminUser; |
|
|
|
use app\model\AgentUser; |
|
|
|
use app\model\Pincode; |
|
|
|
use app\model\User as UserModel; |
|
|
|
use app\validate\User as UserValidate; |
|
|
|
@ -253,4 +254,56 @@ class Passport extends BaseController |
|
|
|
return $this->renderError($exception->getMessage(),$data); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 代理登陆 |
|
|
|
* @return array |
|
|
|
* @throws \think\db\exception\DataNotFoundException |
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
|
* @author whj |
|
|
|
* @date 2023-08-30 15:23 |
|
|
|
*/ |
|
|
|
public function AgentLogin() |
|
|
|
{ |
|
|
|
$data = Request::param(); |
|
|
|
|
|
|
|
$count = 0; |
|
|
|
$defaultCount = 3;# 默认登陆三次提示验证码 |
|
|
|
try { |
|
|
|
|
|
|
|
$cookie_name = 'login_count'.$_SERVER['HTTP_HOST']; |
|
|
|
// 验证用户输入 |
|
|
|
validate(UserValidate::class)->scene('agentLogin')->check($data); |
|
|
|
|
|
|
|
# 验证码验证 |
|
|
|
if ($count = Cookie::get($cookie_name) ?: 0) { |
|
|
|
Cookie::set($cookie_name,$count+1); |
|
|
|
} else { |
|
|
|
Cookie::set($cookie_name,1); |
|
|
|
} |
|
|
|
if ($count > $defaultCount) { |
|
|
|
$this->validate($data,['captcha|验证码'=>'require|captcha']); |
|
|
|
} |
|
|
|
|
|
|
|
// 管理员登录 |
|
|
|
$agentUser = AgentUser::login($data); |
|
|
|
|
|
|
|
if ($agentUser['status'] == 1) { |
|
|
|
|
|
|
|
$userinfo = ['agent_user_id' => $agentUser['data']['id'], 'avatar' => get_image_url($agentUser['data']['avatar'])]; |
|
|
|
$token = ['token'=>signToken($userinfo)]; |
|
|
|
|
|
|
|
Cookie::delete($cookie_name); |
|
|
|
return $this->renderSuccess('登陆成功',$token); |
|
|
|
} else { |
|
|
|
throw new ValidateException($agentUser['msg']); |
|
|
|
} |
|
|
|
} catch (ValidateException $exception) { |
|
|
|
|
|
|
|
$data = ['captcha_img' => '']; |
|
|
|
if ($count >= $defaultCount) $data['captcha_img'] = captcha_src(); |
|
|
|
return $this->renderError($exception->getMessage(),$data); |
|
|
|
} |
|
|
|
} |
|
|
|
} |