Created
January 21, 2013 21:00
-
-
Save DrMabuse23/4589334 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is the model class for table "wr_user". | |
* | |
* The followings are the available columns in table 'wr_user': | |
* @property integer $id | |
* @property integer $group_id | |
* @property integer $password_length | |
* @property string $username | |
* @property string $password_hash | |
* @property string $email | |
* @property string $create | |
* @property string $update | |
* @property integer $status | |
* @property UserStatus $_statusName | |
* @property WR_UserGroup $_groupName | |
*/ | |
class WR_User extends CActiveRecord | |
{ | |
public $verifyPassword; | |
public $password; | |
public $verifyCode; | |
public $_statusName; | |
public $_groupName; | |
/** | |
* Returns the static model of the specified AR class. | |
* @param string $className active record class name. | |
* @return YcmsUser the static model class | |
*/ | |
public static function model($className=__CLASS__) | |
{ | |
return parent::model($className); | |
} | |
/** | |
* @return string the associated database table name | |
*/ | |
public function tableName() | |
{ | |
return 'wr_user'; | |
} | |
/** | |
* @return array validation rules for model attributes. | |
*/ | |
public function rules() | |
{ | |
// NOTE: you should only define rules for those attributes that | |
// will receive user inputs. | |
return array( | |
array('username, password, email', 'required'), | |
array('status,group_id,password_length', 'numerical', 'integerOnly'=>true), | |
array('username, password, email', 'length', 'max'=>128), | |
array('password_hash', 'length', 'max'=>60), | |
array('username', 'unique', 'message' => "This user's name already exists."), | |
array('email', 'unique', 'message' => Yii::t('y','This email already exists.')), | |
array('email','email'), | |
array('username', 'match', 'pattern' => '/^[A-Za-z0-9_]+$/u','message' => "Incorrect symbols (A-z0-9)."), | |
array('password', 'length', 'max'=>128, 'min' => 6,'message' => "Incorrect password (minimal length 4 symbols)."), | |
array('verifyPassword', 'compare', 'compareAttribute'=>'password', 'message' => "Retype Password is incorrect."), | |
array('verifyPassword','required','on' => 'create'), | |
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()), | |
// The following rule is used by search(). | |
// Please remove those attributes that should not be searched. | |
array('id, username, password, email, create, update, status', 'safe', 'on'=>'search'), | |
); | |
} | |
/** | |
* @return array relational rules. | |
*/ | |
public function relations() | |
{ | |
// NOTE: you may need to adjust the relation name and the related | |
// class name for the relations automatically generated below. | |
return array( | |
'profile' => array(self::HAS_ONE, 'WR_UserProfiles', 'user_id'), | |
'usergroup' => array(self::BELONGS_TO, 'WR_UserGroup', 'group_id'), | |
'userstatus' => array(self::BELONGS_TO, 'UserStatus', 'status'), | |
); | |
} | |
/** | |
* @return array customized attribute labels (name=>label) | |
*/ | |
public function attributeLabels() | |
{ | |
return array( | |
'id' => 'ID', | |
'username' => 'Username', | |
'password' => 'Password', | |
'email' => 'Email', | |
'create' => 'Create', | |
'update' => 'Update', | |
'status' => 'Status', | |
'group_id' => 'Gruppe', | |
'verifyPassword'=>"Retype Password", | |
); | |
} | |
/** | |
* Retrieves a list of models based on the current search/filter conditions. | |
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. | |
*/ | |
public function search() | |
{ | |
// Warning: Please modify the following code to remove attributes that | |
// should not be searched. | |
$criteria=new CDbCriteria; | |
$criteria->compare('id',$this->id); | |
$criteria->compare('username',$this->username,true); | |
$criteria->compare('password_hash',$this->password_hash,true); | |
$criteria->compare('password_length',$this->password_length,true); | |
$criteria->compare('email',$this->email,true); | |
$criteria->compare('create',$this->create,true); | |
$criteria->compare('update',$this->update,true); | |
$criteria->compare('status',$this->status); | |
$criteria->compare('group_id',$this->group_id); | |
return new CActiveDataProvider($this, array( | |
'criteria'=>$criteria, | |
)); | |
} | |
protected function beforeSave(){ | |
if(parent::beforeSave()){ | |
if($this->isNewRecord){ | |
$this->create = $this->update = date('Y-m-d H:i:s'); | |
$this->password_hash = crypt($this->password,Randomness::blowfishSalt()); | |
}else{ | |
$this->update = date('Y-m-d H:i:s'); | |
} | |
$this->password_length = strlen($this->password); | |
} | |
return parent::beforeSave(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment