@@ -184,20 +184,23 @@ upon a successful login, change your login action to check the new
184184identity results:
185185
186186``` php
187- public function login()
187+ public function login(): ?\Cake\Http\Response
188188{
189189 $result = $this->Authentication->getResult();
190190
191- // regardless of POST or GET, redirect if user is logged in
191+ // Regardless of POST or GET, redirect if user is logged in
192192 if ($result->isValid()) {
193193 $target = $this->Authentication->getLoginRedirect();
194+
194195 return $this->redirect($target);
195196 }
196197
197- // display error if user submitted and authentication failed
198+ // Display error if user submitted and authentication failed
198199 if ($this->request->is('post')) {
199200 $this->Flash->error('Invalid username or password');
200201 }
202+
203+ return null;
201204}
202205```
203206
@@ -289,7 +292,7 @@ Then in your controller's login method you can use `getLoginRedirect()` to get
289292the redirect target safely from the query string parameter:
290293
291294``` php
292- public function login()
295+ public function login(): ?\Cake\Http\Response
293296{
294297 $result = $this->Authentication->getResult();
295298
@@ -300,8 +303,11 @@ public function login()
300303 if (!$target) {
301304 $target = ['controller' => 'Pages', 'action' => 'display', 'home'];
302305 }
306+
303307 return $this->redirect($target);
304308 }
309+
310+ return null;
305311}
306312```
307313
@@ -312,29 +318,33 @@ functionality. You can replicate that logic with this plugin by
312318leveraging the ` AuthenticationService ` :
313319
314320``` php
315- public function login()
321+ public function login(): ?\Cake\Http\Response
316322{
317323 $result = $this->Authentication->getResult();
318324
319- // regardless of POST or GET, redirect if user is logged in
325+ // Regardless of POST or GET, redirect if user is logged in
320326 if ($result->isValid()) {
321327 $authService = $this->Authentication->getAuthenticationService();
322328
323329 // Get the identifier that was used for authentication.
324330 $identifier = $authService->getIdentificationProvider();
325331 if ($identifier !== null && $identifier->needsPasswordRehash()) {
326332 // Rehash happens on save.
327- $user = $this->Users->get($this->Authentication->getIdentityData('id'));
333+ $user = $this->fetchTable('Users')->get(
334+ $this->Authentication->getIdentityData('id')
335+ );
328336 $user->password = $this->request->getData('password');
329- $this->Users->save ($user);
337+ $this->fetchTable(' Users')->saveOrFail ($user);
330338 }
331339
332340 // Redirect to a logged in page
333341 return $this->redirect([
334342 'controller' => 'Pages',
335343 'action' => 'display',
336- 'home'
344+ 'home',
337345 ]);
338346 }
347+
348+ return null;
339349}
340350```
0 commit comments