我想将用户登录和注销/会话到期信息添加到数据库中,正常登录和注销很容易,但我不知道如何进行自动会话到期。
我的身份验证如下所示。
我的登录控制器操作
if ($request->isPost()) {
$data = $request->getParams();
$userModel = new Application_Model_User_DbTable();
if ($user = $userModel->login($data['email'], $data['password'])) {
/* check if user is activated or not */
if ($user['status'] == 0) {
$this->view->loginerror = "<b>Account not active :</b> Please wait for admin to activate your account";
}elseif($user['status'] == -1){
$this->view->loginerror = "<b>Account Suspended :</b> Your account is suspeneded you must contact admin to continue";
}else {
/* Store authentication data in session */
$auth = Zend_Auth::getInstance();
$identity = Zend_Auth::getInstance()->getStorage();
$identity->write($user);
$this->_redirect('/fax');
}
} else {
$this->view->loginerror = "<b>Invalid login :</b> Email or passsword is invalid !";
}
}
我的用户控件中的身份验证方法
function authenticate($email, $password) {
$where = array();
$where[] = $this->getAdapter()->quoteinto('email = ?', $email);
$user = $this->fetchRow($where);
if (isset($user['email'])) {
$salt = $user['password_salt'];
if (sha1($password . $salt) == $user['password']) {
/** here i will add login session info**/
return $user;
}
return false;
}
return false;
}