0

我正在使用 Tank Auth,并要求我的用户验证他们的电子邮件地址。验证后,用户仍未登录。我希望用户在激活帐户时自动登录。

在我以前的版本(本土认证)中,我编写了一个不需要密码的登录函数,它只能在那种情况下调用。但是,我在 Tank Auth 中看不到这样做的方法。一种解决方案是在激活之前缓存密码,但我真的不想这样做......

4

2 回答 2

1

You can just bypass your login system.

Store either thier email address OR alias in a cookie.

when they activate grab the cookie, search(verify they exist) for the user, then setup a normal login session.

A login is just a set of session rules.

inside your activation script/email process, append

$this->_set_ac_cookie({email});

-

protected function _set_ac_cookie({email})
{
    return $this->input->set_cookie(array(
        'name'  =>  'ac_cookie_'.{email},
        'expire'    =>  '7200', //You may mirror when/if your activation key expires
        'domain'    =>  'yourdomain.com',
        'path'  =>  '/'
    ));
}

check cookie exists

protected function _before_activation({email})
{
    return $this->input->cookie('ac_cookie_'.{email})) ? TRUE : FALSE;
    //make sure {email} has a UNIQUE db constraint
}

when the user clicks the activation link

if($this->_before_activation({email}))
{
        //check user exists AND activation status === false (0)
        //grab the user details from db based on {email}, set activation status to true (1)

        //setup login session
        $this->session->set_userdata(array(
            'logged_in' =>  (int)1,
            'user_id'   =>  {user->id},
            'alias' =>  {user->alias}
        ));

        redirect('dashboard');
}
else
{
    //sorry!
}
于 2012-01-27T18:41:39.467 回答
1

如果您查看处理电子邮件激活的 tank auth 中的代码,您会看到它在电子邮件验证中明确将用户注销。

https://github.com/ilkon/Tank-Auth/blob/master/application/controllers/auth.php

第 243 行。

$this->tank_auth->logout();您可以在第 244 行注释掉它,它应该可以按您的意愿工作,但这是不好的做法。

于 2012-01-27T17:08:57.877 回答