Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This is the model class for table "user".
- *
- * The followings are the available columns in table 'user':
- * @property string $id
- * @property string $type
- * @property string $company_id
- * @property string $password
- * @property string $email
- * @property string $name
- * @property string $status
- */
- class User extends CActiveRecord
- {
- public $old_password;
- public $new_password;
- public $repeat_password;
- /**
- * Returns the static model of the specified AR class.
- * @param string $className active record class name.
- * @return User 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 '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('email, password, repeat_password, phone', 'required', 'on' => 'register'),
- array('email','unique'),
- array('email','email'),
- array('email','unique', 'on'=>'createPwd'),
- array('type, status', 'length', 'max'=>10),
- array('password', 'length', 'max'=>50),
- array('phone', 'length', 'max'=>50),
- array('email, auth_key, access_token, ', 'length', 'max'=>255),
- array('old_password, new_password, repeat_password', 'required', 'on' => 'changePwd'),
- array('old_password', 'findPasswords', 'on' => 'changePwd'),
- array('repeat_password', 'compare', 'compareAttribute'=>'new_password', 'on'=>'changePwd'),
- array('password', 'compare', 'compareAttribute'=>'repeat_password', 'on'=>'createPwd'),
- // The following rule is used by search().
- // Please remove those attributes that should not be searched.
- array('id, type, password, client_id, phone, email, auth_key, access_token, hash, 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(
- // 'company' => array(self::BELONGS_TO, 'Company', 'company_id'),
- // 'userdetail' => array(self::BELONGS_TO, 'UserDetail', 'user_id'),
- 'userdetail' => array(self::BELONGS_TO, 'UserDetail', 'user_id'),
- 'client' => array(self::BELONGS_TO, 'Client', 'client_id'),
- );
- }
- /**
- * @return array customized attribute labels (name=>label)
- */
- public function attributeLabels()
- {
- return array(
- 'id' => 'ID',
- 'type' => 'Type',
- 'client_id' => 'client_id',
- 'password' => 'Password',
- 'new_password' => 'New Password',
- 'old_password' => 'Old Password',
- 'email' => 'Email',
- 'phone' => 'Phone',
- 'auth_key' => 'Auth Key',
- 'access_token' => 'Auth Token',
- 'hash' => 'Hash',
- 'status' => 'Status',
- );
- }
- /**
- * 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,false);
- $criteria->compare('type',$this->type,false);
- $criteria->compare('client_id',$this->client_id,false);
- $criteria->compare('password',$this->password,false);
- $criteria->compare('email',$this->email,false);
- $criteria->compare('phone',$this->email,true);
- $criteria->compare('auth_key',$this->auth_key,false);
- $criteria->compare('access_token',$this->access_token,false);
- $criteria->compare('hash',$this->hash,false);
- $criteria->compare('status',$this->status,false);
- return new CActiveDataProvider($this, array(
- 'criteria'=>$criteria,
- ));
- }
- public function findPasswords($attribute, $params)
- {
- $user = User::model()->findByPk($this->id);
- if ($user->password != sha1($this->old_password)){
- $this->addError($attribute, 'Old password is incorrect.');
- }
- }
- public function beforeSave(){
- if($this->isNewRecord)
- {
- $this->hash = sha1($this->id . date('Y') . $this->email . date('m-d H:i:s'));
- }
- return parent::beforeSave();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment