Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Date facade for storing the password confirmation timestamp #520

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Http/Controllers/ConfirmablePasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Date;
use Laravel\Fortify\Actions\ConfirmPassword;
use Laravel\Fortify\Contracts\ConfirmPasswordViewResponse;
use Laravel\Fortify\Contracts\FailedPasswordConfirmationResponse;
Expand Down Expand Up @@ -54,7 +55,7 @@ public function store(Request $request)
);

if ($confirmed) {
$request->session()->put('auth.password_confirmed_at', time());
$request->session()->put('auth.password_confirmed_at', Date::now()->unix());
}

return $confirmed
Expand Down
13 changes: 10 additions & 3 deletions tests/ConfirmablePasswordControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Foundation\Auth\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Date;
use Laravel\Fortify\Contracts\ConfirmPasswordViewResponse;
use Laravel\Fortify\Fortify;
use Orchestra\Testbench\Attributes\WithMigration;
Expand Down Expand Up @@ -40,6 +41,8 @@ public function test_the_confirm_password_view_is_returned()

public function test_password_can_be_confirmed()
{
$this->freezeSecond();

$response = $this->withoutExceptionHandling()
->actingAs($this->user)
->withSession(['url.intended' => 'http://foo.com/bar'])
Expand All @@ -48,7 +51,7 @@ public function test_password_can_be_confirmed()
['password' => 'secret']
);

$response->assertSessionHas('auth.password_confirmed_at');
$response->assertSessionHas('auth.password_confirmed_at', Date::now()->unix());
$response->assertRedirect('http://foo.com/bar');
}

Expand Down Expand Up @@ -86,6 +89,8 @@ public function test_password_confirmation_can_fail_without_a_password()

public function test_password_confirmation_can_be_customized()
{
$this->freezeSecond();

Fortify::$confirmPasswordsUsingCallback = function () {
return true;
};
Expand All @@ -98,14 +103,16 @@ public function test_password_confirmation_can_be_customized()
['password' => 'invalid']
);

$response->assertSessionHas('auth.password_confirmed_at');
$response->assertSessionHas('auth.password_confirmed_at', Date::now()->unix());
$response->assertRedirect('http://foo.com/bar');

Fortify::$confirmPasswordsUsingCallback = null;
}

public function test_password_confirmation_can_be_customized_and_fail_without_password()
{
$this->freezeSecond();

Fortify::$confirmPasswordsUsingCallback = function () {
return true;
};
Expand All @@ -118,7 +125,7 @@ public function test_password_confirmation_can_be_customized_and_fail_without_pa
['password' => null]
);

$response->assertSessionHas('auth.password_confirmed_at');
$response->assertSessionHas('auth.password_confirmed_at', Date::now()->unix());
$response->assertRedirect('http://foo.com/bar');

Fortify::$confirmPasswordsUsingCallback = null;
Expand Down