class User extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return User the static model class
*/
public $password2;
public $verifyCode;
public $rememberMe;
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(array('username','password','password2'), 'match', 'pattern' => '/^[A-Za-z0-9]+$/u', 'message' => Yii::t('default', 'Ékezetes betű nem engedélyezett!')),
array('username','length','max'=>32),
// convert username to lower case
array('username', 'filter', 'filter'=>'strtolower'),
array('username','length','max'=>10, 'min'=>3),
array('password','length','max'=>64, 'min'=>6),
array('password2','length','max'=>64, 'min'=>6),
// compare password to repeated password
array('password2', 'compare', 'compareAttribute'=>'password'),
array('email','length','max'=>256),
// make sure email is a valid email
array('email','email'),
// make sure username and email are unique
array('username, email', 'unique'),
array('question','length','max'=>256),
// convert question to lower case
array('question', 'filter', 'filter'=>'strtolower'),
array('answer','length','max'=>128),
// convert answer to lower case
array('answer', 'filter', 'filter'=>'strtolower'),
array('username, password, password2, email, question, answer, verifyCode', 'required'),
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')),
);
}
/**
* @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(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'username' => 'Felhasználónév',
'password' => 'Jelszó',
'password2' => 'Jelszó ismét',
'email' => 'Email',
'question' => 'Biztonsági kérdés',
'answer' => 'Válasz',
'verifyCode' => 'Megerősítő kód',
);
}
/**
* 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',$this->password,true);
//$criteria->compare('email',$this->email,true);
//$criteria->compare('question',$this->question,true);
//$criteria->compare('answer',$this->answer,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public function beforeSave()
{
// Check if question has a ? at the end
$last = $this->question[strlen($this->question)-1];
if($last !== "?")
{
$this->question .= '?';
}
$pass = md5(md5($this->password).Yii::app()->params["salt"]);
$this->password = $pass;
return true;
}
}