On Fri, Jun 19, 2009 at 11:12 AM, u2ix<[email protected]> wrote:
>
> Hello
>
> I want to update a field in database (loginCount) after successful
> login.
> But I found now way where to insert this action, without to make a
> redirect, as a callback or similar.
> If I insert it in Users/login it will only be executed on getting the
> login page, as I see?
>
You should be able to do this inside login(). Can you post your code?
I'm doing something similar, except that the logins are saved to a
separate table. This way, I can keep a record of dates/times.
CREATE TABLE IF NOT EXISTS logins
(
id INT(10) UNSIGNED NOT NULL auto_increment PRIMARY KEY,
created DATETIME DEFAULT NULL,
user_id INT(10) UNSIGNED NOT NULL,
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
)
ENGINE=MyISAM
class Login extends AppModel
{
public $belongsTo = array('User');
}
public $hasMany = array(
'Login' => array(
'className' => 'Login',
'foreignKey' => 'user_id',
'dependent' => true
)
);
UsersController:
// this is the stripped-down version
public function login()
{
if ($user = $this->Auth->user())
{
$this->User->Login->create();
$this->User->Login->save(
array(
'Login' => array(
'user_id' => $user['User']['id']
)
)
);
}
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---