Thursday, April 2, 2009

Re: AuthComponent: reset session info on user->save()

The auth session never resets itself unless you log back in. I created
this method below:


/**
* Refreshes the Auth to get new data
* @param string $field
* @param string $value
* @return void
*/
function _refreshAuth($field = '', $value = '') {
if (!empty($field) && !empty($value)) {
$this->Session->write($this->Auth->sessionKey .'.'. $field,
$value);
} else {
if (isset($this->User)) {
$this->Auth->login($this->User->read(false, $this->Auth->user
('id')));
} else {
$this->Auth->login(ClassRegistry::init('User')->findById($this-
>Auth->user('id')));
}
}
}

Place that in your app_controller and call it like so: $this-
>_refreshAuth('email', 'newemail@domain.com');
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: