Skip to content

Commit

Permalink
Merge pull request #19 from thedevdojo/updateUerModel
Browse files Browse the repository at this point in the history
Fixing issues with login flicker
  • Loading branch information
tnylea authored May 24, 2024
2 parents 14d884d + ffc1894 commit 011c918
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 103 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ jobs:
run: php artisan migrate
working-directory: ./laravel_app

- name: Run the Auth Migrations
run: php artisan migrate --path=vendor/devdojo/auth/database/migrations
working-directory: ./laravel_app

# Testing on a mac, this command should be:
# sed -i '' '/"phpunit\/phpunit"/d' composer.json
- name: Remove PHPUnit from composer.json
Expand Down
2 changes: 1 addition & 1 deletion public/build/assets/styles.css

Large diffs are not rendered by default.

42 changes: 22 additions & 20 deletions resources/views/components/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@
@include('auth::includes.head')
</head>
<body id="auth-body" class="overflow-hidden relative w-screen h-screen" style="background-color:{{ config('devdojo.auth.appearance.background.color') }}">
@if(config('devdojo.auth.appearance.background.image'))
<img src="{{ config('devdojo.auth.appearance.background.image') }}" id="auth-background-image" class="object-cover absolute z-10 w-screen h-screen" />
<div id="auth-background-image-overlay" class="absolute inset-0 z-20 w-screen h-screen" style="background-color:{{ config('devdojo.auth.appearance.background.image_overlay_color') }}; opacity:{{ config('devdojo.auth.appearance.background.image_overlay_opacity') }};"></div>
@endif
<div x-data class="relative w-full h-full" x-cloak>
@if(config('devdojo.auth.appearance.background.image'))
<img src="{{ config('devdojo.auth.appearance.background.image') }}" id="auth-background-image" class="object-cover absolute z-10 w-screen h-screen" />
<div id="auth-background-image-overlay" class="absolute inset-0 z-20 w-screen h-screen" style="background-color:{{ config('devdojo.auth.appearance.background.image_overlay_color') }}; opacity:{{ config('devdojo.auth.appearance.background.image_overlay_opacity') }};"></div>
@endif

@php
$slotParentClasses = match(config('devdojo.auth.appearance.alignment.container')){
'left' => 'items-start h-screen',
'center' => 'items-stretch sm:items-center sm:py-10',
'right' => 'items-end h-screen',
};
@endphp
@php
$slotParentClasses = match(config('devdojo.auth.appearance.alignment.container')){
'left' => 'items-start h-screen',
'center' => 'items-stretch sm:items-center sm:py-10',
'right' => 'items-end h-screen',
};
@endphp

<main id="auth-main-content" class="flex relative z-30 flex-col justify-center w-screen min-h-screen {{ $slotParentClasses }}">
{{ $slot }}
</main>
<main id="auth-main-content" class="flex relative z-30 flex-col justify-center w-screen min-h-screen {{ $slotParentClasses }}">
{{ $slot }}
</main>

@if(config('devdojo.auth.settings.enable_branding') && !app()->isLocal())
<a href="https://devdojo.com/auth" target="_blank" class="flex fixed bottom-0 left-1/2 z-30 justify-center items-center px-2.5 py-1.5 w-auto text-xs font-medium rounded-t-lg border -translate-x-1/2 cursor-pointer bg-zinc-900 hover:bg-zinc-800/70 text-white/40 hover:text-white/80 border-zinc-800">
<svg class="mr-1 w-5 h-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 151 201" fill="none"><path fill="currentColor" fill-rule="evenodd" d="M75.847.132c-28.092 23.884-45.7 25-75 25v96.125c0 15.285 4.238 26.069 12.393 35.442l17.526-33.718.345-.661 5.06-9.74L76.496 35l40.323 77.58c20.95 2.616 30.894 8.93 30.894 8.93a219.818 219.818 0 0 0-24.117 1.321l-1.371.15c-1.345.158-2.69.326-4.017.502a227.52 227.52 0 0 0-41.712 9.705C50.36 141.907 30.44 153.7 18.4 161.993c9.303 8.615 22.183 16.475 38.353 26.344 5.927 3.616 12.296 7.503 19.093 11.795 6.796-4.292 13.165-8.179 19.091-11.795 16.494-10.066 29.564-18.042 38.907-26.861a205.398 205.398 0 0 0-35.223-19.64 225.71 225.71 0 0 1 30.106-6.358l10.533 20.272c7.627-9.153 11.586-19.721 11.586-34.493V25.132c-29.3 0-46.909-1.117-75-25Zm.649 112.615c-6.892.793-14.306 1.973-22.26 3.655l2.566-4.923 19.694-37.896 19.693 37.896c-6.582.089-13.155.513-19.693 1.268Z" clip-rule="evenodd"/></svg>
<p>Secured by DevDojo</p>
</a>
@endif
@if(config('devdojo.auth.settings.enable_branding') && !app()->isLocal())
<a href="https://devdojo.com/auth" target="_blank" class="flex fixed bottom-0 left-1/2 z-30 justify-center items-center px-2.5 py-1.5 w-auto text-xs font-medium rounded-t-lg border -translate-x-1/2 cursor-pointer bg-zinc-900 hover:bg-zinc-800/70 text-white/40 hover:text-white/80 border-zinc-800">
<svg class="mr-1 w-5 h-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 151 201" fill="none"><path fill="currentColor" fill-rule="evenodd" d="M75.847.132c-28.092 23.884-45.7 25-75 25v96.125c0 15.285 4.238 26.069 12.393 35.442l17.526-33.718.345-.661 5.06-9.74L76.496 35l40.323 77.58c20.95 2.616 30.894 8.93 30.894 8.93a219.818 219.818 0 0 0-24.117 1.321l-1.371.15c-1.345.158-2.69.326-4.017.502a227.52 227.52 0 0 0-41.712 9.705C50.36 141.907 30.44 153.7 18.4 161.993c9.303 8.615 22.183 16.475 38.353 26.344 5.927 3.616 12.296 7.503 19.093 11.795 6.796-4.292 13.165-8.179 19.091-11.795 16.494-10.066 29.564-18.042 38.907-26.861a205.398 205.398 0 0 0-35.223-19.64 225.71 225.71 0 0 1 30.106-6.358l10.533 20.272c7.627-9.153 11.586-19.721 11.586-34.493V25.132c-29.3 0-46.909-1.117-75-25Zm.649 112.615c-6.892.793-14.306 1.973-22.26 3.655l2.566-4.923 19.694-37.896 19.693 37.896c-6.582.089-13.155.513-19.693 1.268Z" clip-rule="evenodd"/></svg>
<p>Secured by DevDojo</p>
</a>
@endif
</div>
</body>
</html>
77 changes: 39 additions & 38 deletions resources/views/pages/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,44 +88,45 @@ public function authenticate()
?>

