0

嗯,那就麻烦了。代码很简单:

public function action_index()
{

    $post = $this->request->post();

    if ($post) {    
        // if I type it like this, manually - it will work
        $success = Auth::instance()->login('admin','password');

    }

    if (isset($success) and $success) { echo "Пользователь залогинен"; }

}

不幸的是,它只登录数据库中的第一条记录,这是管理员,因为默认配置在表中,如果我创建一个新用户。像这样:

$auth = Auth::instance();
        $user = new Model_User();
        $user->username = "Victor";
        $user->$auth->hash_password('psw123');
        $user->email = "me@email.com";
        $user->save();

而不是像我说的那样使用它,只使用真实数据作为

$post["email"] or $post["username"] with $post["password"]

代码:

if ($post) {    
    // the values from posts: 'Victor' or 'me@email.com` & 'psw123'
    $success = Auth::instance()->login('me@email.com','psw123');

}

它不会登录我。

upd我无法以管理员身份登录,但如果我将角色更改为login(它在数据库中为 1),则一切正常。但是如果角色将被设置为2(它是一个admin角色)它不会接受我,甚至不创建Auth.

        $post = $this->request->post();

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


        if ($success)
        {
            echo "SUCCESS!";
        }

再一次,如果角色为 2(这意味着管理员),这将不是 Success me 而不是login角色。

这个麻烦的原因是什么?

4

1 回答 1

2

I'm assuming you're using a default ORM auth driver. You don't need to hash your password when saving a new user - it is done automatically by a filter in the model. So saving a new user should look something like that:

$user = ORM::factory("user");
$user->username = "Victor";
$user->password = "psw123";
$user->email = "me@email.com";
$user->save();
于 2012-09-12T16:51:21.393 回答