2011-12-21 127 views

回答

2

這很簡單,我建議你自己做,我認爲比研究如何實現和使用新的擴展,會節省大量的時間。

將列CHECK_SUM,STATUS添加到您的用戶表中。 CHECK_SUM用於存儲加密值或任何可用於檢查用戶的隨機值,列STATUS默認爲0,當選中電子郵件地址時,將其設置爲1以使此帳戶能夠登錄。

當用戶提交他們的登記表格:

function encrypt($pswd) 
{ 
    ....//make your own encrypt method to store uses' password 
} 
//suppose your user model is Users 
$users->email=$_POST['email']; 
$users->pswd=encrypt($_POST['pswd']); 
... 
//here comes the customized part 
$users->check_sum=sha1($_POST['email'].time());//or other method to make a safe random string 
if($users->save()) 
{ 
    $to=...; 
    $subject=...; 
    //suppose your reg page is in reg controller. 
    $msg='please visit <a href="domain.com/reg/check?sum='.$users->check_sum.'">this url</a> to finish registration'; 
    mail($to,$subject,$msg,$header); 
} 

在你REG控制器,添加:

public function actionCheck() 
    { 
    if(isset($_GET['sum'])) 
    { 
     $c=new CDbCriteria; 
     $c->condition="check_sum=:i"; 
     $c->params=array($i=>$_GET['sum']); 
     $user=Users::model()->find($c); 
     if($user) 
     { 
     $user->status=1; 
     $user->save(); 
     $this->redirect('http://...'); 
     } 
    } 
    } 

這是我的解決方案。

+0

能否向我解釋你指的是什麼reg控制器 – KItis 2011-12-22 04:20:16

+0

reg控制器用於創建像domain.com/reg/xxx(這裏我們需要的是domain.com/reg/check)之類的url。如果url格式對您不重要,您可以在任何控制器中添加該actionCheck()函數(例如用戶控制器(url將變成x.com/user/check)或您的註冊頁面屬於哪個) – LotusH 2011-12-22 08:42:54

0

實際上有一個擴展用戶管理yii-user,它是一個包含註冊的許多功能的模塊。您始終可以參考源代碼來開發自己的註冊系統。

相關問題