【发布时间】:2012-05-03 22:57:55
【问题描述】:
我使用 Zend_auth 进行身份验证。代码如下:
$authAdapter = $this->getAuthAdapter();
$authAdapter->setIdentity($username)
->setCredential($password);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
# is the user a valid one?
if ($result->isValid()) {
# all info about this user from the login table
# ommit only the password, we don't need that
$userInfo = $authAdapter->getResultRowObject(null, 'password');
# the default storage is a session with namespace Zend_Auth
$authStorage = $auth->getStorage();
$authStorage->write($userInfo);
$emp_id = $userInfo->employee_id;
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$array_db = new Application_Model_SetMstDb();
$array_name = $array_db->getName($emp_id);
foreach ($array_name as $name) :
$fname = $name['first_name'];
$lname = $name['last_name'];
endforeach;
$firstname = new stdClass;
$lastname = new stdClass;
$userInfo->firstname = $fname;
$userInfo->lastname = $lname;
$privilege_id = $userInfo->privilege_id;
echo 'privilege in Login: ' . $privilege_id;
$this->_redirect('index/index');
} else {
$errorMessage = "Invalid username or password";
$this->view->error = $errorMessage;
}
其中getAuthAdapter()如下:
protected function getAuthAdapter() {
$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('credentials')
->setIdentityColumn('employee_id')
->setCredentialColumn('password');
return $authAdapter;
}
我想设置一个会话超时。我想设置一个 5 分钟的超时,当用户 5 分钟没有处于活动状态时,会话应该过期,即应该调用注销操作,其代码如下:
public function logoutAction() {
// action body
Zend_Auth::getInstance()->clearIdentity();
$this->_redirect('login/index');
}
提前谢谢。请帮帮我。很紧急。
当我使用时
$session = new Zend_Session_Namespace( 'Zend_Auth' );
$session->setExpirationSeconds( 60 );
控件在 60 秒后自动重定向到登录页面,但我希望如果应用程序的用户在 60 秒内处于非活动状态,那么只有它会重定向。目前无论用户是否处于活动状态,都会发生重定向。
【问题讨论】:
-
如果我将使用 $session = new Zend_Session_Namespace( 'Zend_Auth' ); $session->setExpirationSeconds(60);那么如何检查 60 秒是否已经完成以及在哪里检查它,就像它必须在每个控制器的 init() 方法中检查一样。
-
请给一些代码sn-p
标签: php zend-framework zend-auth