public function getConfirmEmail($token)
 {
     try {
         $email = Crypt::decrypt($token);
         $userQuery = DB::table('users')->where('email', $email);
         $user = $userQuery->first();
         if (isset($user)) {
             switch (\Config::get('app.registerMode')) {
                 case 'auto':
                     $userQuery->update(['active' => 1]);
                     Util::flash(trans('auth.confirmed'), '', Util::ALERT_SUCCESS);
                     // Foi enviado um email.
                     return view('auth/login');
                     break;
                 case 'confirm':
                     $userQuery->update(['pending' => 1]);
                     return view('info', ['title' => trans('auth.pending-approval_confirmation'), 'text' => trans('auth.pending-approval')]);
                     break;
             }
         } else {
             Util::flash(trans('auth.user'), '', Util::ALERT_ERROR);
         }
         // Não existe o email.
     } catch (Exception $e) {
         Util::flash(trans('auth.token'), '', Util::ALERT_ERROR);
         // Token inválido.
     }
     return Redirect::action(self::HOME_ACTION);
 }
 /**
  * Stream fallback delegator.
  *
  * @param string   $path
  * @param resource $resource
  * @param Config   $config
  * @param string   $fallback
  *
  * @return mixed fallback result
  */
 protected function stream($path, $resource, Config $config, $fallback)
 {
     Util::rewindStream($resource);
     $contents = stream_get_contents($resource);
     $fallbackCall = [$this, $fallback];
     return call_user_func($fallbackCall, $path, $contents, $config);
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function getSize($path)
 {
     if (!($decrypted = $this->read($path))) {
         return false;
     }
     $size = Util::contentSize($decrypted['contents']);
     return compact('path', 'size');
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function update($path, $contents, Config $config)
 {
     $location = $this->applyPathPrefix($path);
     $mimetype = Util::guessMimeType($path, $contents);
     if (($size = file_put_contents($location, $contents)) === false) {
         return false;
     }
     return compact('path', 'size', 'contents', 'mimetype');
 }
 /**
  * @param string $path child path to find in
  *
  * @return Finder
  */
 public function getFinder($path = '')
 {
     $path = Util::normalizePath($path);
     $adapter = $this->getAdapter();
     if (!$adapter instanceof FindableAdapterInterface) {
         throw new NotSupportedException("Adapter doesn't support getFinder action. Adapter in use is: " . get_class($adapter));
     }
     return $adapter->getFinder($path);
 }
Exemplo n.º 6
0
 /**
  * Emulates touch().
  *
  * @param string $path
  *
  * @return bool True on success, false on failure.
  */
 public function handle($path)
 {
     $path = Util::normalizePath($path);
     $adapter = $this->filesystem->getAdapter();
     if ($adapter->has($path)) {
         return true;
     }
     return (bool) $adapter->write($path, '', $this->defaultConfig());
 }
Exemplo n.º 7
0
 /**
  * Write a file
  *
  * @param $path
  * @param $contents
  * @param null $config
  * @return array|bool
  */
 public function write($path, $contents, $config = null)
 {
     $type = 'file';
     $config = Util::ensureConfig($config);
     $result = compact('contents', 'type', 'size', 'path');
     if ($visibility = $config->get('visibility')) {
         $result['visibility'] = $visibility;
     }
     return $result;
 }
Exemplo n.º 8
0
 public function rename($path, $newpath)
 {
     $location = $this->applyPathPrefix($path);
     $destination = $this->applyPathPrefix($newpath);
     $parentDirectory = $this->applyPathPrefix(Util::dirname($newpath));
     if (!$this->ensureDirectory($parentDirectory)) {
         return false;
     }
     return rename($location, $destination);
 }
Exemplo n.º 9
0
 /**
  * Creates a directory.
  *
  * @param string $dirname
  * @param int    $mode
  * @param int    $options
  *
  * @return bool True on success, false on failure.
  */
 public function handle($dirname, $mode, $options)
 {
     $dirname = Util::normalizePath($dirname);
     $adapter = $this->filesystem->getAdapter();
     // If recursive, or a single level directory, just create it.
     if ($options & STREAM_MKDIR_RECURSIVE || strpos($dirname, '/') === false) {
         return (bool) $adapter->createDir($dirname, $this->defaultConfig());
     }
     if (!$adapter->has(dirname($dirname))) {
         throw new FileNotFoundException($dirname);
     }
     return (bool) $adapter->createDir($dirname, $this->defaultConfig());
 }
 /**
  * Checks that a rename is valid.
  *
  * @param string $source
  * @param string $dest
  *
  * @return bool
  */
 protected function isValidRename($source, $dest)
 {
     $adapter = $this->filesystem->getAdapter();
     if (!$adapter->has($source)) {
         throw new FileNotFoundException($source);
     }
     $subdir = Util::dirname($dest);
     if (strlen($subdir) && !$adapter->has($subdir)) {
         throw new FileNotFoundException($source);
     }
     if (!$adapter->has($dest)) {
         return true;
     }
     return $this->compareTypes($source, $dest);
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function storeContents($directory, array $contents, $recursive)
 {
     if ($recursive) {
         return $contents;
     }
     foreach ($contents as $index => $object) {
         $pathinfo = Util::pathinfo($object['path']);
         $object = array_merge($pathinfo, $object);
         if (!$recursive && $object['dirname'] !== $directory) {
             unset($contents[$index]);
             continue;
         }
         $contents[$index] = $object;
     }
     return $contents;
 }
Exemplo n.º 12
0
 /**
  * Delete a directory.
  *
  * @param string $dirname path to directory
  * @param int    $options
  *
  * @return bool
  */
 public function handle($dirname, $options)
 {
     $dirname = Util::normalizePath($dirname);
     if ($dirname === '') {
         throw new RootViolationException('Root directories can not be deleted.');
     }
     $adapter = $this->filesystem->getAdapter();
     if ($options & STREAM_MKDIR_RECURSIVE) {
         // I don't know how this gets triggered.
         return (bool) $adapter->deleteDir($dirname);
     }
     $contents = $this->filesystem->listContents($dirname);
     if (!empty($contents)) {
         throw new DirectoryNotEmptyException();
     }
     return (bool) $adapter->deleteDir($dirname);
 }
Exemplo n.º 13
0
 /**
  * Use flysystem to save the file in the desired location.
  *
  * @param \Onema\ClassyFile\Event\GetClassEvent $event
  */
 public function onGetClassGenerateFile(GetClassEvent $event)
 {
     $statement = $event->getStatements();
     $fileLocation = $event->getFileLocation();
     $code = $event->getCode();
     $name = $statement->name;
     if (!$this->filesystem->has($fileLocation)) {
         // dir doesn't exist, make it
         $this->filesystem->createDir($fileLocation);
     }
     $location = sprintf('%s/%s.php', $fileLocation, $name);
     $this->filesystem->put($location, $code);
     $adapter = $this->filesystem->getAdapter();
     if ($adapter instanceof AbstractAdapter) {
         $prefix = $adapter->getPathPrefix();
         $location = Util::normalizePath($location);
         $event->setFileLocation(sprintf('%s%s', $prefix, $location));
     }
 }
 /**
  * Write a new file.
  *
  * @param string $path
  * @param string $contents
  * @param Config $config Config object
  * @return array|false false on failure file meta data on success
  */
 public function write($path, $contents, Config $config = null)
 {
     $tmpFile = tempnam(sys_get_temp_dir(), 'arconnect-static');
     file_put_contents($tmpFile, $contents);
     $file = new \CURLFile($tmpFile, Util::guessMimeType($path, $tmpFile), basename($tmpFile));
     $data = ['slug' => $path, 'file' => $file];
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->apiUrl . '/' . $this->application);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_exec($ch);
     $fileInfo = curl_getinfo($ch);
     curl_close($ch);
     unlink($tmpFile);
     if ($fileInfo['http_code'] >= 200 && $fileInfo['http_code'] < 400) {
         $response = ['contents' => $contents, 'type' => $fileInfo['content_type'], 'size' => $fileInfo['size_download'], 'path' => $path];
         return $response;
     }
     return false;
 }
 /**
  * Determine if this stream is seekable
  *
  * @param resource $stream
  * @return bool True if this stream is seekable
  */
 protected function isSeekableStream($stream)
 {
     return Util::isSeekableStream($stream);
 }
Exemplo n.º 16
0
 /**
  * Builds the normalized output array from a Blob object.
  *
  * @param string         $path
  * @param BlobProperties $properties
  *
  * @return array
  */
 protected function normalizeBlobProperties($path, BlobProperties $properties)
 {
     return ['path' => $path, 'timestamp' => (int) $properties->getLastModified()->format('U'), 'dirname' => Util::dirname($path), 'mimetype' => $properties->getContentType(), 'size' => $properties->getContentLength(), 'type' => 'file'];
 }
Exemplo n.º 17
0
 /**
  * {@inheritdoc}
  */
 protected function normalizeObject(DataObject $object)
 {
     $name = $object->getName();
     $name = $this->removePathPrefix($name);
     $mimetype = explode('; ', $object->getContentType());
     return ['type' => in_array('application/directory', $mimetype) ? 'dir' : 'file', 'dirname' => Util::dirname($name), 'path' => $name, 'timestamp' => strtotime($object->getLastModified()), 'mimetype' => reset($mimetype), 'size' => $object->getContentLength()];
 }
Exemplo n.º 18
0
 /**
  * @inheritdoc
  */
 public function writeStream($path, $resource, Config $config)
 {
     $this->ensureDirectory(Util::dirname($path));
     if (!ftp_fput($this->getConnection(), $path, $resource, $this->transferMode)) {
         return false;
     }
     if ($visibility = $config->get('visibility')) {
         $this->setVisibility($path, $visibility);
     }
     return compact('path', 'visibility');
 }
 /**
  * Normalize the object result array.
  *
  * @param array  $response
  * @param string $path
  *
  * @return array
  */
 protected function normalizeResponse(array $response, $path = null)
 {
     $result = ['path' => $path ?: $this->removePathPrefix($response['Key'])];
     $result = array_merge($result, Util::pathinfo($result['path']));
     if (isset($response['LastModified'])) {
         $result['timestamp'] = strtotime($response['LastModified']);
     }
     if (substr($result['path'], -1) === '/') {
         $result['type'] = 'dir';
         $result['path'] = rtrim($result['path'], '/');
         return $result;
     }
     return array_merge($result, Util::map($response, static::$resultMap), ['type' => 'file']);
 }
Exemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function get($path, Handler $handler = null)
 {
     $path = Util::normalizePath($path);
     if (!$handler) {
         $metadata = $this->getMetadata($path);
         $handler = $metadata['type'] === 'file' ? new File($this, $path) : new Directory($this, $path);
     }
     $handler->setPath($path);
     $handler->setFilesystem($this);
     return $handler;
 }
Exemplo n.º 21
0
 /**
  * Normalize a result from AWS
  *
  * @param   string  $object
  * @param   string  $path
  * @return  array   file metadata
  */
 protected function normalizeObject($object, $path = null)
 {
     $result = array('path' => $path ?: $object['Key']);
     if (isset($object['LastModified'])) {
         $result['timestamp'] = strtotime($object['LastModified']);
     }
     $result = array_merge($result, Util::map($object, static::$resultMap), array('type' => 'file'));
     $result['dirname'] = Util::dirname($result['path']);
     if (isset($result['contents'])) {
         $result['contents'] = (string) $result['contents'];
     }
     return $result;
 }
Exemplo n.º 22
0
 /**
  * Join dir name and file name and return full path
  *
  * @param  string  $dir
  * @param  string  $name
  * @return string
  * @author Dmitry (dio) Levashov
  **/
 protected function _joinPath($dir, $name)
 {
     return Util::normalizePath($dir . $this->separator . $name);
 }
Exemplo n.º 23
0
 /**
  * Normalize a result from Copy.
  *
  * @param stdClass $object
  * @param string   $path
  *
  * @return array|false file metadata
  */
 protected function normalizeObject($object, $path)
 {
     if (!$object instanceof stdClass) {
         return false;
     }
     if (isset($object->modified_time)) {
         $timestamp = $object->modified_time;
     }
     $path = trim($this->removePathPrefix($path), '/');
     $result = Util::map((array) $object, static::$resultMap);
     return compact('timestamp', 'path') + $result;
 }
 /**
  * {@inheritdoc}
  */
 public function getRealPathName($file)
 {
     return Util::normalizePath($file);
 }
Exemplo n.º 25
0
 /**
  * Ensure parent directories of an object
  *
  * @param   string  $path  object path
  */
 public function ensureParentDirectories($path)
 {
     $object = $this->cache[$path];
     while ($object['dirname'] !== '' && !isset($this->cache[$object['dirname']])) {
         $object = Util::pathinfo($object['dirname']);
         $object['type'] = 'dir';
         $this->cache[$object['path']] = $object;
     }
 }
 /**
  * @inheritdoc
  */
 public function getMetadata($path)
 {
     $path = Util::normalizePath($path);
     $this->assertPresent($path);
     return $this->getAdapter()->getMetadata($path);
 }
Exemplo n.º 27
0
 /**
  * @inheritdoc
  */
 public function getMimetype($path)
 {
     if (!($metadata = $this->read($path))) {
         return false;
     }
     $metadata['mimetype'] = Util::guessMimeType($path, $metadata['contents']);
     return $metadata;
 }
Exemplo n.º 28
0
 /**
  * @param string $path
  * @param array  $config
  *
  * @throws \LogicException
  * @throws \InvalidArgumentException
  * @throws \Exception|\Throwable
  *
  * @return MediaEntity
  */
 protected function createFile($path, array $config)
 {
     $path = Util::normalizePath($path);
     $pathInfo = pathinfo($path);
     return (new MediaEntity())->getConnection()->transaction(function () use($path, $pathInfo, $config) {
         $parent = $this->ensureDirectory(dirname($path));
         $media = MediaEntity::create(['hash' => array_key_exists('hash', $config) ? $config['hash'] : md5(uniqid('media', true)), 'ext' => null, 'type' => MediaEntity::TYPE_FILE, 'caption' => array_key_exists('caption ', $config) ? $config['caption'] : $pathInfo['basename'], 'parent_id' => array_key_exists('parent_id', $config) ? $config['parent_id'] : null]);
         $dir = dirname($media->realPath);
         if (@mkdir($dir, 0755, true) && !is_dir($dir)) {
             throw new \InvalidArgumentException();
         }
         if ($parent) {
             $media->makeChildOf($parent);
         } else {
             $media->makeRoot();
         }
         return $media;
     });
 }
 /**
  * @dataProvider metaGetterProvider
  *
  * @param $method
  * @param $key
  * @param $value
  */
 public function testMetaGetters($method, $key, $value)
 {
     $cache = new Memory();
     $this->assertFalse($cache->{$method}('path.txt'));
     $cache->updateObject('path.txt', $object = ['path' => 'path.txt', 'type' => 'file', $key => $value] + Util::pathinfo('path.txt'), true);
     $this->assertEquals($object, $cache->{$method}('path.txt'));
     $this->assertEquals($object, $cache->getMetadata('path.txt'));
 }
Exemplo n.º 30
0
 protected function normalizeObject($object, $path = null)
 {
     $result = array('path' => $path ?: ltrim($object['path'], '/'));
     if (isset($object['modified'])) {
         $result['timestamp'] = strtotime($object['modified']);
     }
     $result = array_merge($result, Util::map($object, static::$resultMap));
     $result['type'] = $object['is_dir'] ? 'dir' : 'file';
     return $result;
 }