Thursday, April 2, 2009

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

That's brilliant and simple, thanks for that. I boiled it down a bit
to something that fits right into the AuthComponent, as follows. Not
sure if it is core-worthy as I am fairly new with cake, but I will use
it via a subclass of AuthComponent for now (since it looks like I will
have one anyway for other reasons)....


/**
* Reloads the given field and value within in the session. If no
arguments
* are given, will read the AuthComponent::userModel and re-load the
Session
* using the result.
*
* @param string $field
* @param string $value
* @return void
*/
function refresh($field = '', $value = '') {
if (!empty($field) && !empty($value)) {
$this->Session->write($this->sessionKey .'.'. $field,
$value);
} elseif ($user =& $this->getModel()) {
$this->login($user->read(false, $this->user('id')));
}
}

cheers ~
Sam


On Apr 2, 5:27 pm, Miles J <mileswjohn...@gmail.com> wrote:
> 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', 'newem...@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: