我有一个网站,我想检查用户是否已经从另一台设备登录。我在用户表中存储了一个会话值,我需要一些条件来防止这种情况发生。
我有这个登录过程的代码:
public static function login($request)
{
if (empty($request)) {
return false;
}
Zend_Session::regenerateId();
$authAdapter = new Zend_Auth_Adapter_DbTable();
$authAdapter->setTableName('ah_users');
$authAdapter->setCredential($request['password']);
$authAdapter->setCredentialTreatment('MD5(?)');
$authAdapter->setCredentialColumn('password');
$authAdapter->setIdentity($request['username']);
$authAdapter->setIdentityColumn('nname');
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
$authData = $authAdapter->getResultRowObject();
$user = new Model_AhUsers((array) $authData);
if(!$user->isActive()) return 3; //if user is activated
if($authData->role == 'admin' && $authData->payment != 'completed') return 4;
//here i want to query if user is logged in from another browser / pc device to return 1
$user->seskey = Zend_Session::getId();
$user->update();
self::setLoggedUser($user);
return 0;
}
return 2;
}
而且我也有这些功能,但无论我如何组合它们,它都不能正常工作。
public static function isLogged()
{
$auth = Zend_Auth::getInstance();
return $auth->hasIdentity();
}
public static function setLoggedUser(Model_AhUsers $user)
{
$auth = Zend_Auth::getInstance();
$storage = $auth->getStorage();
$storage->write($user);
}
/**
* @return Model_AhUsers|null
*/
public static function getLoggedUser()
{
$auth = Zend_Auth::getInstance();
return $auth->getIdentity();
}
public function logout()
{
$auth = Zend_Auth::getInstance();
$auth->clearIdentity();
}