Created
November 27, 2023 22:20
-
-
Save jcnevado/a12298f314784da70593910a417d4a90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function login_2fa() { | |
try { | |
//code... | |
$google2fa = new \PragmaRX\Google2FA\Google2FA(); | |
$credentials = request(['email', 'verification_code']); | |
$user = User::where('email', $credentials['email'])->first(); | |
$window = request('working_time', true) === false ? 5 : 0; | |
$valid = $google2fa->verifyKey($user->secret_2fa, $credentials['verification_code'], $window); | |
$status = $status2 = true; | |
$error = $error2 = ''; | |
if ($valid === false) { | |
$status = false; | |
$error = 'Code Usuario incorrecto'; | |
} | |
if (!$token = auth('api-jwt')->login($user)) { | |
$status = false; | |
$error = 'Login incorrecto'; | |
return response()->json(['status' => false, 'error' => 'Unauthorized'], 401); | |
} | |
$user->login_retries = 0; | |
$user->status = "1"; | |
$payload = auth('api-jwt')->payload(); | |
if ($payload) { | |
$user->login_expiration = $payload['exp']; | |
} | |
$user->last_login = time(); | |
$user->save(); | |
//event(new SlackLoginSuccessEvent($credentials['email'], true)); | |
return $this->respondWithToken($token); | |
} catch (\Throwable $th) { | |
return $th->getMessage(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment