2012-01-27 52 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