我正在尝试在 Kohana 3.3.0 中将 Auth 模块与 ORM 驱动程序一起使用,但我唯一能做的就是在数据库中插入新用户。我不能用他们登录。
我从一个空白的 Kohana 项目、一个简单的路由、数据库配置文件开始,然后导入了 ORM 模块中包含的 auth SQL 模式(没有其他表)。我没有为用户创建新的模型文件。
这是我复制到我的应用程序路径/配置目录的配置文件:
<?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()
);
现在这是我的简单控制器。我尝试将用户加载到 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...");
}
}
}
}
该控制器无法登录。但是当我检查我的数据库时,我看到用户已正确保存密码散列。我忘记了我的配置吗?