Beispiel #1
0
 /**
  * Hash passwords if required
  * @return boolean 
  */
 public function beforeSave()
 {
     if ($this->scenario == 'create' || $this->scenario == 'admin_change_password') {
         $this->password = UserIdentity::doHash($this->password);
     } else {
         if ($this->scenario == 'new_password') {
             $this->password = UserIdentity::doHash($this->password_new);
         }
     }
     $dataDir = Yii::getPathOfAlias('application.data');
     foreach ($this->_fileFields as $field) {
         $uploadFile = CUploadedFile::getInstance($this, $field);
         if (!$uploadFile) {
             continue;
         }
         $this->{$field} = $uploadFile;
         $dirPath = $dataDir . '/' . strtolower(__CLASS__);
         if (!file_exists($dirPath)) {
             mkdir($dirPath, 0777, true);
         }
         if (!$this->{$field} || !$this->{$field}->saveAs($dirPath . '/' . $field . '_' . $this->id)) {
             Yii::app()->user->setFlash('danger', 'problem saving image for field: ' . $field);
         }
     }
     return parent::beforeSave();
 }