Reputation: 5087
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
Upvotes: 1
Views: 1115
Reputation: 16499
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.
Upvotes: 3
Reputation: 6721
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.
Upvotes: 0
Reputation: 803
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');
Upvotes: 0