Auto-login to CakePHP

Do I use a registration form for different users? After a new user logs in, registered users must redirect to the page after login. We use the Auth component for authentication.

How to do it?

+3
source share
4 answers

If you want the user to automatically log in after registration, you can use the login () method of AuthComponent.

if ($this->User->save($this->data)) {
    $this->Auth->login($this->data);
}
+6
source

On new cakes you need to add

$this->Auth->login();

after adding the user to the database.

+3
source

, , , , - . , :

$this->Auth->loginAction = array (
   'controller' => 'whichever_controller',
   'action'     => 'desired_action',
   'admin'      => true
);

admin , /admin/whichever_controller/desired_action.

0
source

You will need to call the login method manually from your register action.

Store the username + unhashed password in the array, then call it from the method after saving as follows:

$data = array('username' => 'user', 'password' => $unhashedPw);
$this->User->login($data);
0
source

Source: https://habr.com/ru/post/1718446/


All Articles