-
Notifications
You must be signed in to change notification settings - Fork 988
/
LSWebUser.php
89 lines (73 loc) · 2.46 KB
/
LSWebUser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
Yii::import('application.helpers.Hash', true);
class LSWebUser extends CWebUser
{
protected $sessionVariable = 'LSWebUser';
public function __construct()
{
$this->loginUrl = Yii::app()->createUrl('admin/authentication', array('sa' => 'login'));
}
public function checkAccess($operation, $params = array(), $allowCaching = true)
{
if ($operation == 'administrator')
{
return Permission::model()->hasGlobalPermission('superadmin', 'read');
}
else
{
return parent::checkAccess($operation, $params, $allowCaching);
}
}
public function getStateKeyPrefix()
{
return $this->sessionVariable;
}
public function setFlash($key, $value, $defaultValue = null) {
$this->setState("flash.$key", $value, $defaultValue);
}
public function hasFlash($key) {
$this->hasState("flash.$key");
}
public function getFlashes($delete = true)
{
$result = $this->getState('flash', array());
$this->removeState('flash');
return $result;
}
public function getState($key, $defaultValue = null)
{
if (!isset($_SESSION[$this->sessionVariable]) || !Hash::check($_SESSION[$this->sessionVariable], $key))
{
return $defaultValue;
}
else
{
return Hash::get($_SESSION[$this->sessionVariable], $key);
}
}
/**
* Removes a state variable.
* @param string $key
*/
public function removeState($key)
{
$this->setState($key, null);
}
public function setState($key, $value, $defaultValue = null)
{
$current = isset($_SESSION[$this->sessionVariable]) ? $_SESSION[$this->sessionVariable] : array();
if($value === $defaultValue)
{
$_SESSION[$this->sessionVariable] = Hash::remove($current, $key);
}
else
{
$_SESSION[$this->sessionVariable] = Hash::insert($current, $key, $value);
}
}
public function hasState($key)
{
return isset($_SESSION[$this->sessionVariable]) && Hash::check($_SESSION[$this->sessionVariable], $key);
}
}
?>