Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Commit

Permalink
feat: remember me for login form (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
Highjhacker authored Jul 7, 2021
1 parent 0d939a3 commit 805bf5f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions resources/lang/en/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'sign-in' => [
'forgot_password' => 'Forgot password?',
'register_now' => 'Not a member? <a href=":route" class="font-semibold underline link">Sign up</a>',
'remember_me' => 'Remember Me',
],

'register-form' => [
Expand Down
14 changes: 10 additions & 4 deletions resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ class="w-full"
/>
</div>

<div class="flex flex-col-reverse items-center justify-between space-y-4 md:space-y-0 md:flex-row">
<x-ark-checkbox name="remember" :errors="$errors">
@slot('label')
@lang('fortify::auth.sign-in.remember_me')
@endslot
</x-ark-checkbox>

<div class="flex flex-col-reverse items-center justify-between space-y-4 sm:space-y-0 sm:flex-row">
@if(Route::has('password.request'))
<div class="flex-1 mt-8 md:mt-0">
<a href="{{ route('password.request') }}" class="link">@lang('fortify::auth.sign-in.forgot_password')</a>
<div class="flex-1 mt-8 sm:mt-0">
<a href="{{ route('password.request') }}" class="link font-semibold">@lang('fortify::auth.sign-in.forgot_password')</a>
</div>
@endif

<button type="submit" class="w-full button-secondary md:w-auto">
<button type="submit" class="w-full button-secondary sm:w-auto">
@lang('fortify::actions.sign_in')
</button>
</div>
Expand Down
29 changes: 29 additions & 0 deletions tests/Actions/AuthenticateUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

$this->assertNotNull($loggedUser);
$this->assertTrue($user->is($loggedUser));
$this->assertFalse($request->filled('remember'));
});

it('login the user by the email when alt username is set', function () {
Expand All @@ -44,6 +45,7 @@

$this->assertNotNull($loggedUser);
$this->assertTrue($user->is($loggedUser));
$this->assertFalse($request->filled('remember'));
});

it('login the user by the alt username (username)', function () {
Expand All @@ -64,6 +66,7 @@

$this->assertNotNull($loggedUser);
$this->assertTrue($user->is($loggedUser));
$this->assertFalse($request->filled('remember'));
});

it('doesnt login the user by the alt username if not set (username)', function () {
Expand All @@ -83,6 +86,7 @@
$loggedUser = $authenticator->handle();

$this->assertNull($loggedUser);
$this->assertFalse($request->filled('remember'));
});

it('doesnt login the user if password is incorrect', function () {
Expand All @@ -102,3 +106,28 @@

$this->assertNull($loggedUser);
});

it('should handle the remember me checkbox', function () {
Config::set('fortify.models.user', \ARKEcosystem\Fortify\Models\User::class);
Config::set('fortify.username_alt', 'username');

$user = User::factory()->withUsername()->create();

$request = new Request();

$this->assertFalse($request->filled('remember'));

$request->replace([
'email' => $user->username,
'password' => 'password',
'remember' => true,
]);

$authenticator = new AuthenticateUser($request);
$loggedUser = $authenticator->handle();

$this->assertNotNull($loggedUser);
$this->assertTrue($user->is($loggedUser));

$this->assertTrue($request->filled('remember'));
});

0 comments on commit 805bf5f

Please sign in to comment.