Skip to content

Commit

Permalink
Adding more functionality to fix the PHP stan bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tnylea committed May 19, 2024
1 parent 2281a41 commit df2fe12
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
use function Laravel\Folio\{middleware, name};
use Livewire\Volt\Component;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Livewire\Attributes\On;
use PragmaRX\Google2FA\Google2FA;
use Devdojo\Auth\Actions\TwoFactorAuth\DisableTwoFactorAuthentication;
Expand Down Expand Up @@ -47,8 +49,9 @@ public function enable(){
}
private function generateCodes(){
$generateCodesFor = new GenerateNewRecoveryCodes();
return $generateCodesFor(auth()->user());
Collection::times(8, function () {
return Str::random(10).'-'.Str::random(10);;
});
}
public function cancelTwoFactor(){
Expand Down
5 changes: 3 additions & 2 deletions src/Actions/TwoFactorAuth/DisableTwoFactorAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace Devdojo\Auth\Actions\TwoFactorAuth;

use Devdojo\Auth\Events\TwoFactorAuthenticationDisabled;
use Devdojo\Auth\Models\User;

class DisableTwoFactorAuthentication
{
/**
* Disable two factor authentication for the user.
*
* @param mixed $user
* @param \Devdojo\Auth\Models\User $user
* @return void
*/
public function __invoke($user)
public function __invoke(User $user)
{
if (! is_null($user->two_factor_secret) ||
! is_null($user->two_factor_recovery_codes) ||
Expand Down
27 changes: 0 additions & 27 deletions src/Actions/TwoFactorAuth/GenerateNewRecoveryCodes.php

This file was deleted.

19 changes: 11 additions & 8 deletions src/Actions/TwoFactorAuth/GenerateQrCodeAndSecretKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,32 @@
use BaconQrCode\Renderer\ImageRenderer;
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Writer;
use Devdojo\Auth\Models\User;
use PragmaRX\Google2FA\Google2FA;

class GenerateQrCodeAndSecretKey
{
public string $companyName;
/**
* Generate new recovery codes for the user.
*
* @param mixed $user
* @return void
* @param \Devdojo\Auth\Models\User $user
* @return array{string, string}
*/
public function __invoke($user): array
public function __invoke(User $user): array
{

$google2fa = new Google2FA();
$secret_key = $google2fa->generateSecretKey();

//$secretKeyEncrypted = encrypt($secret_key);
//echo $google2fa->generateSecretKey();
$this->companyName = 'Auth';
if(is_string(config('app.name'))){
$this->companyName = config('app.name');
}

// TODO - Make sure config('app.name') works below.
$g2faUrl = $google2fa->getQRCodeUrl(
config('app.name'),
$user->email,
$this->companyName,
(string)$user->email,
$secret_key
);

Expand Down
3 changes: 2 additions & 1 deletion src/Http/Controllers/SocialController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Request;
use Illuminate\Http\RedirectResponse;
use Laravel\Socialite\Facades\Socialite;

class SocialController
Expand All @@ -18,7 +19,7 @@ public function __construct()

}

public function redirect(Request $request, $driver)
public function redirect(Request $request, string $driver): RedirectResponse
{
$this->dynamicallySetSocialProviderCredentials($driver);

Expand Down
10 changes: 9 additions & 1 deletion src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
use Illuminate\Foundation\Auth\User as Authenticatable;
use PragmaRX\Google2FA\Google2FA;

/**
* Class User
*
* @property string|null $email
* @property string|null $two_factor_secret
* @property string|null $two_factor_recovery_codes
* @property \Illuminate\Support\Carbon|null $two_factor_confirmed_at
*/
class User extends Authenticatable implements MustVerifyEmail
{
use HasSocialProviders;

protected $fillable = [
'name', 'email', 'password', 'two_factor_secret', 'two_factor_recovery_codes',
'name', 'email', 'password', 'two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at'
];

public function hasVerifiedEmail()
Expand Down

0 comments on commit df2fe12

Please sign in to comment.