File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ class SessionAuthAdapter implements AuthenticatableInterface
4040{
4141 use AuthTrait;
4242
43+ private const REMEMBER_TOKEN_LIFETIME = 2592000 ;
44+
4345 /**
4446 * @throws AuthException
4547 */
@@ -201,7 +203,15 @@ private function setRememberToken(User $user): void
201203 [$ this ->keyFields [AuthKeys::REMEMBER_TOKEN ] => $ rememberToken ]
202204 );
203205
204- cookie ()->set ($ this ->keyFields [AuthKeys::REMEMBER_TOKEN ], $ rememberToken );
206+ cookie ()->set (
207+ $ this ->keyFields [AuthKeys::REMEMBER_TOKEN ],
208+ $ rememberToken ,
209+ self ::REMEMBER_TOKEN_LIFETIME ,
210+ '/ ' ,
211+ '' ,
212+ true ,
213+ true
214+ );
205215 }
206216
207217 /**
Original file line number Diff line number Diff line change @@ -63,6 +63,34 @@ public function testWebSigninWithRemember(): void
6363 $ this ->assertTrue ($ this ->sessionAuth ->check ());
6464 }
6565
66+ public function testWebSigninWithRememberSetsCookie (): void
67+ {
68+ $ this ->assertFalse (cookie ()->has ('remember_token ' ));
69+
70+ $ this ->sessionAuth ->signin ('admin@qt.com ' , 'qwerty ' , true );
71+
72+ $ this ->assertTrue (cookie ()->has ('remember_token ' ));
73+ $ this ->assertNotEmpty (cookie ()->get ('remember_token ' ));
74+ }
75+
76+ public function testWebSigninWithoutRememberDoesNotSetCookie (): void
77+ {
78+ $ this ->sessionAuth ->signin ('admin@qt.com ' , 'qwerty ' );
79+
80+ $ this ->assertFalse (cookie ()->has ('remember_token ' ));
81+ }
82+
83+ public function testWebSignoutRemovesRememberCookie (): void
84+ {
85+ $ this ->sessionAuth ->signin ('admin@qt.com ' , 'qwerty ' , true );
86+
87+ $ this ->assertTrue (cookie ()->has ('remember_token ' ));
88+
89+ $ this ->sessionAuth ->signout ();
90+
91+ $ this ->assertFalse (cookie ()->has ('remember_token ' ));
92+ }
93+
6694 public function testWebSignout (): void
6795 {
6896 $ this ->assertFalse ($ this ->sessionAuth ->check ());
You can’t perform that action at this time.
0 commit comments