Ejemplo n.º 1
0
 protected function processUpload($media, ModelInterface $model)
 {
     $request = $model->getDI()->getRequest();
     if (true == $request->hasFiles(true)) {
         foreach ($request->getUploadedFiles() as $file) {
             $key = $file->getKey();
             $type = $file->getType();
             // Check extension allowed
             if (!in_array($type, $this->allowedFormats)) {
                 throw new \Exception(sprintf('File %s has invalid extension. Allowable only: %s', $file->getName(), str_replace('image/', ' ', implode(',', $this->allowedFormats))));
             }
             // Check allowed min size
             $this->checkMinSize($file, $this->allowMinSize);
             // Check allowed max size
             $this->checkMaxsize($file, $this->allowMaxSize);
             // Create full path image
             $fullPath = rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath;
             // Check upload directory
             if (is_writable($fullPath) === false) {
                 throw new \Exception(sprintf('The specified directory %s is not writable', $fullPath));
             }
             if ($key != $this->imageField) {
                 continue;
             }
             $uniqueFileName = md5($file->getName()) . '-' . uniqid() . '.' . strtolower($file->getExtension());
             $fullPath .= $uniqueFileName;
             if ($file->moveTo($fullPath)) {
                 $model->writeAttribute($this->imageField, $this->datePath . $uniqueFileName);
                 // Resize images big
                 $myImageResize = new ImageResize(rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath, $uniqueFileName, rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath, $uniqueFileName, $media->imageMaxWidth, $media->imageMaxHeight, '', $media->imageQuality);
                 $myImageResize->output();
                 unset($myImageResize);
                 // Resize images medium
                 $nameMediumPart = substr($uniqueFileName, 0, strrpos($uniqueFileName, '.'));
                 $nameMedium = $nameMediumPart . '-medium.' . strtolower($file->getExtension());
                 $myImageResize = new ImageResize(rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath, $uniqueFileName, rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath, $nameMedium, $media->imageMediumWidth, $media->imageMediumHeight, '', $media->imageQuality);
                 $myImageResize->output();
                 unset($myImageResize);
                 // Resize images small
                 $nameThumbPart = substr($uniqueFileName, 0, strrpos($uniqueFileName, '.'));
                 $nameThumb = $nameThumbPart . '-small.' . strtolower($file->getExtension());
                 $myImageResize = new ImageResize(rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath, $uniqueFileName, rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath, $nameThumb, $media->imageThumbWidth, $media->imageThumbHeight, '', $media->imageQuality);
                 $myImageResize->output();
                 unset($myImageResize);
                 // Delete old file
                 $this->processDelete();
             }
         }
     }
     return $this;
 }
Ejemplo n.º 2
0
 protected function processUpload(ModelInterface $model)
 {
     /* @var $request \Phalcon\Http\Request */
     $request = $model->getDI()->getRequest();
     if ($request->hasFiles(true)) {
         foreach ($request->getUploadedFiles() as $file) {
             if ($file->getKey() != $this->imageField || !in_array($file->getType(), $this->allowedFormats)) {
                 continue;
             }
             $uniqueFileName = time() . '-' . uniqid() . '.' . strtolower($file->getExtension());
             if (!file_exists($this->uploadPath)) {
                 mkdir($this->uploadPath, 0755, true);
             }
             $file_name = rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $uniqueFileName;
             if (!$file->moveTo($file_name)) {
                 if (!(file_exists($file->getTempName()) && copy($file->getTempName(), $file_name))) {
                     return $this;
                 }
             }
             $model->writeAttribute($this->imageField, $uniqueFileName);
             // Delete old file
             $this->processDelete();
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @param \Phalcon\Mvc\ModelInterface $user
  * @param string                      $newPassword
  * 
  * @return boolean
  */
 public function changePassword(\Phalcon\Mvc\ModelInterface $user, $newPassword)
 {
     $eventsManager = $this->getEventsManager();
     if ($eventsManager instanceof \Phalcon\Events\ManagerInterface) {
         if ($eventsManager->fire("auth:beforeChangePassword", $this) === false) {
             return false;
         }
     }
     $user->writeAttribute($this->passwordField, $this->getDI()->getShared("security")->hash($newPassword));
     $success = $user->update();
     if ($eventsManager instanceof \Phalcon\Events\ManagerInterface) {
         $eventsManager->fire("auth:afterChangePassword", $this);
     }
     return $success;
 }