无法使用Auth :: login()登录

时间:2014-03-13 08:10:26

标签: php kohana kohana-3 kohana-3.3

我记得登录角色,我不知道哪里出了问题。

这是一些代码: 配置/ auth.php

return array(

        'driver'       => 'ORM',
        'hash_method'  => 'sha256',
        'hash_key'     => 'hashKey',
        'lifetime'     => 1209600,
        'session_type' => Session::$default,
        'session_key'  => 'auth_user',

        'users' => array(
                // 'admin' => 'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02',
        ),

);

//用户模型

class Model_User extends Model_Auth_User {

    protected $_has_many = array('roles' =>
        array(
            'model' => 'Role',
            'foreign_key' => 'user_id',
            'through' => 'roles_users',
            )); 
}

//注册

  

$ auth = Auth :: instance();           $ user = ORM :: factory('user');

    $user->username = $this->post['email'];

    $user->email    = $this->post['email'];

    $user->password = $auth->hash($this->post['password']);

    $user->type     = 3; // Ordinary user
    $user->active   = 0; // It will be inactive till he ativates via mail

    try {
        $user->save();
    // and so on

激活

    $user = ORM::factory('user', $this->request->param('id'));
    $user->active = 1;
    // login role
    $user->add('roles', ORM::factory('role', array('name' => 'login')));
    $user->save();

登录

Auth::instance()->login($post['email'], $post['password']);

            if (! Auth::instance()->logged_in()) {

不幸的是,logged_in是假的。我不知道为什么。

我会赞美任何帮助

1 个答案:

答案 0 :(得分:2)

  

$ user-> password = $ auth-> hash($ this-> post [' password']);

Kohana正在使用它自己的密码。将此行更改为:

$user->password = $this->post['password'];