generated from filamentphp/plugin-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
160 additions
and
32 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
{ | ||
"Secure your account": "Secure your account", | ||
"Your account has been secured with two factor authentication": "Your account has been secured with two factor authentication", | ||
"Activate": "Activate", | ||
"Add additional security to your account using two factor authentication": "Add additional security to your account using two factor authentication", | ||
"You have three options to confirm your identity, please choose one of the options below to continue": "You have three options to confirm your identity, please choose one of the options below to continue", | ||
"Two-Factor Authentication enabled": "Two-Factor Authentication enabled", | ||
"Or scan the QR code with your authenticator app": "Or scan the QR code with your authenticator app", | ||
"The secret key to setup the authenticator app is": "The secret key to setup the authenticator app is", | ||
"Save these recovery codes in a secure place as they can be used to recover access to your account if you lose your device.": "Save these recovery codes in a secure place as they can be used to recover access to your account if you lose your device.", | ||
"Authenticate with your code": "Authenticate with your code", | ||
"Cancel": "Cancel", | ||
"Code": "Code", | ||
"Confirm": "Confirm", | ||
"Deactivate": "Deactivate", | ||
"Login": "Login", | ||
"Authenticate with your code": "Authenticate with your code", | ||
"Or scan the QR code with your authenticator app": "Or scan the QR code with your authenticator app", | ||
"Password Confirmation": "Password Confirmation", | ||
"Recovery code": "Recovery code", | ||
"Resend": "Resend", | ||
"Reset Password": "Reset Password", | ||
"Save these recovery codes in a secure place as they can be used to recover access to your account if you lose your device.": "Save these recovery codes in a secure place as they can be used to recover access to your account if you lose your device.", | ||
"Secure your account": "Secure your account", | ||
"Submit": "Submit", | ||
"Resend": "Resend", | ||
"Successfully resend the OTP code": "Successfully resend the OTP code", | ||
"Recovery code": "Recovery code", | ||
"Password Confirmation": "Password Confirmation", | ||
"Confirm": "Confirm", | ||
"Verify": "Verify", | ||
"Code": "Code", | ||
"The secret key to setup the authenticator app is": "The secret key to setup the authenticator app is", | ||
"Two-Factor Authentication": "Two-Factor Authentication", | ||
"Activate": "Activate", | ||
"Deactivate": "Deactivate" | ||
"Two-Factor Authentication enabled": "Two-Factor Authentication enabled", | ||
"Verify": "Verify", | ||
"You have three options to confirm your identity, please choose one of the options below to continue": "You have three options to confirm your identity, please choose one of the options below to continue", | ||
"Your account has been secured with two factor authentication": "Your account has been secured with two factor authentication", | ||
"Your security code for :app": "Your security code for :app", | ||
"Your security code is": "Your security code is" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
{ | ||
"Secure your account": "Beveilig uw account", | ||
"Your account has been secured with two factor authentication": "Uw account is beveiligd met tweestaps-verificatie", | ||
"Activate": "Activeer", | ||
"Add additional security to your account using two factor authentication": "Voeg extra beveiliging toe aan uw account met tweestaps-verificatie", | ||
"You have three options to confirm your identity, please choose one of the options below to continue": "U heeft drie opties om uw identiteit te bevestigen, kies een van de onderstaande opties om door te gaan", | ||
"Two-Factor Authentication enabled": "Tweestaps-verificatie ingeschakeld", | ||
"Or scan the QR code with your authenticator app": "Of scan de QR-code met uw authenticator-app", | ||
"The secret key to setup the authenticator app is": "De geheime sleutel om de authenticator-app in te stellen is", | ||
"Save these recovery codes in a secure place as they can be used to recover access to your account if you lose your device.": "Bewaar deze herstelcodes op een veilige plaats, omdat ze kunnen worden gebruikt om toegang tot uw account te herstellen als u uw apparaat verliest.", | ||
"Authenticate with your code": "Verifieer met uw authenticatiecode", | ||
"Cancel": "Annuleren", | ||
"Code": "Code", | ||
"Confirm": "Bevestigen", | ||
"Deactivate": "Deactiveer", | ||
"Login": "Inloggen", | ||
"Authenticate with your code": "Verifieer met uw authenticatiecode", | ||
"Or scan the QR code with your authenticator app": "Of scan de QR-code met uw authenticator-app", | ||
"Password Confirmation": "Wachtwoordbevestiging", | ||
"Recovery code": "Herstelcode", | ||
"Resend": "Opnieuw Verzenden", | ||
"Reset Password": "Wachtwoord Resetten", | ||
"Save these recovery codes in a secure place as they can be used to recover access to your account if you lose your device.": "Bewaar deze herstelcodes op een veilige plaats, omdat ze kunnen worden gebruikt om toegang tot uw account te herstellen als u uw apparaat verliest.", | ||
"Secure your account": "Beveilig uw account", | ||
"Submit": "Verzenden", | ||
"Resend": "Opnieuw Verzenden", | ||
"Successfully resend the OTP code": "OTP-code succesvol opnieuw verzonden", | ||
"Recovery code": "Herstelcode", | ||
"Password Confirmation": "Wachtwoordbevestiging", | ||
"Confirm": "Bevestigen", | ||
"Verify": "Verifiëren", | ||
"Code": "Code", | ||
"The secret key to setup the authenticator app is": "De geheime sleutel om de authenticator-app in te stellen is", | ||
"Two-Factor Authentication": "Tweestaps-verificatie", | ||
"Activate": "Activeer", | ||
"Deactivate": "Deactiveer" | ||
"Two-Factor Authentication enabled": "Tweestaps-verificatie ingeschakeld", | ||
"Verify": "Verifiëren", | ||
"You have three options to confirm your identity, please choose one of the options below to continue": "U heeft drie opties om uw identiteit te bevestigen, kies een van de onderstaande opties om door te gaan", | ||
"Your account has been secured with two factor authentication": "Uw account is beveiligd met tweestaps-verificatie", | ||
"Your security code for :app": "Uw beveiligingscode voor :app", | ||
"Your security code is": "Uw beveiligingscode is" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Vormkracht10\TwoFactorAuth\Actions; | ||
|
||
use PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException; | ||
use PragmaRX\Google2FA\Exceptions\InvalidCharactersException; | ||
use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException; | ||
use PragmaRX\Google2FA\Google2FA; | ||
|
||
class GenerateOTP | ||
{ | ||
/** | ||
* @throws IncompatibleWithGoogleAuthenticatorException | ||
* @throws SecretKeyTooShortException | ||
* @throws InvalidCharactersException | ||
*/ | ||
public static function for(string $secret): string | ||
{ | ||
return app(Google2FA::class)->getCurrentOtp($secret); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Vormkracht10\TwoFactorAuth\Listeners; | ||
|
||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Vormkracht10\TwoFactorAuth\Notifications\SendOTP; | ||
use Laravel\Fortify\Events\TwoFactorAuthenticationEnabled; | ||
use Laravel\Fortify\Events\TwoFactorAuthenticationChallenged; | ||
|
||
class SendTwoFactorCodeListener | ||
{ | ||
/** | ||
* Create the event listener. | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Handle the event. | ||
*/ | ||
public function handle(TwoFactorAuthenticationChallenged|TwoFactorAuthenticationEnabled $event): void | ||
{ | ||
$event->user->notify(app(SendOTP::class)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace Vormkracht10\TwoFactorAuth\Notifications; | ||
|
||
use App\Models\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Notification; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Vormkracht10\TwoFactorAuth\Actions\GenerateOTP; | ||
use Vormkracht10\TwoFactorAuth\Enums\TwoFactorType; | ||
use PragmaRX\Google2FA\Exceptions\InvalidCharactersException; | ||
use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException; | ||
use PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException; | ||
|
||
class SendOTP extends Notification implements ShouldQueue | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* Create a new notification instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Get the notification's delivery channels. | ||
* | ||
* @return array<int, string> | ||
*/ | ||
public function via(object $notifiable): array | ||
{ | ||
return $notifiable->two_factor_type === TwoFactorType::email ? ['mail'] : []; | ||
} | ||
|
||
/** | ||
* Get the mail representation of the notification. | ||
*/ | ||
public function toMail(object $notifiable): MailMessage | ||
{ | ||
return (new MailMessage) | ||
->subject(__('Your security code for :app', ['app' => config('app.name')])) | ||
->line(__('Your security code is') . ' ' . $this->getTwoFactorCode($notifiable)); | ||
} | ||
|
||
/** | ||
* Get the array representation of the notification. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(object $notifiable): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
|
||
/** | ||
* @throws IncompatibleWithGoogleAuthenticatorException | ||
* @throws SecretKeyTooShortException | ||
* @throws InvalidCharactersException | ||
*/ | ||
public function getTwoFactorCode(User $notifiable): ?string | ||
{ | ||
if (!$notifiable->two_factor_secret) { | ||
return null; | ||
} | ||
|
||
return GenerateOTP::for( | ||
decrypt($notifiable->two_factor_secret) | ||
); | ||
} | ||
} |