|
|
|
@ -47,6 +47,9 @@ class Passport extends BaseController |
|
|
|
|
|
|
|
// 注册用户 |
|
|
|
if ($userModel->register($data)) { |
|
|
|
|
|
|
|
Cookie::delete('send_code'.$_SERVER['HTTP_HOST']); |
|
|
|
|
|
|
|
return $this->renderSuccess('注册成功'); |
|
|
|
} else { |
|
|
|
return $this->renderSuccess('手机号已注册'); |
|
|
|
@ -70,14 +73,15 @@ class Passport extends BaseController |
|
|
|
$count = 0; |
|
|
|
$defaultCount = 3; |
|
|
|
try { |
|
|
|
$cookie_name = 'login_count'.$_SERVER['HTTP_HOST']; |
|
|
|
// 验证用户输入 |
|
|
|
validate(UserValidate::class)->scene('login')->check($data); |
|
|
|
|
|
|
|
# 验证码验证 |
|
|
|
if ($count = Cookie::get('login_count'.$_SERVER['HTTP_HOST'])) { |
|
|
|
Cookie::set('login_count'.$_SERVER['HTTP_HOST'],$count+1); |
|
|
|
if ($count = Cookie::get($cookie_name)) { |
|
|
|
Cookie::set($cookie_name,$count+1); |
|
|
|
} else { |
|
|
|
Cookie::set('login_count'.$_SERVER['HTTP_HOST'],1); |
|
|
|
Cookie::set($cookie_name,1); |
|
|
|
} |
|
|
|
if ($count > $defaultCount) { |
|
|
|
$this->validate($data,['captcha|验证码'=>'require|captcha']); |
|
|
|
@ -91,6 +95,7 @@ class Passport extends BaseController |
|
|
|
$userinfo = ['id' => $user['data']['id'], 'avatar' => $user['data']['avatar']]; |
|
|
|
$token = ['token'=>signToken($userinfo)]; |
|
|
|
|
|
|
|
Cookie::delete($cookie_name); |
|
|
|
return $this->renderSuccess('登陆成功',$token); |
|
|
|
} else { |
|
|
|
throw new ValidateException($user['msg']); |
|
|
|
@ -104,16 +109,28 @@ class Passport extends BaseController |
|
|
|
|
|
|
|
/** |
|
|
|
* 发送短信验证码 |
|
|
|
* @return array|void |
|
|
|
* @return array |
|
|
|
* @throws \think\db\exception\DataNotFoundException |
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
|
*/ |
|
|
|
public function sendCode() |
|
|
|
{ |
|
|
|
$data = Request::param(); |
|
|
|
|
|
|
|
try { |
|
|
|
$cookie_name = 'send_code'.$_SERVER['HTTP_HOST']; |
|
|
|
|
|
|
|
validate(UserValidate::class)->scene('sendCode')->check($data); |
|
|
|
|
|
|
|
if ($time = Cookie::get($cookie_name)) { |
|
|
|
$s = time() - $time; |
|
|
|
if ($s < 60) { |
|
|
|
return $this->renderError("请等待 {$s} 秒后操作",['residue_time' => $s]); |
|
|
|
} else { |
|
|
|
Cookie::delete($cookie_name); |
|
|
|
} |
|
|
|
} |
|
|
|
$phone = $data['phone']; |
|
|
|
$code = rand(1000 , 9999); |
|
|
|
|
|
|
|
@ -127,6 +144,9 @@ class Passport extends BaseController |
|
|
|
$res = $Pincode->sendSave($phone,$code); |
|
|
|
|
|
|
|
if ($res['status']) { |
|
|
|
|
|
|
|
Cookie::set($cookie_name,time()); |
|
|
|
|
|
|
|
return $this->renderSuccess('发送成功' , ['code' => $code]); |
|
|
|
} else { |
|
|
|
throw new ValidateException('发送失败'); |
|
|
|
|