| xqd
@@ -7,6 +7,7 @@ use App\Models\AdminRole;
|
|
|
use App\Models\User;
|
|
|
use App\Models\UserInfoModel;
|
|
|
use App\Models\UserInviteLog;
|
|
|
+use App\Services\JPushService;
|
|
|
use App\Services\SmsService;
|
|
|
use App\Services\TencentImAccountService;
|
|
|
use App\Transformers\UserTransformer;
|
| xqd
@@ -28,6 +29,26 @@ class AuthorizationsController extends Controller
|
|
|
$this->tencentImAccountService = $tencentImAccountService;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 极光认证一键登录
|
|
|
+ */
|
|
|
+ public function auth_login(Request $request){
|
|
|
+ try {
|
|
|
+ if(empty($request->loginToken)){
|
|
|
+ throw new Exception("参数错误");
|
|
|
+ }
|
|
|
+ $loginToken = $request->loginToken;
|
|
|
+ $exID = $request->post('exID','800');
|
|
|
+ $ret = JPushService::jgLoginTokenVerify($loginToken,$exID);
|
|
|
+ $mobile = JPushService::jgOpensslPrivateDecrypt($ret['phone']);
|
|
|
+ $res = $this->do_login($mobile);
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ return $this->response->errorForbidden($exception->getMessage());
|
|
|
+ }
|
|
|
+ return response()->json($res);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 手机号登录
|
|
|
* @param Request $request
|
| xqd
@@ -35,34 +56,78 @@ class AuthorizationsController extends Controller
|
|
|
*/
|
|
|
public function login_by_mobile(Request $request)
|
|
|
{
|
|
|
- $validator = Validator::make($request->all(), [
|
|
|
- 'mobile' => ['required', 'regex:/^1[3456789]\d{9}$/'],
|
|
|
- 'verifyKey' => 'bail|required|string',
|
|
|
- 'smsCode' => 'bail|required',
|
|
|
- ], [
|
|
|
- 'mobile.required'=>"手机号码必须",
|
|
|
- 'mobile.regex'=>"手机号码格式错误",
|
|
|
- 'verifyKey.required'=>"验证码必须",
|
|
|
- 'smsCode.required'=>"短信验证码必须",
|
|
|
- ]);
|
|
|
- if ($validator->fails()) {
|
|
|
- return $this->response()->errorForbidden($validator->messages()->first());
|
|
|
- }
|
|
|
-
|
|
|
try {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'mobile' => ['required', 'regex:/^1[3456789]\d{9}$/'],
|
|
|
+ 'verifyKey' => 'bail|required|string',
|
|
|
+ 'smsCode' => 'bail|required',
|
|
|
+ ], [
|
|
|
+ 'mobile.required'=>"手机号码必须",
|
|
|
+ 'mobile.regex'=>"手机号码格式错误",
|
|
|
+ 'verifyKey.required'=>"验证码必须",
|
|
|
+ 'smsCode.required'=>"短信验证码必须",
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return $this->response()->errorForbidden($validator->messages()->first());
|
|
|
+ }
|
|
|
//验证短信验证码
|
|
|
SmsService::checkSmsCodeByVerifyKey($request->verifyKey, $request->smsCode);
|
|
|
+
|
|
|
+ $res = $this->do_login($request->mobile);
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ return $this->response->errorForbidden($exception->getMessage());
|
|
|
} catch (SmsException $e) {
|
|
|
- abort(403, $e->getMessage());
|
|
|
- } catch (\Exception $e) {
|
|
|
- abort(403, '短信校验失败');
|
|
|
+ return $this->response->errorForbidden($e->getMessage());
|
|
|
}
|
|
|
|
|
|
- User::firstOrCreate([
|
|
|
- 'mobile' => $request->input('mobile'),
|
|
|
- ]);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户账号密码登录
|
|
|
+ * @param Request $request
|
|
|
+ * @return \Illuminate\Http\JsonResponse|void
|
|
|
+ */
|
|
|
+ public function login_by_account_password(Request $request)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'mobile' => ['required', 'regex:/^1[3456789]\d{9}$/'],
|
|
|
+ 'password' => 'required|string',
|
|
|
+ ],[
|
|
|
+ 'mobile.required'=>"手机号码必须",
|
|
|
+ 'mobile.regex'=>"手机号码格式错误",
|
|
|
+ 'password.required'=>"密码必须",
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ throw new Exception($validator->messages()->first());
|
|
|
+ }
|
|
|
+ $res = $this->do_login($request->mobile,$request->password);
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ return $this->response->errorForbidden($exception->getMessage());
|
|
|
+ }
|
|
|
|
|
|
- $user = User::query()->where(['mobile'=>$request->input('mobile')])->first();
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //登录操作
|
|
|
+ public function do_login($mobile,$password=null){
|
|
|
+ if(!empty($password)){
|
|
|
+ if (!$user=User::where(['mobile' => $mobile])->first()) {
|
|
|
+ throw new Exception("用户不存在");
|
|
|
+ }
|
|
|
+ $credentials = ['mobile'=>$mobile,'password'=>$password];
|
|
|
+
|
|
|
+ if (!auth('api')->attempt($credentials)) {
|
|
|
+ throw new Exception("用户名或密码错误");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ User::firstOrCreate([
|
|
|
+ 'mobile' => $mobile,
|
|
|
+ ]);
|
|
|
+ $user = User::query()->where(['mobile'=>$mobile])->first();
|
|
|
+ }
|
|
|
|
|
|
if (!$user->ycode) {
|
|
|
$user->ycode = $this->create_code();
|
| xqd
@@ -71,17 +136,17 @@ class AuthorizationsController extends Controller
|
|
|
UserInfoModel::query()->firstOrCreate(['user_id'=>$user->id]);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
if (!$user->tencent_im_user_id) {
|
|
|
$user->tencent_im_user_id = $this->tencentImAccountService->accountImport($user);
|
|
|
}
|
|
|
if($user->status!=1){
|
|
|
- return $this->response->errorForbidden("用户已被禁用,请联系管理员");
|
|
|
+ throw new Exception("用户已被禁用,请联系管理员");
|
|
|
}
|
|
|
-
|
|
|
- $user->save();
|
|
|
$token = Auth::guard('api')->fromUser($user);
|
|
|
- self::updateLastLogin($user, $token);
|
|
|
+ $user->remember_token = $token;
|
|
|
+ $user->last_login_time = Carbon::now();
|
|
|
+ $user->last_login_ip = request()->ip();
|
|
|
+ $user->save();
|
|
|
|
|
|
$resdata['token'] = "Bearer ".$token;
|
|
|
$resdata['sex'] = $user->sex;
|
| xqd
@@ -94,11 +159,10 @@ class AuthorizationsController extends Controller
|
|
|
$resdata['ycode'] =$user->ycode;
|
|
|
$resdata['online'] =$user->online;
|
|
|
$resdata['notice_status'] =$user->notice_status;
|
|
|
-
|
|
|
-
|
|
|
- return response()->json($resdata);
|
|
|
+ return $resdata;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public function captcha(){
|
|
|
return response(captcha_src());
|
|
|
}
|
| xqd
@@ -116,66 +180,6 @@ class AuthorizationsController extends Controller
|
|
|
return $code;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 用户账号密码登录
|
|
|
- * @param Request $request
|
|
|
- * @return \Illuminate\Http\JsonResponse|void
|
|
|
- */
|
|
|
- public function login_by_account_password(Request $request)
|
|
|
- {
|
|
|
- $validator = Validator::make($request->all(), [
|
|
|
- 'mobile' => ['required', 'regex:/^1[3456789]\d{9}$/'],
|
|
|
- 'password' => 'required|string',
|
|
|
- ],[
|
|
|
- 'mobile.required'=>"手机号码必须",
|
|
|
- 'mobile.regex'=>"手机号码格式错误",
|
|
|
- 'password.required'=>"密码必须",
|
|
|
- ]);
|
|
|
- if ($validator->fails()) {
|
|
|
- return $this->response()->errorForbidden($validator->messages()->first());
|
|
|
- }
|
|
|
- if (!$user=User::where(['mobile' => $request->mobile])->first()) {
|
|
|
- return $this->response->errorForbidden('用户不存在!');
|
|
|
- }
|
|
|
- $credentials = $request->only('mobile', 'password');
|
|
|
-
|
|
|
- if (!$token = auth('api')->attempt($credentials)) {
|
|
|
- return $this->response->errorForbidden ('用户名或密码错误');
|
|
|
- }
|
|
|
- if($user->status!=1){
|
|
|
- return $this->response->errorForbidden("用户已被禁用,请联系管理员");
|
|
|
- }
|
|
|
- if(!UserInfoModel::query()->where('user_id',$user->id)->first()){
|
|
|
- UserInfoModel::query()->firstOrCreate(['user_id'=>$user->id]);
|
|
|
- }
|
|
|
-
|
|
|
- if (!$user->ycode) {
|
|
|
- $user->ycode = $this->create_code();
|
|
|
- }
|
|
|
-
|
|
|
- if (!$user->tencent_im_user_id) {
|
|
|
- $user->tencent_im_user_id = $this->tencentImAccountService->accountImport($user);
|
|
|
- }
|
|
|
-
|
|
|
- $user->save();
|
|
|
- self::updateLastLogin($user, $token);
|
|
|
-
|
|
|
- $resdata['token'] = "Bearer ".$token;
|
|
|
- $resdata['sex'] = $user->sex;
|
|
|
- $resdata['password'] = $user->password?1:0;
|
|
|
- $resdata['tencent_im_user_id'] =$user->tencent_im_user_id;
|
|
|
- $resdata['mobile'] =$user->mobile;
|
|
|
- $resdata['lock_pass'] =$user->lock_pass?$user->lock_pass:false;
|
|
|
- $resdata['status'] =$user->status;
|
|
|
- $resdata['is_auth'] =$user->is_auth;
|
|
|
- $resdata['ycode'] =$user->ycode;
|
|
|
- $resdata['online'] =$user->online;
|
|
|
- $resdata['notice_status'] =$user->notice_status;
|
|
|
- return response()->json($resdata);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 注册账号
|
|
|
*/
|