无法使用Kohana 3.3.0 ORM Auth登录

Rom*_*lus 4 kohana kohana-orm kohana-auth

我想在Kohana 3.3.0中使用带有ORM驱动程序的Auth模块,但我唯一能做的就是在数据库中插入新用户.我不能用他们登录.

我从一个空白的Kohana项目,一个简单的路径,数据库配置文件开始,然后我导入了ORM模块中包含的auth SQL模式(没有其他表).我没有为用户创建新的模型文件.

这是我复制到app path/config目录的配置文件:

<?php defined('SYSPATH') or die('No direct access allowed.');

return array(

        'driver'       => 'ORM',
        'hash_method'  => 'sha256',
        'hash_key'     => 'secretkey',
        'lifetime'     => 1209600,
        'session_type' => Session::$default,
        'session_key'  => 'auth_user',
        'users'        => array()

);
Run Code Online (Sandbox Code Playgroud)

现在这是我的简单控制器.我尝试将用户加载到te数据库,然后使用该用户登录.

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_User extends Controller {

    public function action_index(){

        // Enter a new user manually
        $user = ORM::factory('user');
        $user->username = 'mylogin';
        $user->password = 'mypassword';
        $user->email = 'me@email.fr';

        try{
            $user->save();
        }
        catch(ORM_Validation_Exception $e){
            $errors = $e->errors();
        }

        if(isset($errors)){
            $this->response->body(var_dump($errors));
        }else{

            // Login with this user
            $success = Auth::instance()->login('mylogin','mypassword');
            if ($success){
                $this->response->body("Welcome !");
            }else{
                $this->response->body("Not welcome...");
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

此控制器无法登录.但是当我检查我的数据库时,我看到用户已正确保存密码哈希值.我忘记了配置吗?

bia*_*ron 8

每个用户都必须有一个login角色:

...
$user->save();
$user->add('roles', ORM::factory('role')->where('name', '=', 'login')->find());
Run Code Online (Sandbox Code Playgroud)