1
votes

I have created app where I used the AuthComponent for user authentication.

It is working fine.

but I have created one function which login user with user data as follows.

protected function __login_user($conditions) {
    $this->User->recursive = -1;
    $userData = $this->User->find('first', array('condtions' => $conditions));
    unset($userData['User']['password']);
    if( !empty( $userData ) ) {
            $this->Auth->login($userData['User']);
            return true;
    } else {
        return false;
    }
}

This function works fine when I login with ajax.

But if it is http request with post/get it work as::

It redirect me to the login redirect link, show the session for auth too just one time.

When I refresh the page the session get loss and logout.

Does anyone know why this happening?

1
Try this return $this->Auth->login($userData['User']);. - Indrasinh Bihola
Still it is not working. - Pankaj Badukale

1 Answers

0
votes

Your function is declared protected in php and as it includes at least a preceding underscore character in the name (_) it is "private" to cake and can't be accessed from the outside world.