Вопрос

I've remembered about login role and I don't know where's a problem.

Here's some code: config/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',
        ),

);

// user model

class Model_User extends Model_Auth_User {

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

// register

$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

activating

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

logging in

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

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

And unfortunately logged_in is false. I have no idea why.

I would appriciate any help

Это было полезно?

Решение

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

Kohana is hashing passwords by it's own. Change this line to:

$user->password = $this->post['password'];
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top