This repository was archived by the owner on Feb 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathWebUser.php
More file actions
86 lines (72 loc) · 2.5 KB
/
Copy pathWebUser.php
File metadata and controls
86 lines (72 loc) · 2.5 KB
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
<?php
class WebUser extends CWebUser
{
/**
* @var boolean whether to enable cookie-based login. Defaults to false.
*/
public $allowAutoLogin=true;
/**
* @var string|array the URL for login. If using array, the first element should be
* the route to the login action, and the rest name-value pairs are GET parameters
* to construct the login URL (e.g. array('/site/login')). If this property is null,
* a 403 HTTP exception will be raised instead.
* @see CController::createUrl
*/
public $loginUrl=array('/user/login');
public function getRole()
{
return $this->getState('__role');
}
public function getId()
{
return $this->getState('__id') ? $this->getState('__id') : 0;
}
// protected function beforeLogin($id, $states, $fromCookie)
// {
// parent::beforeLogin($id, $states, $fromCookie);
//
// $model = new UserLoginStats();
// $model->attributes = array(
// 'user_id' => $id,
// 'ip' => ip2long(Yii::app()->request->getUserHostAddress())
// );
// $model->save();
//
// return true;
// }
protected function afterLogin($fromCookie)
{
parent::afterLogin($fromCookie);
$this->updateSession();
}
public function updateSession() {
$user = Yii::app()->getModule('user')->user($this->id);
if ($user!==false){
$this->name = $user->username;
$userAttributes = CMap::mergeArray(array(
'email'=>$user->email,
'username'=>$user->username,
'create_at'=>$user->create_at,
'lastvisit_at'=>$user->lastvisit_at,
),$user->profile->getAttributes());
foreach ($userAttributes as $attrName=>$attrValue) {
$this->setState($attrName,$attrValue);
}
}
}
public function model($id=0) {
return Yii::app()->getModule('user')->user($id);
}
public function user($id=0) {
return $this->model($id);
}
public function getUserByName($username) {
return Yii::app()->getModule('user')->getUserByName($username);
}
public function getAdmins() {
return Yii::app()->getModule('user')->getAdmins();
}
public function isAdmin() {
return Yii::app()->getModule('user')->isAdmin();
}
}