public function up()
 {
     $this->createTable('user', array('id' => 'pk', 'fname' => 'string', 'lname' => 'string', 'username' => 'string', 'password' => 'string', 'pw_reset_token' => 'string', 'email' => 'string', 'role' => 'string', 'is_deleted' => 'int', 'create_date' => 'datetime'), 'ENGINE=InnoDB');
     $this->createTable('cookie', array('id' => 'pk', 'username' => 'string', 'token' => 'string', 'create_date' => 'datetime'), 'ENGINE=InnoDB');
     $this->createTable('post', array('id' => 'pk', 'title' => 'string', 'content' => 'string', 'user_id' => 'int', 'is_deleted' => 'int', 'create_date' => 'datetime'), 'ENGINE=InnoDB');
     $this->createTable('comment', array('id' => 'pk', 'post_id' => 'int', 'content' => 'string', 'user_id' => 'int', 'is_deleted' => 'int', 'create_date' => 'datetime'), 'ENGINE=InnoDB');
     $enc = new bCrypt();
     $password = $enc->hash('1q2w3e');
     $this->insert('user', array('fname' => 'Super', 'lname' => 'User', 'username' => 'super', 'password' => $password, 'pw_reset_token' => '', 'email' => '*****@*****.**', 'role' => 'admin', 'is_deleted' => 0, 'create_date' => new CDbExpression('NOW()')));
     $userId = Yii::app()->db->getLastInsertId();
     $this->insert('post', array('title' => 'Lorem Ipsum', 'content' => 'Sed posuere consectetur est at lobortis. Donec id elit non mi porta gravida at eget metus. Donec ullamcorper nulla non metus auctor fringilla. Nullam id dolor id nibh ultricies vehicula ut id elit. Maecenas faucibus mollis interdum.', 'user_id' => $userId, 'is_deleted' => 0, 'create_date' => new CDbExpression('NOW()')));
     $postId = Yii::app()->db->getLastInsertId();
     $this->insert('comment', array('content' => 'Sed posuere consectetur est at lobortis. Donec id elit non mi porta gravida at eget metus. Donec ullamcorper nulla non metus auctor fringilla. Nullam id dolor id nibh ultricies vehicula ut id elit. Maecenas faucibus mollis interdum.', 'post_id' => $postId, 'user_id' => $userId, 'is_deleted' => 0, 'create_date' => new CDbExpression('NOW()')));
 }
Пример #2
0
 public function authenticate()
 {
     $user = $this->_user = User::model()->findByAttributes(array('username' => $this->username));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } elseif (!bCrypt::verify($this->password, $user->password)) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
     } elseif ($user->is_deleted) {
         $this->errorCode = self::ERROR_USER_IS_DELETED;
     } else {
         $this->_id = $user->id;
         $this->errorCode = self::ERROR_NONE;
     }
     return !$this->errorCode;
 }
Пример #3
0
 public function actionUpdatePass()
 {
     if (!Yii::app()->request->isAjaxRequest) {
         return;
     }
     if (isset($_POST) && !empty($_POST)) {
         $passold = $_POST['passwordold'];
         $passnew = $_POST['password'];
         $model = $this->loadModel(Yii::app()->user->getId(), 'Users');
         $msg = "Password lama salah. Untuk mengganti password, password lama harus benar.";
         $status = false;
         if (bCrypt::verify($passold, $model->password)) {
             //                $crypt = new bCrypt();
             //                $pass = $crypt->hash($passnew);
             $model->password = $passnew;
             if ($model->save()) {
                 $status = true;
                 $msg = "Password berhasil diganti.";
             } else {
                 $status = false;
                 $msg = "Password gagal diganti";
             }
         }
         echo CJSON::encode(array('success' => $status, 'msg' => $msg));
         Yii::app()->end();
     }
 }
Пример #4
0
 public function encrypt($value)
 {
     $enc = new bCrypt();
     return $enc->hash($value);
 }