gpt4 book ai didi

remember-me - Kohana 3.2 验证 ORM : I can't seem to stay logged in with the "remember me" option set

转载 作者:行者123 更新时间:2023-12-04 02:50:41 28 4
gpt4 key购买 nike

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

我已经像这样设置了东西(如果有任何帮助,我们将不胜感激!!!):

bootstrap.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(
),

);

类/ Controller /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);

}

类/ Controller /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;
}
}

最佳答案

尝试像这样设置 $remember:

$remember = array_key_exists('remember', $this->request->post()) ? (bool) $this->request->post('remember') : FALSE;

关于remember-me - Kohana 3.2 验证 ORM : I can't seem to stay logged in with the "remember me" option set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10730304/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com