tags:

views:

185

answers:

3

I have

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

which retrieves the current user from the session.

I want to make an admin user be able to 'act as' a customer. And I was hoping to be able to just replace the customer_id in the user session when they enter the customer interface.

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

This doesn't work because I can't find a way to push the $user data back into Auth

A: 

If you are simply checking the customer_id on the session to determine if that user is of the type customer, instead of:

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

I would try:

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

weisjohn
Missing the Auth for 'Auth.User.customer_id'
Jack B Nimble
A: 

Try combining $this->Auth->logout() and then $this->Auth->login() with the customers' data.

However, you need to implement additional logic if you want your admin to be able to return to his account without entering his credentials again. It's a no brainer, but worth mentioning.

dr Hannibal Lecter
+2  A: 

This should work:

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

Please note that this approach of just changing the customer_id can have some side effects if you are also using Acl and group based permission model.

duckyflip