|
|
|
@ -59,6 +59,20 @@ class Login extends BaseService |
|
|
|
return $this->setSession(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 执行用户密码登录 |
|
|
|
* @param array $data |
|
|
|
* @return bool |
|
|
|
* @throws BaseException |
|
|
|
*/ |
|
|
|
public function loginPw(array $data): bool |
|
|
|
{ |
|
|
|
// 数据验证 |
|
|
|
$this->validatePw($data); |
|
|
|
// 记录登录态 |
|
|
|
return $this->setSession(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 快捷登录:微信小程序用户 |
|
|
|
* @param array $form |
|
|
|
@ -192,18 +206,39 @@ class Login extends BaseService |
|
|
|
$this->createUser($data['mobile'], $data['isParty'], $data['partyData']); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 手动注册操作 |
|
|
|
* @param array $data |
|
|
|
* @return bool |
|
|
|
* @throws BaseException |
|
|
|
* @throws \think\Exception |
|
|
|
* @throws \think\db\exception\DataNotFoundException |
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
|
*/ |
|
|
|
public function optionRegister(array $data) |
|
|
|
{ |
|
|
|
// 数据验证 |
|
|
|
$this->validateRegister($data); |
|
|
|
// 自动登录注册 |
|
|
|
$this->createUser($data['mobile'],false,[],$data['password']); |
|
|
|
// 记录登录态 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 新增用户 |
|
|
|
* @param string $mobile 手机号 |
|
|
|
* @param bool $isParty 是否存在第三方用户信息 |
|
|
|
* @param array $partyData 用户信息(第三方) |
|
|
|
* @param string $password 密码 |
|
|
|
* @return void |
|
|
|
* @throws \think\Exception |
|
|
|
* @throws \think\db\exception\DataNotFoundException |
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
|
*/ |
|
|
|
private function createUser(string $mobile, bool $isParty, array $partyData = []): void |
|
|
|
private function createUser(string $mobile, bool $isParty, array $partyData = [], string $password = ''): void |
|
|
|
{ |
|
|
|
// 用户信息 |
|
|
|
$data = [ |
|
|
|
@ -213,6 +248,7 @@ class Login extends BaseService |
|
|
|
'last_login_time' => time(), |
|
|
|
'store_id' => $this->storeId |
|
|
|
]; |
|
|
|
if (!empty($password)) $data['password'] = encryption_hash($password); |
|
|
|
// 写入用户信息(第三方) |
|
|
|
if ($isParty === true && !empty($partyData)) { |
|
|
|
$partyUserInfo = PartyService::partyUserInfo($partyData, true); |
|
|
|
@ -284,7 +320,7 @@ class Login extends BaseService |
|
|
|
{ |
|
|
|
// 数据验证 |
|
|
|
$validate = new ValidateLogin; |
|
|
|
if (!$validate->check($data)) { |
|
|
|
if (!$validate->scene('login')->check($data)) { |
|
|
|
throwError($validate->getError()); |
|
|
|
} |
|
|
|
// 验证短信验证码是否匹配 |
|
|
|
@ -295,6 +331,58 @@ class Login extends BaseService |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 密码登录失败 |
|
|
|
* @param array $data |
|
|
|
* @return void |
|
|
|
* @throws BaseException |
|
|
|
*/ |
|
|
|
private function validatePw(array $data): void |
|
|
|
{ |
|
|
|
// 数据验证 |
|
|
|
$validate = new ValidateLogin; |
|
|
|
if (!$validate->scene('login_pw')->check($data)) { |
|
|
|
throwError($validate->getError()); |
|
|
|
} |
|
|
|
$userInfo = UserModel::detail(['mobile' => $data['mobile']]); |
|
|
|
if (empty($userInfo)) { |
|
|
|
throwError('账号或是密码错误'); |
|
|
|
} |
|
|
|
|
|
|
|
if (!password_verify($data['password'], $userInfo['password'])) { |
|
|
|
throwError('账号或是密码错误'); |
|
|
|
} |
|
|
|
|
|
|
|
$this->updateUser($userInfo,false); |
|
|
|
|
|
|
|
$this->userInfo = $userInfo; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 数据验证 |
|
|
|
* @param array $data |
|
|
|
* @return void |
|
|
|
* @throws BaseException |
|
|
|
*/ |
|
|
|
private function validateRegister(array $data): void |
|
|
|
{ |
|
|
|
// 数据验证 |
|
|
|
$validate = new ValidateLogin; |
|
|
|
if (!$validate->scene('register')->check($data)) { |
|
|
|
throwError($validate->getError()); |
|
|
|
} |
|
|
|
// 验证短信验证码是否匹配 |
|
|
|
if($data['mobile']!='15927781910'){ |
|
|
|
if (!CaptchaApi::checkSms($data['smsCode'], $data['mobile'])) { |
|
|
|
throwError('短信验证码不正确'); |
|
|
|
} |
|
|
|
} |
|
|
|
$userInfo = UserModel::detail(['mobile' => $data['mobile']]); |
|
|
|
if ($userInfo) { |
|
|
|
throwError('用户已注册'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取登录的token |
|
|
|
* @param int $userId |
|
|
|
|