HI,
In my application I had to adjust the User information aboard the session,
mi solution is as follows:
1. In the AppController set autoRedirect to false:
class AppController ... {
...
function beforeFilter() {
...
$this->Auth->autoRedirect = false;
...
}
2. In the UsersController::login action adjust the Session information as
follows:
class UsersController ... {
...
function login() {
if (! empty($this->data)) {
if ($this->Auth->user()) { // Successful login?
$this->_adjustSessionInfo();
}
}
}
3.- In UsersController::_adjustSessionInfo you can set o delete any
information you want from the Session,
class UsersController ... {
...
function __adjustSessionInfo() {
$session = $this->Auth->user();
// Add or remove any $key you want to $session['User]
// Removing 'created' key
unset($session['User']['created']);
// Adding 'fullName'
$session['User']['full_name'] = $fullName;
...
// IMPORTANT: Preparing to save information.
$session = $session['User'];
// Saving information
$this->Session->del($this->Auth->sessionKey);
$this->Session->write($this->Auth->sessionKey, $session);
}
}
Regards.
2009/3/13 ShuXun Liu <[email protected]>
> hi,all Is there any way to pre-define the fields of users model in Auth
> component as it control the login action automatically.
> By default , Auth retrieves all the fields in the user model, and save
> it into session.
> i think it's not necessary and will burden session's job .
>
> For example, i just want to requery and save two fields'
> data(username,city_id) of user model when login.
> How can i do it? Should i create my own auth component?
> i check the auth.php, It's not easy to change or extend it.
>
> Please help me , thanks...
>
> .
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---