郵件激活代碼實現
如果用戶激活的時間超過24小時,說明激活連接過期,這個時候,重新發送激活郵件;
//郵箱激活操作
public function activate()
{
//接收超鏈接身上傳遞的用戶id以及生產的唯一口令
$user_id = $_GET['uid'];
$acive_code = $_GET['code'];
//獲得用戶模型
$m_user = Factory::M('UserModel');
//基礎模型中,封裝過find()方法根據主鍵查詢用戶信息
//但是當時封裝的是protected,如果想在這裏使用將其改爲public
$user = $m_user -> find($user_id);
if($user){
//激活鏈接是有效的
//判斷激活時間是否過期
if(time()-$user['active_code_time']>24*3600){
//重新發送激活郵件,還需要先生成新的口令並更新數據庫
$data['user_id'] = $user_id;
$data['active_code'] = md5(mt_rand(10000,99999).time());
$data['active_code_time'] = time();
//將基礎模型中的proteced修改爲public
$m_user -> update($data);
$this -> sendMail($user_id,$data['active_code'],$user['email']);
$this -> jumpWait('激活鏈接已過期,重新發送激活郵件,請重新查收並激活',
'index.php?m=home&c=user&a=register');
}else{
//激活成功,更新數據表,將is_active修改爲1
$data['user_id'] = $user_id;
$data['is_active'] = 1;
$m_user -> update($data);
//直接登錄
$this -> jumpNow('index.php?m=home&c=user&a=login');
}
}else{
//沒有找到,說明激活鏈接無效的
$this -> jumpWait('激活鏈接無效','index.php?m=home&c=user&a=register');
}
}
登錄判斷,郵件激活狀態