Skip to content

Commit

Permalink
Adding updates to two factor auth
Browse files Browse the repository at this point in the history
  • Loading branch information
tnylea committed May 13, 2024
2 parents c24a0c4 + f522123 commit edb5870
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 51 deletions.
93 changes: 46 additions & 47 deletions resources/views/pages/auth/setup/providers.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,56 +29,55 @@ public function update($slug, $checked){
?>

<x-auth::layouts.setup>
<div>
<x-auth::layouts.setup>

@volt('auth.setup.providers')
<section class="relative px-4 py-5 mx-auto w-full max-w-screen-lg">
<x-auth::setup.full-screen-loader wire:target="update" />
<x-auth::setup.heading title="Social Providers" description="Select the social networks that users can use for authentication" />
<div class="relative w-full">
@if(!file_exists(base_path('config/devdojo/auth/providers.php')))
<x-auth::setup.config-notification />
@else
<div class="grid grid-cols-2">
@foreach($this->providers as $network_slug => $provider)

<div class="flex relative justify-between items-center max-w-sm border-b border-b-zinc-200">
<div class="flex relative justify-start items-center py-5 space-x-3">
<div class="flex items-center space-x-3">
<div class="w-7 h-7">
@if(isset($provider['svg']) && !empty(trim($provider['svg'])))
{!! $provider['svg'] !!}
@volt('auth.setup.providers')
<section class="relative px-4 py-5 mx-auto w-full max-w-screen-lg">
<x-auth::setup.full-screen-loader wire:target="update" />
<x-auth::setup.heading title="Social Providers" description="Select the social networks that users can use for authentication" />
<div class="relative w-full">
@if(!file_exists(base_path('config/devdojo/auth/providers.php')))
<x-auth::setup.config-notification />
@else
<div class="grid grid-cols-2">
@foreach($this->providers as $network_slug => $provider)

<div class="flex relative justify-between items-center max-w-sm border-b border-b-zinc-200">
<div class="flex relative justify-start items-center py-5 space-x-3">
<div class="flex items-center space-x-3">
<div class="w-7 h-7">
@if(isset($provider['svg']) && !empty(trim($provider['svg'])))
{!! $provider['svg'] !!}
@else
<span class="block w-full h-full rounded-full bg-zinc-200"></span>
@endif
</div>
<div class="relative">
<h4 class="text-base font-bold">{{ $provider['name'] }}</h4>
<p class="hidden text-sm">slug: {{ $network_slug }}</p>
</div>
</div>
<div class="relative right">
@if(isset($provider['client_id']) && !empty(trim($provider['client_id'])) && isset($provider['client_secret']) && !empty(trim($provider['client_secret'])))
<span x-tooltip="Keys have been added" class="flex justify-center items-center w-7 h-7 text-green-500 bg-green-100 rounded-full">
<x-phosphor-key-duotone class="w-4 h-4 text-green-500" />
<span>
@else
<span class="block w-full h-full rounded-full bg-zinc-200"></span>
<span x-tooltip="Missing keys for {{ strtoupper($network_slug) }}_CLIENT_ID and {{ strtoupper($network_slug) }}_CLIENT_SECRET inside your .env" class="flex justify-center items-center w-7 h-7 text-red-500 bg-red-100 rounded-full border-red-200">
<x-phosphor-key-duotone class="w-4 h-4 text-red-500" />
<span>
@endif
</div>
<div class="relative">
<h4 class="text-base font-bold">{{ $provider['name'] }}</h4>
<p class="hidden text-sm">slug: {{ $network_slug }}</p>
</div>
</div>
</div>
<div class="relative right">
@if(isset($provider['client_id']) && !empty(trim($provider['client_id'])) && isset($provider['client_secret']) && !empty(trim($provider['client_secret'])))
<span x-tooltip="Keys have been added" class="flex justify-center items-center w-7 h-7 text-green-500 bg-green-100 rounded-full">
<x-phosphor-key-duotone class="w-4 h-4 text-green-500" />
<span>
@else
<span x-tooltip="Missing keys for {{ strtoupper($network_slug) }}_CLIENT_ID and {{ strtoupper($network_slug) }}_CLIENT_SECRET inside your .env" class="flex justify-center items-center w-7 h-7 text-red-500 bg-red-100 rounded-full border-red-200">
<x-phosphor-key-duotone class="w-4 h-4 text-red-500" />
<span>
@endif
</div>
<x-auth::setup.checkbox wire:change="update('{{ $network_slug }}', $el.checked)" :checked="($provider['active'] ? true : false)" />
</div>
<x-auth::setup.checkbox wire:change="update('{{ $network_slug }}', $el.checked)" :checked="($provider['active'] ? true : false)" />
</div>
@endforeach
</div>
@endif
</div>
</section>
@endvolt

</x-auth::layouts.setup>


@endforeach
</div>
@endif
</div>
</section>
@endvolt

</x-auth::layouts.setup>
</div>
4 changes: 2 additions & 2 deletions resources/views/pages/auth/verify.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function resend()
<div class="mt-5 text-sm leading-6 text-gray-700 dark:text-gray-400">
<p>Before proceeding, please check your email for a verification link. If you did not receive the email, <a wire:click="resend" class="text-gray-700 underline transition duration-150 ease-in-out cursor-pointer dark:text-gray-300 hover:text-gray-600 focus:outline-none focus:underline">click here to request another</a>.</p>
</div>



<div class="mt-2 space-x-0.5 text-sm leading-5 text-center text-gray-600 translate-y-4 dark:text-gray-400">
Expand All @@ -71,7 +71,7 @@ public function resend()
@csrf
</form>
</div>

</x-auth::elements.container>
@endvolt

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Devdojo\Auth\Actions\TwoFactorAuth\GenerateQrCodeAndSecretKey;
name('user.two-factor-authentication');
//middleware(['auth', 'verified', 'password.confirm']);
middleware(['auth', 'verified', 'two-factor-enabled']);
// middleware(['auth'])
Expand Down Expand Up @@ -165,4 +164,4 @@ public function disable(){
</section>
@endvolt

</x-auth::layouts.empty>
</x-auth::layouts.empty>
24 changes: 24 additions & 0 deletions tests/Feature/AuthProvidersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

it('loads providers from configuration on mount', function () {
config()->set('devdojo.auth.providers', [
'google' => ['name' => 'Google', 'active' => true],
'facebook' => ['name' => 'Facebook', 'active' => false],
]);

Livewire::test('auth.setup.providers')
->assertSet('providers.google.active', true)
->assertSet('providers.facebook.active', false);
});

it('updates provider activation correctly and clears config cache', function () {
Livewire::test('auth.setup.providers')
->call('update', 'google', true)
->assertSet('providers.google.active', true);
assert(config('devdojo.auth.providers.google.active') === true);

Livewire::test('auth.setup.providers')
->call('update', 'google', false)
->assertSet('providers.google.active', false);
assert(config('devdojo.auth.providers.google.active') === false);
});

0 comments on commit edb5870

Please sign in to comment.