1
0
Fork 0

user_socialte

master
panliang 2023-10-16 15:19:46 +08:00
parent c0abe0262e
commit b1d15f9324
3 changed files with 19 additions and 8 deletions

View File

@ -49,8 +49,12 @@ class AuthController extends AdminAuthController
$openid = $request->input('openid');
$open_type = $request->input('open_type');
if ($openid && $open_type) {
UserSocialite::where(['openid' => $openid, 'type' => SocialiteType::from($open_type), 'user_type' => $user->getMorphClass()])->update([
UserSocialite::updateOrCreate([
'type' => SocialiteType::from($open_type),
'user_type' => $user->getMorphClass(),
'user_id' => $user->id,
], [
'openid' => $openid,
]);
}

View File

@ -32,9 +32,7 @@ class AuthController extends Controller
$openid = $request->input('openid');
$open_type = $request->input('open_type');
if ($openid && $open_type) {
UserSocialite::where(['openid' => $openid, 'type' => SocialiteType::from($open_type), 'user_type' => $user->getMorphClass()])->update([
'user_id' => $user->id,
]);
$this->updateUserSocialite($user, $openid, SocialiteType::from($open_type));
}
$token = $user->createToken('client')->plainTextToken;
return $this->response()->success(['token' => $token, 'user' => $user]);
@ -53,9 +51,7 @@ class AuthController extends Controller
$openid = $request->input('openid');
$open_type = $request->input('open_type');
if ($openid && $open_type) {
UserSocialite::where(['openid' => $openid, 'type' => SocialiteType::from($open_type), 'user_type' => $user->getMorphClass()])->update([
'user_id' => $user->id,
]);
$this->updateUserSocialite($user, $openid, SocialiteType::from($open_type));
}
DB::commit();
$token = $user->createToken('client')->plainTextToken;
@ -65,4 +61,15 @@ class AuthController extends Controller
return $this->response()->fail($e->getMessage());
}
}
protected function updateUserSocialite($user, $openid, $type)
{
UserSocialite::updateOrCreate([
'type' => $type,
'user_type' => $user->getMorphClass(),
'user_id' => $user->id,
], [
'openid' => $openid,
]);
}
}

View File

@ -16,7 +16,7 @@ return new class extends Migration
$table->string('type');
$table->nullableMorphs('user');
$table->string('openid');
$table->json('data');
$table->json('data')->nullable();
$table->timestamps();
});
}