Login Googgle (Verificar que exista en la lista de confianza)
This commit is contained in:
parent
80637327ee
commit
1d342997ca
@ -31,44 +31,49 @@ public function handleProviderCallback($provider){
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$userProvider = Socialite::driver($provider) ->stateless()->user();
|
$userProvider = Socialite::driver($provider) ->stateless()->user();
|
||||||
error_log(json_encode($userProvider->user));
|
|
||||||
}
|
}
|
||||||
catch (ClientException $exception) {
|
catch (ClientException $exception) {
|
||||||
return response()->json(['error' => 'Credenciales de google invalidas.'],422);
|
return response()->json(['error' => 'Credenciales de google invalidas.'],422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isset(User::where("email","=", $userProvider->email)->first()){
|
||||||
|
$userCreated = User::firstOrCreate(
|
||||||
|
[
|
||||||
|
'email' => $userProvider->email
|
||||||
|
],
|
||||||
|
[
|
||||||
|
//'email_verified_at' => now(),
|
||||||
|
'name' => $userProvider->user['given_name'],
|
||||||
|
'lastname' => $userProvider->user['family_name'],
|
||||||
|
'status' => true
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$userCreated->providers()->updateOrCreate(
|
||||||
|
[
|
||||||
|
'provider' => $provider,
|
||||||
|
'id_provider' => $userProvider->getId()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'avatar' => $userProvider->getAvatar()
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
$userCreated = User::firstOrCreate(
|
$token = $userCreated->createToken('token-auth_token')->plainTextToken;
|
||||||
[
|
return response()->json([
|
||||||
'email' => $userProvider->email
|
"message" => "Usuario logueado",
|
||||||
],
|
"user" => $userCreated,
|
||||||
[
|
"image" => $userProvider->getAvatar(),
|
||||||
//'email_verified_at' => now(),
|
"role" => $userCreated->roles[0]->name,
|
||||||
'name' => $userProvider->user['given_name'],
|
"access_token" => $token
|
||||||
'lastname' => $userProvider->user['family_name'],
|
]);
|
||||||
'status' => true
|
}
|
||||||
]
|
else{
|
||||||
);
|
return response()->json([
|
||||||
|
"status" => 0,
|
||||||
$userCreated->providers()->updateOrCreate(
|
"message" => "Usuario no registrado en el sistema",
|
||||||
[
|
], 404);
|
||||||
'provider' => $provider,
|
}
|
||||||
'id_provider' => $userProvider->getId()
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'avatar' => $userProvider->getAvatar()
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$token = $userCreated->createToken('token-auth_token')->plainTextToken;
|
|
||||||
return response()->json([
|
|
||||||
"message" => "Usuario logueado",
|
|
||||||
"user" => $userCreated,
|
|
||||||
"image" => $userProvider->getAvatar(),
|
|
||||||
|
|
||||||
"access_token" => $token
|
|
||||||
]);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user