{{-- Needs a root div for all tests to pass correctly --}}
<div>
<x-auth::layouts.app title="{{ config('devdojo.auth.language.login.page_title') }}">
<x-auth::layouts.app title="{{ config('devdojo.auth.language.login.page_title') }}">
<div class="relative w-full h-full">
@volt('auth.login')
<x-auth::elements.container>

<x-auth::elements.heading
:text="($language->login->headline ?? 'No Heading')"
:description="($language->login->subheadline ?? 'No Description')"
:show_subheadline="($language->login->show_subheadline ?? false)" />

<form wire:submit="authenticate" class="mt-5 space-y-5">

@if($showPasswordField)
<x-auth::elements.input-placeholder value="{{ $email }}">
<button type="button" wire:click="editIdentity" class="font-medium text-blue-500">Edit</button>
</x-auth::elements.input-placeholder>
@else
<x-auth::elements.input label="Email Address" type="email" wire:model="email" autofocus="true" id="email" required />
@endif
<div class="relative w-full">
<x-auth::elements.container>

<x-auth::elements.heading
:text="($language->login->headline ?? 'No Heading')"
:description="($language->login->subheadline ?? 'No Description')"
:show_subheadline="($language->login->show_subheadline ?? false)" />

@if($showPasswordField)
<x-auth::elements.input label="Password" type="password" wire:model="password" id="password" />
<div class="flex justify-between items-center mt-6 text-sm leading-5">
<x-auth::elements.text-link href="{{ route('auth.password.request') }}">Forgot your password?</x-auth::elements.text-link>
</div>
@endif

<x-auth::elements.button type="primary" rounded="md" size="md" submit="true">Continue</x-auth::elements.button>
</form>


<div class="mt-3 space-x-0.5 text-sm leading-5 text-left" style="color:{{ config('devdojo.auth.appearance.color.text') }}">
<span class="opacity-[47%]">Don't have an account?</span>
<x-auth::elements.text-link href="{{ route('auth.register') }}">Sign up</x-auth::elements.text-link>
</div>

</x-auth::elements.container>
<form wire:submit="authenticate" class="mt-5 space-y-5">

@if($showPasswordField)
<x-auth::elements.input-placeholder value="{{ $email }}">
<button type="button" wire:click="editIdentity" class="font-medium text-blue-500">Edit</button>
</x-auth::elements.input-placeholder>
@else
<x-auth::elements.input label="Email Address" type="email" wire:model="email" autofocus="true" id="email" required />
@endif

@if($showPasswordField)
<x-auth::elements.input label="Password" type="password" wire:model="password" id="password" />
<div class="flex justify-between items-center mt-6 text-sm leading-5">
<x-auth::elements.text-link href="{{ route('auth.password.request') }}">Forgot your password?</x-auth::elements.text-link>
</div>
@endif

<x-auth::elements.button type="primary" rounded="md" size="md" submit="true">Continue</x-auth::elements.button>
</form>


