Вопрос

I'm trying to get cupcake forum plugin's login function to work.

In the users_controller.php,

since the $user variable in the login function was not populated, it was giving errors. So I modified the login function as below:

public function login() {
    if (!empty($this->data)) {
        $this->User->set($this->data);
        $this->User->action = 'login';
        //--------------code that i added--------------
        $username=$this->data['User']['username'];
        $password=$this->data['User']['password'];
        $user=$this->User->find('all',array(
                    'condition'=>array(
                            'User.username'=>$username,
                            'User.password'=>$password
                            )));

        print_r($user);
      //------------------------------------------------------------------------

        if ($this->User->validates()) {
            if ($user == $this->Auth->user()) {
                $this->User->login($user);
                $this->Session->delete('Forum');
                $this->redirect($this->Auth->loginRedirect);
            }
            else
                echo('i\'m not auth user');
        }
        else
            echo('not validated');
    }

    $this->Toolbar->pageTitle(__d('forum', 'Login', true));
}

print_r($user) displays all the users from User model. By right it should be displaying only the data of the user who has logged in. How can I achieve that? I'm clueless and this is driving me insane.

Это было полезно?

Решение

$user=$this->User->find('all',array(
                    'condition'=>array( // here
                            'User.username'=>$username,
                            'User.password'=>$password
                            )));

You have a typo - it should be conditions

As the key is invalid, Cake won't recognise it and just ignores it - so returns all your users.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top