Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This is the model class for table "members".
- *
- * The followings are the available columns in table 'members':
- * @property integer $ID
- * @property string $username
- * @property integer $permissionLevel
- * @property string $password
- * @property string $email
- * @property string $date
- */
- class Members extends CActiveRecord
- {
- /**
- * Defining variables not present in the database
- */
- public $password_repeat;
- //public $verifyCode;
- /**
- * Returns the static model of the specified AR class.
- * @param string $className active record class name.
- * @return Members 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 'members';
- }
- /**
- * @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', 'required'),
- array('password', 'required'),
- // array('verifyCode', 'required'),
- //array('password_repeat', 'required'),
- // email has to be a valid email address
- array('email', 'email'),
- // verifyCode needs to be entered correctly
- //array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
- // The following rule is used to compare the passwords
- array('password', 'compare', 'compareAttribute'=>'password_repeat', 'on'=>'register'),
- // The following rule is used by search().
- // Please remove those attributes that should not be searched.
- //array('ID, username, permissionLevel, email, date', 'safe', 'on'=>'search'),
- array('password', 'safe'),
- array('password_repeat', 'safe'),
- // array('verifyCode', 'safe'),
- );
- }
- /**
- * @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' => 'Username',
- 'permissionLevel' => 'Permission Level',
- 'password' => 'Password',
- 'email' => 'Email',
- 'date' => 'Date',
- // 'verifyCode' => 'Verification Code',
- );
- }
- /**
- * 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('permissionLevel',$this->permissionLevel);
- $criteria->compare('password',$this->password,true);
- $criteria->compare('email',$this->email,true);
- $criteria->compare('date',$this->date,true);
- return new CActiveDataProvider($this, array(
- 'criteria'=>$criteria,
- ));
- }
- /**
- * Checks if the username already exists in the database
- * $return true if unique, false if not.
- */
- public function isUserUnique()
- {
- if ($this::model()->findByAttributes(array('username'=>$this->username)))
- return false;
- else
- return true;
- }
- /**
- * Creates an ccount based on user input
- * @return false upon failure, return true if successful.
- */
- public function createAccount()
- {
- if ($this->isUserUnique())
- {
- $member = new Members('register');
- $member->username=$this->username;
- $member->permissionLevel=2;
- $member->password=crypt($this->password, "comaan11");
- $member->email=$this->email;
- $member->date=Date("Y-m-d H:i:s");
- $member->save();
- print_r($member->getErrors());
- }
- else
- {
- $this->addError('username','A user with that name already exists.');
- return false;
- }
- //for debugging
- //print_r($member->getErrors());
- }
- }
Add Comment
Please, Sign In to add comment