3

我在使用 Auth / ORM 和 auto_login 时遇到问题。我将生命周期设置为两周,但无论浏览器是否关闭,我都会在大约一个小时后注销。事实上,它是基于时间的,因为会话确实保持不变,即使在浏览器关闭时也是如此。

我已经设置了这样的东西(任何帮助将不胜感激!!!):

引导程序.php

Cookie::$salt = 'some random string here';

配置/auth.php

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

return array(

'driver'       => 'ORM',
'hash_method'  => 'sha256',
'hash_key'     => '<another random string>',
'lifetime'     => 1209600, // TWO WEEKS, NO?
'session_type' => Session::$default,
'session_key'  => 'auth_user',

// Username/password combinations for the Auth File driver
'users' => array(
),

);

类/控制器/auth.php

public function action_login() { // Check to make sure the user isn't already logged in... if (Auth::instance()->logged_in() || Auth::instance()->auto_login()) {
$this->request->redirect($this->request->referrer()); }

$referrer = base64_encode($this->request->referrer());

$post = $this->request->post();
if (!empty($post))
{
    $remember = isset($post['remember']); // <-- This value has been verified
    Auth::instance()->login(Arr::get($post, 'email'), Arr::get($post, 'password'), $remember);

    if (Auth::instance()->logged_in())
    {
        $this->request->redirect(base64_decode(Arr::get($post, 'referrer')));
    }
    else
    {
        $this->view->set('error', true);
    }

    if (isset($post['referrer']))
    {
        $referrer = Arr::get($post, 'referrer');
    }
}

$this->view = Template::factory('auth/login');
$this->view->set('referrer', $referrer);

} 

类/控制器/website.php

class Controller_Website extends Controller { 
    public function before()
    {
        $parent_before = parent::before();

        if (Auth::instance()->logged_in() || Auth::instance()->auto_login()) //<-- isn't this where the magic is supposed to be happening?!?!
        {
            $this->user = Auth::instance()->get_user();
        }
        elseif ($this->require_auth && !in_array($this->request->action(), $this->auth_allow_actions))
        {
            $this->request->redirect('/auth/login');
        }

        return $parent_before;
    }
}
4

1 回答 1

0

尝试像这样设置 $remember:

$remember = array_key_exists('remember', $this->request->post()) ? (bool) $this->request->post('remember') : FALSE;
于 2012-05-25T15:17:00.777 回答