示例#1
0
 /**
  * Returns the static model of the specified AR class.
  * @param string $className active record class name.
  * @return Configuration the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
示例#2
0
 /**
  * BeforeDelete
  * Clears caches for rebuilding
  * @see CActiveRecord::beforeDelete
  */
 public function beforeDelete()
 {
     Yii::app()->cache->delete('CiiMS::Content::list');
     Yii::app()->cache->delete('CiiMS::Routes');
     Yii::app()->cache->delete('content-' . $this->id . '-layout');
     Yii::app()->cache->delete('content-' . $this->id . '-view');
     return parent::beforeDelete();
 }
示例#3
0
 /**
  * BeforeDelete
  * Clears caches for rebuilding
  * @see CActiveRecord::beforeDelete
  */
 public function beforeDelete()
 {
     Yii::app()->cache->delete('content');
     Yii::app()->cache->delete('content-listing');
     Yii::app()->cache->delete('WFF-content-url-rules');
     Yii::app()->cache->delete('content-' . $this->id . '-layout');
     Yii::app()->cache->delete('content-' . $this->id . '-view');
     return parent::beforeDelete();
 }
示例#4
0
文件: Users.php 项目: bartuspan/CiiMS
 /**
  * Sets some default values for the user record.
  * TODO: This should have been moved to CiiModel
  * @see CActiveRecord::beforeValidate()
  **/
 public function beforeValidate()
 {
     // If the password is nulled, or unchanged
     if ($this->password == NULL || $this->password == Cii::get($this->_oldAttributes, 'password', false)) {
         if (!$this->isNewRecord) {
             $this->password = $this->_oldAttributes['password'];
         }
     } else {
         $this->password = password_hash($this->password, PASSWORD_BCRYPT, array('cost' => Cii::getBcryptCost()));
         if (!$this->isNewRecord) {
             $emailSettings = new EmailSettings();
             $emailSettings->send($this, Yii::t('ciims.models.Users', 'CiiMS Password Change Notification'), 'webroot.themes.' . Cii::getConfig('theme', 'default') . '.views.email.passwordchange', array('user' => $this));
         }
     }
     return parent::beforeValidate();
 }
示例#5
0
 /**
  * Automatically corrects parent tree issues that arise when a parent category node
  * is deleted.
  * @return boolean
  */
 public function beforeDelete()
 {
     // Prevents the main "uncategorized category from being deleted"
     if ($this->id == 1) {
         Yii::app()->user->setFlash('error', Yii::t('ciims.models.Categories', 'This category cannot be deleted'));
         return false;
     }
     Yii::app()->cache->delete('CiiMS::Content::list');
     Yii::app()->cache->delete('CiiMS::Routes');
     Yii::app()->cache->delete('categories-pid');
     $parent = $this->parent_id;
     $id = $this->id;
     // Reassign all posts to the parent category
     Yii::app()->db->createCommand('UPDATE content SET category_id = :parent_id WHERE category_id = :id')->bindParam(':parent_id', $parent)->bindParam(':id', $id)->execute();
     // Reassign all child categories to the parent category
     $data = $this->findAllByAttributes(array('parent_id' => $id));
     foreach ($data as $row) {
         $id = $row->id;
         Yii::app()->db->createCommand('UPDATE categories SET parent_id = :parent_id WHERE id = :id')->bindParam(':parent_id', $parent)->bindParam(':id', $id)->execute();
     }
     return parent::beforeDelete();
 }
示例#6
0
 /**
  * After Delete method, decriments the comment count of the parent content
  * @return  bool
  */
 public function afterDelete()
 {
     $content = Content::model()->findByPk($this->content_id);
     if ($content === NULL) {
         return true;
     }
     $content->comment_count = $content->comment_count = max($content->comment_count - 1, 0);
     $content->save();
     return parent::afterDelete();
 }
示例#7
0
 /**
  * Bind behaviors for changing the user's email, and allow them to make the appropriate changes on their end.
  * The intention behind this, is that the user has to first, verify that they requested the change, and second
  * verify that they own both email addresses.
  *
  * The intention behind this is to protect the user from changes to their account, either by an administrator or a malicious user.
  * This doesn't protect from database attacks, it only protects from malicious attacks from within CiiMS.
  * 
  * @return parent::afterSave();
  */
 public function beforeSave()
 {
     // If the user's email address is about to change
     if (isset($this->_oldAttributes['email']) && $this->_oldAttributes['email'] != $this->email) {
         // Store the new email address
         $newEmail = $this->email;
         // Reset the email addres and block the change internally
         $this->email = $this->_oldAttributes['email'];
         // Save the NEW email address in the database as a metadata record
         $meta = UserMetadata::model()->findByAttributes(array('user_id' => $this->id, 'key' => 'newEmailAddress'));
         if ($meta === NULL) {
             $meta = new UserMetadata();
         }
         $meta->user_id = $this->id;
         $meta->key = 'newEmailAddress';
         $meta->value = $newEmail;
         $meta->save();
         $meta = UserMetadata::model()->findByAttributes(array('user_id' => $this->id, 'key' => 'newEmailAddressChangeKey'));
         if ($meta === NULL) {
             $meta = new UserMetadata();
         }
         $meta->user_id = $this->id;
         $meta->key = 'newEmailAddressChangeKey';
         $key = $meta->value = md5(md5($newEmail . time()) . Yii::app()->params['encryptionKey']);
         $meta->save();
         // Delete all API tokens associated to this account
         $response = Yii::app()->db->createCommand('DELETE FROM user_metadata WHERE `key` LIKE "api_key%" AND user_id = :id')->bindParam(':id', $this->id)->execute();
         // Fire off an email to the OLD email address asking them VERIFY the change
         $response = Yii::app()->controller->sendEmail($this, Yii::t('Dashboard.email', 'CiiMS Email Change Notification'), 'application.modules.dashboard.views.email.email-change', array('key' => $key));
     }
     return parent::beforeSave();
 }
示例#8
0
 /**
  * After a new comment is posted, set the reputation += 10
  * @see parent::afterSave();
  */
 public function afterSave()
 {
     if ($this->_isNewRecord) {
         $user = Users::model()->findByPk($this->author_id);
         $user->setReputation(10);
     }
     return parent::afterSave();
 }