Guest User

Untitled

a guest
Oct 23rd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.74 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * This is the model class for table "user".
  5.  *
  6.  * The followings are the available columns in table 'user':
  7.  * @property integer $id
  8.  * @property string $username
  9.  * @property string $password
  10.  * @property string $salt
  11.  * @property string $email
  12.  * @property string $profile
  13.  */
  14. class User extends CActiveRecord
  15. {
  16.     /**
  17.      * Returns the static model of the specified AR class.
  18.      * @return User the static model class
  19.      */
  20.     public static function model($className=__CLASS__)
  21.     {
  22.         return parent::model($className);
  23.     }
  24.  
  25.     /**
  26.      * @return string the associated database table name
  27.      */
  28.     public function tableName()
  29.     {
  30.         return 'user';
  31.     }
  32.  
  33.     /**
  34.      * @return array validation rules for model attributes.
  35.      */
  36.     public function rules()
  37.     {
  38.         // NOTE: you should only define rules for those attributes that
  39.         // will receive user inputs.
  40.         return array(
  41.             array('username, password, salt, email, profile', 'required'),
  42.             array('username, password, salt, email, profile', 'length', 'max'=>255),
  43.             // The following rule is used by search().
  44.             // Please remove those attributes that should not be searched.
  45.             array('id, username, password, salt, email, profile', 'safe', 'on'=>'search'),
  46.         );
  47.     }
  48.  
  49.     /**
  50.      * @return array relational rules.
  51.      */
  52.     public function relations()
  53.     {
  54.         // NOTE: you may need to adjust the relation name and the related
  55.         // class name for the relations automatically generated below.
  56.         return array(
  57.         );
  58.     }
  59.  
  60.     /**
  61.      * @return array customized attribute labels (name=>label)
  62.      */
  63.     public function attributeLabels()
  64.     {
  65.         return array(
  66.             'id' => 'ID',
  67.             'username' => 'Username',
  68.             'password' => 'Password',
  69.             'salt' => 'Salt',
  70.             'email' => 'Email',
  71.             'profile' => 'Profile',
  72.         );
  73.     }
  74.  
  75.     /**
  76.      * Retrieves a list of models based on the current search/filter conditions.
  77.      * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  78.      */
  79.     public function search()
  80.     {
  81.         // Warning: Please modify the following code to remove attributes that
  82.         // should not be searched.
  83.  
  84.         $criteria=new CDbCriteria;
  85.  
  86.         $criteria->compare('id',$this->id);
  87.         $criteria->compare('username',$this->username,true);
  88.         $criteria->compare('password',$this->password,true);
  89.         $criteria->compare('salt',$this->salt,true);
  90.         $criteria->compare('email',$this->email,true);
  91.         $criteria->compare('profile',$this->profile,true);
  92.  
  93.         return new CActiveDataProvider($this, array(
  94.             'criteria'=>$criteria,
  95.         ));
  96.     }
  97.    
  98.       public function validatePassword($password)
  99.     {
  100.         return $this->hashPassword($password,$this->salt)===$this->password;
  101.     }
  102.  
  103.     public function hashPassword($password,$salt)
  104.     {
  105.         return md5($salt.$password);
  106.     }
  107. }
Add Comment
Please, Sign In to add comment