2012-01-27 93 views
0

我正在使用坦克认证,并要求我的用户验证他们的电子邮件地址。经过验证,用户仍未登录。我希望用户在激活其帐户时自动登录。坦克认证:自动登录电子邮件验证

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

+0

你的问题是什么? – SeanNieuwoudt 2012-01-27 16:42:58

+0

我如何在电子邮件验证中自动登录用户? – Mala 2012-01-27 16:59:48

+0

看到这个(由图书馆本人作者给出的解决方案): http://stackoverflow.com/questions/4729194/codeigniter-tank-auth – developer10 2012-02-06 23:03:25

回答

1

你可以绕过你的登录系统。

将他们的电子邮件地址或别名存储在cookie中。

当他们激活抓取cookie,搜索(验证他们存在)为用户,然后设置一个正常的登录会话。

登录只是一组会话规则。

您激活脚本/电子邮件的过程中,追加

$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' => '/' 
    )); 
} 

检查cookie存在

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

当U ser点击激活链接

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! 
} 
+0

真棒,谢谢。我主要使用了这样的东西,基本上写了一个非常类似于你最后一个codeblock的force_login()函数 – Mala 2012-01-27 22:03:41

1

如果你看看tank auth中处理电子邮件激活的代码,你会看到它通过电子邮件验证明确记录用户。

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

线你可以只注释掉$this->tank_auth->logout();上线244,它应该工作,只要你想它,但是这将是不好的做法。

+0

从我可以在代码中看到的情况,只适用于用户登录未激活,从而得到一个未激活的会话去吧 – Mala 2012-01-27 22:02:51