<div class="mt-3 space-x-0.5 text-sm leading-5 text-left" style="color:{{ config('devdojo.auth.appearance.color.text') }}">
<span class="opacity-[47%]">Don't have an account?</span>
<x-auth::elements.text-link href="{{ route('auth.register') }}">Sign up</x-auth::elements.text-link>
</div>

</x-auth::elements.container>
</div>
@endvolt
</x-auth::layouts.app>
</div>
</div>
</x-auth::layouts.app>
77 changes: 37 additions & 40 deletions resources/views/pages/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,55 +98,52 @@ public function register()
?>

{{-- Needs a root div for all tests to pass correctly --}}
<div>
<x-auth::layouts.app title="{{ config('devdojo.auth.language.register.page_title') }}">
<x-auth::layouts.app title="{{ config('devdojo.auth.language.register.page_title') }}">

@volt('auth.register')
<x-auth::elements.container>
@volt('auth.register')
<x-auth::elements.container>

<x-auth::elements.heading
:text="($language->register->headline ?? 'No Heading')"
:description="($language->register->subheadline ?? 'No Description')"
:show_subheadline="($language->register->show_subheadline ?? false)" />
<x-auth::elements.heading
:text="($language->register->headline ?? 'No Heading')"
:description="($language->register->subheadline ?? 'No Description')"
:show_subheadline="($language->register->show_subheadline ?? false)" />

<form wire:submit="register" class="mt-5 space-y-5">
<form wire:submit="register" class="mt-5 space-y-5">

@if($showNameField)
<x-auth::elements.input label="Name" type="text" wire:model="name" autofocus="true" required />
@endif
@if($showNameField)
<x-auth::elements.input label="Name" type="text" wire:model="name" autofocus="true" required />
@endif

@if($showEmailField)
@php
$autofocusEmail = ($showNameField) ? false : true;
@endphp
<x-auth::elements.input label="Email Address" type="email" wire:model="email" :autofocus="$autofocusEmail" required />
@endif

@if($showEmailField)
@php
$autofocusEmail = ($showNameField) ? false : true;
@endphp
<x-auth::elements.input label="Email Address" type="email" wire:model="email" :autofocus="$autofocusEmail" required />
@endif
@if($showPasswordField)
<x-auth::elements.input label="Password" type="password" wire:model="password" id="password" required />
@endif

@if($showPasswordField)
<x-auth::elements.input label="Password" type="password" wire:model="password" id="password" required />
@endif
<x-auth::elements.button rounded="md" submit="true">Continue</x-auth::elements.button>
</form>

<x-auth::elements.button rounded="md" submit="true">Continue</x-auth::elements.button>
</form>
<div class="mt-3 space-x-0.5 text-sm leading-5 text-left" style="color:{{ config('devdojo.auth.appearance.color.text') }}">
<span class="opacity-[47%]">Already have an account?</span>
<x-auth::elements.text-link href="{{ route('auth.login') }}">Sign in</x-auth::elements.text-link>
</div>

<div class="mt-3 space-x-0.5 text-sm leading-5 text-left" style="color:{{ config('devdojo.auth.appearance.color.text') }}">
<span class="opacity-[47%]">Already have an account?</span>
<x-auth::elements.text-link href="{{ route('auth.login') }}">Sign in</x-auth::elements.text-link>
@if(count($this->social_providers))
<x-auth::elements.separator class="my-7">or</x-auto::elements.separator>
<div class="relative space-y-2 w-full">
@foreach($this->social_providers as $slug => $provider)
<x-auth::elements.social-button :$slug :$provider />
@endforeach
</div>

@if(count($this->social_providers))
<x-auth::elements.separator class="my-7">or</x-auto::elements.separator>
<div class="relative space-y-2 w-full">
@foreach($this->social_providers as $slug => $provider)
<x-auth::elements.social-button :$slug :$provider />
@endforeach
</div>
@endif
@endif


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

</x-auth::layouts.app>
</div>
</x-auth::layouts.app>
1 change: 1 addition & 0 deletions tests/Feature/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
$this->withoutExceptionHandling();
$this->mock(Registered::class);
config()->set('devdojo.auth.settings.registration_include_name_field', true);
config()->set('devdojo.auth.settings.registration_require_email_verification', false);

Livewire::test('auth.register')
->set('email', '[email protected]')
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/TwoFactorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
});

test('User logs in when two factor disabled, the login.id session should not be created', function () {
config()->set('devdojo.auth.settings.enable_2fa', false);
$user = createUser(['password' => \Hash::make('password123'), 'two_factor_confirmed_at' => now()]);

Livewire::test('auth.login')
Expand Down Expand Up @@ -61,6 +62,7 @@
});

it('user cannot view two factor challenge page logging in if it\'s disabled', function () {
config()->set('devdojo.auth.settings.enable_2fa', false);
$user = loginAsUser();
$this->get('user/two-factor-authentication')
->assertRedirect('/');
Expand Down

0 comments on commit 011c918

Please sign in to comment.