Skip to content

Commit ab1a769

Browse files
Use Date for storing the password confirmation timestamp (#520)
1 parent e8b2010 commit ab1a769

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Http/Controllers/ConfirmablePasswordController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Contracts\Auth\StatefulGuard;
66
use Illuminate\Http\Request;
77
use Illuminate\Routing\Controller;
8+
use Illuminate\Support\Facades\Date;
89
use Laravel\Fortify\Actions\ConfirmPassword;
910
use Laravel\Fortify\Contracts\ConfirmPasswordViewResponse;
1011
use Laravel\Fortify\Contracts\FailedPasswordConfirmationResponse;
@@ -54,7 +55,7 @@ public function store(Request $request)
5455
);
5556

5657
if ($confirmed) {
57-
$request->session()->put('auth.password_confirmed_at', time());
58+
$request->session()->put('auth.password_confirmed_at', Date::now()->unix());
5859
}
5960

6061
return $confirmed

tests/ConfirmablePasswordControllerTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Foundation\Auth\User;
66
use Illuminate\Foundation\Testing\RefreshDatabase;
7+
use Illuminate\Support\Facades\Date;
78
use Laravel\Fortify\Contracts\ConfirmPasswordViewResponse;
89
use Laravel\Fortify\Fortify;
910
use Orchestra\Testbench\Attributes\WithMigration;
@@ -40,6 +41,8 @@ public function test_the_confirm_password_view_is_returned()
4041

4142
public function test_password_can_be_confirmed()
4243
{
44+
$this->freezeSecond();
45+
4346
$response = $this->withoutExceptionHandling()
4447
->actingAs($this->user)
4548
->withSession(['url.intended' => 'http://foo.com/bar'])
@@ -48,7 +51,7 @@ public function test_password_can_be_confirmed()
4851
['password' => 'secret']
4952
);
5053

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

@@ -86,6 +89,8 @@ public function test_password_confirmation_can_fail_without_a_password()
8689

8790
public function test_password_confirmation_can_be_customized()
8891
{
92+
$this->freezeSecond();
93+
8994
Fortify::$confirmPasswordsUsingCallback = function () {
9095
return true;
9196
};
@@ -98,14 +103,16 @@ public function test_password_confirmation_can_be_customized()
98103
['password' => 'invalid']
99104
);
100105

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

104109
Fortify::$confirmPasswordsUsingCallback = null;
105110
}
106111

107112
public function test_password_confirmation_can_be_customized_and_fail_without_password()
108113
{
114+
$this->freezeSecond();
115+
109116
Fortify::$confirmPasswordsUsingCallback = function () {
110117
return true;
111118
};
@@ -118,7 +125,7 @@ public function test_password_confirmation_can_be_customized_and_fail_without_pa
118125
['password' => null]
119126
);
120127

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

124131
Fortify::$confirmPasswordsUsingCallback = null;

0 commit comments

Comments
 (0)