|
@@ -15,9 +15,9 @@ namespace app\index\service\passport;
|
|
|
use think\facade\Cache;
|
|
|
use think\helper\Str;
|
|
|
use yiovo\captcha\facade\CaptchaApi;
|
|
|
-use app\api\model\{User as UserModel, Setting as SettingModel};
|
|
|
-use app\api\service\{user\Oauth as OauthService, user\Avatar as AvatarService, passport\Party as PartyService};
|
|
|
-use app\api\validate\passport\Login as ValidateLogin;
|
|
|
+use app\index\model\{User as UserModel, Setting as SettingModel};
|
|
|
+use app\index\service\{user\Oauth as OauthService, user\Avatar as AvatarService, passport\Party as PartyService};
|
|
|
+use app\index\validate\passport\Login as ValidateLogin;
|
|
|
use app\common\service\BaseService;
|
|
|
use app\common\enum\Setting as SettingEnum;
|
|
|
use cores\exception\BaseException;
|
|
@@ -51,9 +51,9 @@ class Login extends BaseService
|
|
|
public function login(array $data): bool
|
|
|
{
|
|
|
empty($data['partyData']) && $data['partyData'] = [];
|
|
|
- if ($data['isParty'] == 'true' || $data['isParty'] === true){
|
|
|
+ if ($data['isParty'] == 'true' || $data['isParty'] === true) {
|
|
|
$data['isParty'] = true;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$data['isParty'] = false;
|
|
|
}
|
|
|
|
|
@@ -67,6 +67,54 @@ class Login extends BaseService
|
|
|
return $this->setSession();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function toLogin(array $data): bool
|
|
|
+ {
|
|
|
+ empty($data['partyData']) && $data['partyData'] = [];
|
|
|
+ if ($data['isParty'] == 'true' || $data['isParty'] === true) {
|
|
|
+ $data['isParty'] = true;
|
|
|
+ } else {
|
|
|
+ $data['isParty'] = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 数据验证
|
|
|
+ $this->validate($data);
|
|
|
+ // 自动登录注册
|
|
|
+ $userInfo = UserModel::detail(['mobile' => $data['mobile']]);
|
|
|
+ if ($userInfo) {
|
|
|
+ if (md5($data['password'] . $userInfo['salt']) !== $userInfo['password']) {
|
|
|
+ throwError('The account does not exist or the password is incorrect.', 500, []);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->updateUser($userInfo, $data['isParty'], $data['partyData']);
|
|
|
+ // 保存第三方用户信息
|
|
|
+ $this->createUserOauth($this->getUserId(), $data['isParty'], $data['partyData']);
|
|
|
+ // 记录登录态
|
|
|
+ return $this->setSession();
|
|
|
+ } else {
|
|
|
+ throwError('The account does not exist or the password is incorrect.', 500, []);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function toRegister(array $data): bool
|
|
|
+ {
|
|
|
+ empty($data['partyData']) && $data['partyData'] = [];
|
|
|
+ if ($data['isParty'] == 'true' || $data['isParty'] === true) {
|
|
|
+ $data['isParty'] = true;
|
|
|
+ } else {
|
|
|
+ $data['isParty'] = false;
|
|
|
+ }
|
|
|
+ // 数据验证
|
|
|
+ $this->validate($data);
|
|
|
+ $userInfo = UserModel::detail(['mobile' => $data['mobile']]);
|
|
|
+ if ($userInfo) {
|
|
|
+ throwError('The account you entered has already been registered.', 500, []);
|
|
|
+ }
|
|
|
+ // 用户不存在: 创建一个新用户
|
|
|
+ $this->createUser($data['mobile'], $data['isParty'], $data['partyData'], $data['password']);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 快捷登录:微信小程序用户
|
|
|
* @param array $form
|
|
@@ -112,14 +160,14 @@ class Login extends BaseService
|
|
|
return $this->setSession();
|
|
|
}
|
|
|
|
|
|
- public function resetPassword($email,$smsCode,$password)
|
|
|
+ public function resetPassword($email, $smsCode, $password)
|
|
|
{
|
|
|
//todo 电子烟校验邮箱mobile的验证码是否匹配
|
|
|
$mailCaptcha = new MailCaptcha();
|
|
|
$mailCaptcha->checkCaptcha($smsCode, $email);
|
|
|
|
|
|
- $userInfo = !empty($email) ? UserModel::detail(['mobile'=>$email]) : null;
|
|
|
- if (empty($userInfo)){
|
|
|
+ $userInfo = !empty($email) ? UserModel::detail(['mobile' => $email]) : null;
|
|
|
+ if (empty($userInfo)) {
|
|
|
throwError('Not exit', 401, []);
|
|
|
}
|
|
|
|