Guest User

Untitled

a guest
Jul 4th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.31 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * This is the model class for table "members".
  5.  *
  6.  * The followings are the available columns in table 'members':
  7.  * @property integer $ID
  8.  * @property string $username
  9.  * @property integer $permissionLevel
  10.  * @property string $password
  11.  * @property string $email
  12.  * @property string $date
  13.  */
  14. class Members extends CActiveRecord
  15. {
  16.    /**
  17.     * Defining variables not present in the database
  18.     */
  19.    public $password_repeat;
  20.    public $verifyCode;
  21.  
  22.     /**
  23.      * Returns the static model of the specified AR class.
  24.      * @param string $className active record class name.
  25.      * @return Members the static model class
  26.      */
  27.     public static function model($className=__CLASS__)
  28.     {
  29.         return parent::model($className);
  30.     }
  31.  
  32.     /**
  33.      * @return string the associated database table name
  34.      */
  35.     public function tableName()
  36.     {
  37.         return 'members';
  38.     }
  39.  
  40.     /**
  41.      * @return array validation rules for model attributes.
  42.      */
  43.     public function rules()
  44.     {
  45.         // NOTE: you should only define rules for those attributes that
  46.         // will receive user inputs.
  47.         return array(
  48.             array('username, password', 'required'),
  49.          array('password_repeat, verifyCode', 'required', 'on'=>'register'),
  50.             //array('permissionLevel', 'numerical', 'integerOnly'=>true),
  51.          // email has to be a valid email address
  52.             array('email', 'email'),
  53.             // verifyCode needs to be entered correctly
  54.             array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements(), 'on'=>'register'),
  55.             // The following rule is used to compare the passwords
  56.          array('password', 'compare', 'on'=>'register'),        
  57.          // The following rule is used by search().
  58.             // Please remove those attributes that should not be searched.
  59.             array('ID, username, permissionLevel, email, date', 'safe', 'on'=>'search'),
  60.          array('password, password_repeat, verifyCode', 'safe'),
  61.         );
  62.     }
  63.  
  64.     /**
  65.      * @return array relational rules.
  66.      */
  67.     public function relations()
  68.     {
  69.         // NOTE: you may need to adjust the relation name and the related
  70.         // class name for the relations automatically generated below.
  71.         return array(
  72.         );
  73.     }
  74.  
  75.     /**
  76.      * @return array customized attribute labels (name=>label)
  77.      */
  78.     public function attributeLabels()
  79.     {
  80.         return array(
  81.             'ID' => 'ID',
  82.             'username' => 'Username',
  83.             'permissionLevel' => 'Permission Level',
  84.             'password' => 'Password',
  85.             'email' => 'Email',
  86.             'date' => 'Date',
  87.          'verifyCode' => 'Verification Code',
  88.         );
  89.     }
  90.  
  91.     /**
  92.      * Retrieves a list of models based on the current search/filter conditions.
  93.      * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  94.      */
  95.     public function search()
  96.     {
  97.         // Warning: Please modify the following code to remove attributes that
  98.         // should not be searched.
  99.  
  100.         $criteria=new CDbCriteria;
  101.  
  102.         $criteria->compare('ID',$this->ID);
  103.         $criteria->compare('username',$this->username,true);
  104.         $criteria->compare('permissionLevel',$this->permissionLevel);
  105.         $criteria->compare('password',$this->password,true);
  106.         $criteria->compare('email',$this->email,true);
  107.         $criteria->compare('date',$this->date,true);
  108.  
  109.         return new CActiveDataProvider($this, array(
  110.             'criteria'=>$criteria,
  111.         ));
  112.     }
  113.  
  114.    /**
  115.     * Checks if the username already exists in the database
  116.     * $return true if unique, false if not.
  117.     */
  118.    public function isUserUnique()
  119.    {
  120.       if ($this::model()->findByAttributes(array('username'=>$this->username)))
  121.          return false;
  122.       else
  123.          return true;
  124.    }
  125.    
  126.    /**
  127.     * Creates an ccount based on user input
  128.     * @return false upon failure, return true if successful.
  129.     */
  130.     public function createAccount()
  131.     {
  132.       if ($this->isUserUnique())
  133.       {
  134.          $member = new Members('register');
  135.          $member->username=$this->username;
  136.          $member->permissionLevel=2;
  137.          $member->password=crypt($this->password, "comaan11");
  138.          $member->email=$this->email;
  139.          $member->date=Date("Y-m-d H:i:s");
  140.          
  141.          $member->save();
  142.          print_r($member->getErrors());
  143.       }
  144.       else
  145.       {
  146.          $this->addError('username','A user with that name already exists.');
  147.          return false;
  148.       }
  149.          
  150.          
  151.       //for debugging
  152.       //print_r($member->getErrors());
  153.     }
  154. }
Add Comment
Please, Sign In to add comment