3 class User extends CActiveRecord
34 public static function model($className = __CLASS__)
44 return Yii::app()->getModule(
'user')->tableUsers;
54 return ((get_class(Yii::app()) ==
'CConsoleApplication' || (get_class(Yii::app()) !=
'CConsoleApplication' && Yii::app()->getModule(
'user')->isAdmin())) ? array(
55 array(
'username',
'length',
'max' => 20,
'min' => 3,
'message' =>
UserModule::t(
"Incorrect username (length between 3 and 20 characters).")),
56 array(
'password',
'length',
'max' => 128,
'min' => 4,
'message' =>
UserModule::t(
"Incorrect password (minimal length 4 symbols).")),
57 array(
'email',
'email'),
58 array(
'username',
'unique',
'message' =>
UserModule::t(
"This user's name already exists.")),
59 array(
'email',
'unique',
'message' =>
UserModule::t(
"This user's email address already exists.")),
60 array(
'username',
'match',
'pattern' =>
'/^[A-Za-z0-9_]+$/u',
'message' =>
UserModule::t(
"Incorrect symbols (A-z0-9).")),
61 array(
'status',
'in',
'range' => array(self::STATUS_NOACTIVE, self::STATUS_ACTIVE, self::STATUS_BANNED, self::STATUS_TEMP)),
62 array(
'superuser',
'in',
'range' => array(0, 1)),
63 array(
'create_at',
'default',
'value' => date(
'Y-m-d H:i:s'),
'setOnEmpty' =>
true,
'on' =>
'insert'),
64 array(
'lastvisit_at',
'default',
'value' =>
'0000-00-00 00:00:00',
'setOnEmpty' =>
true,
'on' =>
'insert'),
65 array(
'username, email, superuser, status',
'required'),
66 array(
'superuser, status',
'numerical',
'integerOnly' =>
true),
67 array(
'id, username, password, email, activkey, create_at, lastvisit_at, superuser, status',
'safe',
'on' =>
'search'),
68 ) : ((Yii::app()->user->id == $this->id) ? array(
69 array(
'username, email',
'required'),
70 array(
'username',
'length',
'max' => 20,
'min' => 3,
'message' =>
UserModule::t(
"Incorrect username (length between 3 and 20 characters).")),
71 array(
'email',
'email'),
72 array(
'username',
'unique',
'message' =>
UserModule::t(
"This user's name already exists.")),
73 array(
'username',
'match',
'pattern' =>
'/^[A-Za-z0-9_]+$/u',
'message' =>
UserModule::t(
"Incorrect symbols (A-z0-9).")),
74 array(
'email',
'unique',
'message' =>
UserModule::t(
"This user's email address already exists.")),
83 $relations = Yii::app()->getModule(
'user')->relations;
84 if (!isset($relations[
'profile'])) {
85 $relations[
'profile'] = array(self::HAS_ONE,
'Profile',
'user_id');
117 'condition' =>
'status='.self::STATUS_ACTIVE,
119 'notactive' => array(
120 'condition' =>
'status='.self::STATUS_NOACTIVE,
123 'condition' =>
'status='.self::STATUS_BANNED,
126 'condition' =>
'status='.self::STATUS_TEMP,
128 'superuser' => array(
129 'condition' =>
'superuser=1',
132 'select' =>
'id, username, password, email, activkey, create_at, lastvisit_at, superuser, status',
139 return CMap::mergeArray(Yii::app()->getModule(
'user')->
defaultScope, array(
141 'select' =>
'user.id, user.username, user.email, user.create_at, user.lastvisit_at, user.superuser, user.status, user.token, user.activkey',
148 'UserStatus' => array(
154 'AdminStatus' => array(
160 return isset($_items[$type][$code]) ? $_items[$type][$code] :
false;
162 return isset($_items[$type]) ? $_items[$type] :
false;
176 $criteria =
new CDbCriteria();
178 $criteria->compare(
'id', $this->
id);
179 $criteria->compare(
'username', $this->username,
true);
180 $criteria->compare(
'password', $this->password);
181 $criteria->compare(
'email', $this->email,
true);
182 $criteria->compare(
'activkey', $this->activkey);
183 $criteria->compare(
'create_at', $this->create_at);
184 $criteria->compare(
'lastvisit_at', $this->lastvisit_at);
185 $criteria->compare(
'superuser', $this->superuser);
186 $criteria->compare(
'status', $this->status);
188 return new CActiveDataProvider(get_class($this), array(
189 'criteria' => $criteria,
190 'pagination' => array(
191 'pageSize' => Yii::app()->getModule(
'user')->user_page_size,
198 return strtotime($this->create_at);
203 $this->create_at = date(
'Y-m-d H:i:s', $value);
208 return strtotime($this->lastvisit_at);
213 $this->lastvisit_at = date(
'Y-m-d H:i:s', $value);
224 'CBase64Behavior' => array(
225 'class' =>
'CBase64Behavior',
226 'serialAttributes' => array(
'token'),