views:

64

answers:

1

hello,

trying to develop some sort of login tracker for my cakephp application.

i know that i need code like:

$this->data['LoginSession']['username'] = $_SERVER['REMOTE_ADDR'];
$this->data['LoginSession']['ipAddress'] = $_SERVER['REMOTE_ADDR'];
$this->LoginSession->save($this->data);

... in (i guess) users_controller, but don't know exactly where.

also i would like to track successful, but also unsuccessful logins.

can you help me with this please? thank you in advance!

A: 

Do you already have the login function?

function login() {
    if ($this->Auth->user()) {
        //do your tracking stuff/DB call here
        $this->redirect($this->Auth->redirect());
    }
}
nolandark
i have something simular: $this->Auth->loginRedirect = array('controller' => 'publications'); but, login works fine, n problem with that. i just want to add this new feature that will track all login attempts.
Then do it before `if ($this->Auth->user()) {`.
bancer
AuthComponent will handle redirection for you (without running your `login()` action or doing any tracking) if you have `$this->Auth->autoRedirect` enabled (the default setting). If you want to handle the redirects yourself (with extra code for tracking) then you will need to turn autoredirect off. See the last example here: http://book.cakephp.org/view/1274/autoRedirect
deizel