How to change user session after user login using CakePHP?

I have

$user = $this->Auth->user();

      

which fetches the current user from the session.

I want the admin user to be able to "act like" the client. And I was hoping I could just replace the customer_id in the user session when they enter the UI.

$user['User']['customer_id'] = 4;

      

It doesn't work because I can't find a way to return user $ data in Auth

+1


a source to share


3 answers


This should work:

$this->Session->write('Auth.User.customer_id', 4);

      



Note that this approach of only changing the customer_id may have some side effects if you are also using the Acl and group based permission model.

+3


a source


If you just check the client_id on the session to determine if that user is a type, not:

$ user ['User'] ['customer_id'] = 4;



I would try:

$ this-> Session-> write ('User.customer_id', '4');

0


a source


Try to combine $this->Auth->logout()

and then $this->Auth->login()

with customer data.

However, you need to implement additional logic if you want your administrator to be able to return to their account without entering their credentials again. This is not a problem, but worth mentioning.

0


a source







All Articles