Reputation: 13
I need to add possibility of Admin to enter User account, but i stucked when i change session data, i got logout.
$_SESSION['Auth']['User']['username']=$user_data['User']['username'];
To come back into admin session I made new variable
$_SESSION['Auth']['Admin']['id']=$user_id
Please help me to change admin data into user, and add possibility to come back as admin when logout
Upvotes: 1
Views: 361
Reputation: 290
Or you could just change the variables in the session as needed. I did it yesterday just changing the id of the logged user, but you can also change the stored username or email address or anything on session:
$this->Session->write('Auth.User.id',$newLoggedUserId);
$this->Session->write('Auth.User.username',$newLoggedUserName);
$this->Session->write('Auth.User.email',$newLoggedUserEmail);
Upvotes: 0
Reputation: 710
To login as a user when your are admin you can do this:
In your controller:
$user = $this->User->findById($idOfUserYouWantToLoginAs);
... // handle case where $user is empty
$this->Auth->login($user['User']);
Upvotes: 1