本文整理汇总了PHP中Roles::getUserTimeout方法的典型用法代码示例。如果您正苦于以下问题:PHP Roles::getUserTimeout方法的具体用法?PHP Roles::getUserTimeout怎么用?PHP Roles::getUserTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Roles
的用法示例。
在下文中一共展示了Roles::getUserTimeout方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetUserTimeout
public function testGetUserTimeout()
{
$this->assertTrue(Yii::app()->cache->flush());
$defaultTimeout = 60;
Yii::app()->settings->timeout = $defaultTimeout;
// admin's timeout should be the big one based on role
$this->assertEquals($this->role('longTimeout')->timeout, Roles::getUserTimeout($this->user('admin')->id, false));
// testuser's timeout should also be the big one, and not the "Peon"
// role's timeout length
$this->assertEquals($this->role('longTimeout')->timeout, Roles::getUserTimeout($this->user('testUser')->id, false));
// testuser2's timeout should be the "Peon" role's timeout length
// because that user has that role, and that role has a timeout longer
// than the default timeout
$this->assertEquals($this->role('shortTimeout')->timeout, Roles::getUserTimeout($this->user('testUser2')->id, false));
// testuser3 should have no role. Here, let's ensure that in case the
// fixtures have been modified otherwise
RoleToUser::model()->deleteAllByAttributes(array('userId' => $this->user('testUser3')->id));
$this->assertEquals($defaultTimeout, Roles::getUserTimeout($this->user('testUser3')->id, false));
}
示例2: cleanUpSessions
/**
* Clear session records which have timed out. Log the timeout.
*/
public static function cleanUpSessions()
{
// Only select users with active sessions to clear out, in case there are
// dozens of inactive users, to make things more efficient:
$users = Yii::app()->db->createCommand()->select('x2_users.id,x2_users.username')->from('x2_users')->rightJoin('x2_sessions', 'x2_sessions.user = x2_users.username')->where('x2_users.username IS NOT NULL AND x2_users.username != ""')->queryAll();
foreach ($users as $user) {
$timeout = Roles::getUserTimeout($user['id']);
$sessions = X2Model::model('Session')->findAllByAttributes(array('user' => $user['username']), 'lastUpdated < :cutoff', array(':cutoff' => time() - $timeout));
foreach ($sessions as $session) {
SessionLog::logSession($session->user, $session->id, 'passiveTimeout');
$session->delete();
}
}
// check timeout on sessions not corresponding to any existing user
$defaultTimeout = 900;
self::model()->deleteAll(array('condition' => 'lastUpdated < :cutoff and
user not in (select distinct (username) from x2_users)', 'params' => array(':cutoff' => time() - $defaultTimeout)));
}
示例3: beginRequest
//.........这里部分代码省略.........
$this->owner->params->profile = X2Model::model('Profile')->findByAttributes(array('username' => $this->owner->user->getName()));
$this->setSuModel($this->owner->params->profile->user);
} else {
$this->owner->params->profile = Profile::model()->getGuestProfile();
}
} else {
// Use the admin profile as the user profile.
//
// If a different profile is desired in an API call or console
// command, a different profile should be loaded.
//
// Using "admin" as the default profile should not affect
// permissions (that's what the "suModel" property is for). It is
// merely to account for cases where there is a reference to the
// "profile" property of some model or component class that would
// break the application outside the scope of a web request with a
// session and cookie-based authentication.
$notGuest = false;
$this->owner->params->profile = $adminProf;
$userModel = $this->owner->params->profile->user;
$this->setSuModel($userModel instanceof User ? $userModel : User::model()->findByPk(1));
}
// Set session variables
if (!$noSession) {
$sessionId = isset($_SESSION['sessionId']) ? $_SESSION['sessionId'] : session_id();
$session = X2Model::model('Session')->findByPk($sessionId);
if (!empty($this->owner->params->profile)) {
$_SESSION['fullscreen'] = $this->owner->params->profile->fullscreen;
}
if (!($this->owner->request->getPathInfo() == 'site/getEvents')) {
if ($notGuest) {
$this->owner->user->setReturnUrl($this->owner->request->requestUri);
if ($session != null) {
$timeout = Roles::getUserTimeout($this->owner->user->getId());
if ($session->lastUpdated + $timeout < time()) {
SessionLog::logSession($this->owner->user->getName(), $sessionId, 'activeTimeout');
$session->delete();
$this->owner->user->logout(false);
$this->_suModel = null;
$this->_suID = null;
$this->setUserAccessParameters(null);
} else {
// Print a warning message
if ($this->owner->session['debugEmailWarning']) {
$this->owner->session['debugEmailWarning'] = 0;
$this->owner->user->setFlash('admin.debugEmailMode', Yii::t('app', 'Note, email debugging mode ' . 'is enabled. Emails will not ' . 'actually be delivered.'));
}
$session->lastUpdated = time();
$session->update(array('lastUpdated'));
$this->owner->params->sessionStatus = $session->status;
}
} else {
$this->owner->user->logout(false);
}
} else {
// Guest
$this->setUserAccessParameters(null);
}
}
}
// Configure logos
if (!($logo = $this->owner->cache['x2Power'])) {
$logo = 'data:image/png;base64,' . base64_encode(file_get_contents(implode(DIRECTORY_SEPARATOR, array(Yii::app()->basePath, '..', 'images', 'powered_by_x2engine.png'))));
$this->owner->cache['x2Power'] = $logo;
}
$this->owner->params->x2Power = $logo;