1 <?php
2
3 class WebUser extends CWebUser
4 {
5
6 7 8
9 public $allowAutoLogin=true;
10 11 12 13 14 15 16
17 public $loginUrl=array('/user/login');
18
19 public function getRole()
20 {
21 return $this->getState('__role');
22 }
23
24 public function getId()
25 {
26 return $this->getState('__id') ? $this->getState('__id') : 0;
27 }
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 protected function afterLogin($fromCookie)
44 {
45 parent::afterLogin($fromCookie);
46 $this->updateSession();
47 }
48
49 public function updateSession() {
50 $user = Yii::app()->getModule('user')->user($this->id);
51 $this->name = $user->username;
52 $userAttributes = CMap::mergeArray(array(
53 'email'=>$user->email,
54 'username'=>$user->username,
55 'create_at'=>$user->create_at,
56 'lastvisit_at'=>$user->lastvisit_at,
57 ),$user->profile->getAttributes());
58 foreach ($userAttributes as $attrName=>$attrValue) {
59 $this->setState($attrName,$attrValue);
60 }
61 }
62
63 public function model($id=0) {
64 return Yii::app()->getModule('user')->user($id);
65 }
66
67 public function user($id=0) {
68 return $this->model($id);
69 }
70
71 public function getUserByName($username) {
72 return Yii::app()->getModule('user')->getUserByName($username);
73 }
74
75 public function getAdmins() {
76 return Yii::app()->getModule('user')->getAdmins();
77 }
78
79 public function isAdmin() {
80 return Yii::app()->getModule('user')->isAdmin();
81 }
82
83 }