开发者

Login with Kohana auth module - what am I doing wrong?

开发者 https://www.devze.com 2022-12-27 18:20 出处:网络
I\'m trying to login with the following controller action, but my login attempt keeps failing (I get the \'invalid username and/or password\' message).What am I doing wrong?I also tried the other meth

I'm trying to login with the following controller action, but my login attempt keeps failing (I get the 'invalid username and/or password' message). What am I doing wrong? I also tried the other method given in the examples in the auth documentation, Auth::instance()->login($user->username, $form->password);, but I get the same result. Kohana version is 2.3.4.

public function login() {
    $auth = Auth::instance();
    if ($auth->logged_in()) {
        url::redir开发者_开发百科ect('/account/summary');
    }

    $view = new View('login');
    $view->username = '';
    $view->password = '';

    $post = $this->input->post();
    $form = new Validation($post);
    $form->pre_filter('trim', 'username')
         ->pre_filter('trim', 'password')
         ->add_rules('username', 'required');

    $failed = false;
    if (!empty($post) && $form->validate()) {
        $login = array(
            'username'  => $form->username,
            'password'  => $form->password,
        );
        if (ORM::factory('user')->login($login)) {
            url::redirect('/accounts/summary');
        } else {
            $view->username = $form->username;
            $view->message = in_array('required', $form->errors()) ?
                             'Username and password are required.' :
                             'Invalid username and/or password.';
        }
    }

    $view->render(true);
}


Figured out my problem... Something in my registration process is missing, because it's creating the user record but not the role-to-user assoc record. Login needs a specific role to log in to, or it won't work even with a valid username and password. Manually inserting the record allowed my to log in, so I'll just have to debug my registration action a bit.

0

精彩评论

暂无评论...
验证码 换一张
取 消