/**
  * @Request({"user", "key"})
  */
 public function activateAction($username, $activation)
 {
     $message = '';
     if (empty($username) || empty($activation) || !($user = User::where(['username' => $username, 'activation' => $activation, 'status' => User::STATUS_BLOCKED, 'login IS NULL'])->first())) {
         return AuthController::messageView(['message' => __('Invalid key.'), 'success' => false]);
     }
     if ($admin = $this->module->config('registration') == 'approval' and !$user->get('verified')) {
         $user->activation = App::get('auth.random')->generateString(32);
         $this->sendApproveMail($user);
         $message = __('Your email has been verified. Once an administrator approves your account, you will be notified by email.');
     } else {
         $user->set('verified', true);
         $user->status = User::STATUS_ACTIVE;
         $user->activation = '';
         $this->sendWelcomeEmail($user);
         if ($admin) {
             $message = __('The user\'s account has been activated and the user has been notified about it.');
         } else {
             $message = __('Your account has been activated.');
         }
     }
     $user->save();
     App::message()->success($message);
     return App::redirect('@user/login');
 }
 /**
  * @Request({"user", "key"})
  */
 public function confirmAction($username = "", $activation = "")
 {
     if (empty($username) || empty($activation) || !($user = User::where(compact('username', 'activation'))->first())) {
         return $this->messageView(__('Invalid key.'), $success = false);
     }
     if ($user->isBlocked()) {
         return $this->messageView(__('Your account has not been activated or is blocked.'), $success = false);
     }
     $error = '';
     if ('POST' === App::request()->getMethod()) {
         try {
             if (!App::csrf()->validate()) {
                 throw new Exception(__('Invalid token. Please try again.'));
             }
             $password = App::request()->request->get('password');
             if (empty($password)) {
                 throw new Exception(__('Enter password.'));
             }
             if ($password != trim($password)) {
                 throw new Exception(__('Invalid password.'));
             }
             $user->password = App::get('auth.password')->hash($password);
             $user->activation = null;
             $user->save();
             App::message()->success(__('Your password has been reset.'));
             return App::redirect('@user/login');
         } catch (Exception $e) {
             $error = $e->getMessage();
         }
     }
     return ['$view' => ['title' => __('Reset Confirm'), 'name' => 'system/user/reset-confirm.php'], 'username' => $username, 'activation' => $activation, 'error' => $error];
 }
 /**
  * @Request({"user": "******"}, csrf=true)
  */
 public function saveAction($data)
 {
     $user = App::user();
     if (!$user->isAuthenticated()) {
         App::abort(404);
     }
     try {
         $user = User::find($user->id);
         if ($password = @$data['password_new']) {
             if (!App::auth()->getUserProvider()->validateCredentials($user, ['password' => @$data['password_old']])) {
                 throw new Exception(__('Invalid Password.'));
             }
             if (trim($password) != $password || strlen($password) < 3) {
                 throw new Exception(__('Invalid Password.'));
             }
             $user->password = App::get('auth.password')->hash($password);
         }
         if (@$data['email'] != $user->email) {
             $user->set('verified', false);
         }
         $user->name = @$data['name'];
         $user->email = @$data['email'];
         $user->validate();
         $user->save();
         return ['message' => 'success'];
     } catch (Exception $e) {
         App::abort(400, $e->getMessage());
     }
 }
Example #4
0
 /**
  * @Request({"url": "string"}, csrf=true)
  */
 public function downloadAction($url)
 {
     $file = tempnam(App::get('path.temp'), 'update_');
     App::session()->set('system.update', $file);
     if (!file_put_contents($file, @fopen($url, 'r'))) {
         App::abort(500, 'Download failed or Path not writable.');
     }
     return [];
 }
Example #5
0
 /**
  * Constructor.
  *
  * @param mixed $output
  */
 public function __construct($output = null)
 {
     $this->output = $output ?: new StreamOutput(fopen('php://output', 'w'));
     $config = array_flip(['path.temp', 'path.cache', 'path.vendor', 'path.artifact', 'path.packages', 'system.api']);
     array_walk($config, function (&$value, $key) {
         $value = App::get($key);
     });
     $this->composer = new Composer($config, $output);
 }
 /**
  * Register a field type.
  * @param array $package
  */
 protected function registerFieldType($package)
 {
     $loader = App::get('autoloader');
     if (isset($package['autoload'])) {
         foreach ($package['autoload'] as $namespace => $path) {
             $loader->addPsr4($namespace, $this->resolvePath($package, $path));
         }
     }
     $this->fieldTypes[$package['id']] = new $package['class']($package);
 }
Example #7
0
 /**
  * Gets a list of files and directories and their writable status.
  *
  * @return string[]
  */
 protected function getDirectories()
 {
     // -TODO-
     $directories = [App::get('path.storage'), App::get('path.temp'), App::get('config.file')];
     $result = [];
     foreach ($directories as $directory) {
         $result[$this->getRelativePath($directory)] = is_writable($directory);
         if (is_dir($directory)) {
             foreach (App::finder()->in($directory)->directories()->depth(0) as $dir) {
                 $result[$this->getRelativePath($dir->getPathname())] = is_writable($dir->getPathname());
             }
         }
     }
     return $result;
 }
 /**
  * @Request({"config": "array", "options": "array"}, csrf=true)
  */
 public function saveAction($values = [], $options = [])
 {
     $config = new Config();
     $config->merge(include $file = App::get('config.file'));
     foreach ($values as $module => $value) {
         $config->set($module, $value);
     }
     file_put_contents($file, $config->dump());
     foreach ($options as $module => $value) {
         $this->configAction($module, $value);
     }
     if (function_exists('opcache_invalidate')) {
         opcache_invalidate($file);
     }
     return ['message' => 'success'];
 }
Example #9
0
 /**
  * @Request({"url": "string", "shasum": "string"}, csrf=true)
  */
 public function downloadAction($url, $shasum)
 {
     try {
         $file = tempnam(App::get('path.temp'), 'update_');
         App::session()->set('system.update', $file);
         $client = new Client();
         $data = $client->get($url)->getBody();
         if (sha1($data) !== $shasum) {
             throw new \RuntimeException('Package checksum verification failed.');
         }
         if (!file_put_contents($file, $data)) {
             throw new \RuntimeException('Path is not writable.');
         }
         return [];
     } catch (\Exception $e) {
         if ($e instanceof TransferException) {
             $error = 'Package download failed.';
         } else {
             $error = $e->getMessage();
         }
         App::abort(500, $error);
     }
 }
 /**
  * @Request({"user", "key"})
  */
 public function activateAction($username, $activation)
 {
     if (empty($username) || empty($activation) || !($user = User::where(['username' => $username, 'activation' => $activation, 'login IS NULL'])->first())) {
         App::abort(400, __('Invalid key.'));
     }
     $verifying = false;
     if ($this->module->config('require_verification') && !$user->get('verified')) {
         $user->set('verified', true);
         $verifying = true;
     }
     if ($this->module->config('registration') === 'approval' && $user->status === User::STATUS_BLOCKED && $verifying) {
         $user->activation = App::get('auth.random')->generateString(32);
         $this->sendApproveMail($user);
         $message = __('Your email has been verified. Once an administrator approves your account, you will be notified by email.');
     } else {
         $user->status = User::STATUS_ACTIVE;
         $user->activation = '';
         $this->sendWelcomeEmail($user);
         $message = $verifying ? __('Your account has been activated.') : __('The user\'s account has been activated and the user has been notified about it.');
     }
     $user->save();
     App::message()->success($message);
     return App::redirect('@user/login');
 }
Example #11
0
 /**
  * Updates the user in the corresponding session.
  */
 public function onUserChange()
 {
     App::config('system/user')->set('auth.refresh_token', App::get('auth.random')->generateString(16));
 }
 /**
  * @Route("/", methods="GET")
  */
 public function indexAction()
 {
     return ['$view' => ['title' => __('Dashboard'), 'name' => 'system/dashboard:views/index.php'], '$data' => ['widgets' => array_values($this->dashboard->getWidgets()), 'api' => App::get('system.api'), 'version' => App::version(), 'channel' => 'stable']];
 }
Example #13
0
 /**
  * Initialize system.
  */
 public function onSystemInit()
 {
     App::auth()->setUserProvider(new UserProvider(App::get('auth.password')));
     App::auth()->refresh(App::module('system/user')->config('auth.refresh_token'));
 }
Example #14
0
 /**
  * @Request({"config": "array", "option": "array", "user": "******"})
  */
 public function installAction($config = [], $option = [], $user = [])
 {
     $status = $this->checkAction($config);
     $message = $status['message'];
     $status = $status['status'];
     try {
         if ('no-connection' == $status) {
             App::abort(400, __('No database connection.'));
         }
         if ('tables-exist' == $status) {
             App::abort(400, $message);
         }
         $scripts = new PackageScripts(App::path() . '/app/system/scripts.php');
         $scripts->install();
         App::db()->insert('@system_user', ['name' => $user['username'], 'username' => $user['username'], 'password' => App::get('auth.password')->hash($user['password']), 'status' => 1, 'email' => $user['email'], 'registered' => date('Y-m-d H:i:s'), 'roles' => '2,3']);
         $option['system']['version'] = App::version();
         $option['system']['extensions'] = ['blog'];
         $option['system']['site']['theme'] = 'theme-one';
         foreach ($option as $name => $values) {
             App::config()->set($name, App::config($name)->merge($values));
         }
         if ($this->packages) {
             $installer = new PackageManager(new NullOutput());
             $installer->install($this->packages);
         }
         if (file_exists(__DIR__ . '/../../install.php')) {
             require_once __DIR__ . '/../../install.php';
         }
         if (!$this->config) {
             $configuration = new Config();
             $configuration->set('application.debug', false);
             foreach ($config as $key => $value) {
                 $configuration->set($key, $value);
             }
             $configuration->set('system.secret', App::get('auth.random')->generateString(64));
             if (!file_put_contents($this->configFile, $configuration->dump())) {
                 $status = 'write-failed';
                 App::abort(400, __('Can\'t write config.'));
             }
         }
         App::module('system/cache')->clearCache();
         $status = 'success';
     } catch (DBALException $e) {
         $status = 'db-sql-failed';
         $message = __('Database error: %error%', ['%error%' => $e->getMessage()]);
     } catch (\Exception $e) {
         $message = $e->getMessage();
     }
     return ['status' => $status, 'message' => $message];
 }
 /**
  * @param array $options
  */
 public static function clearCache($options = [])
 {
     if (@$options['temp']) {
         App::file()->delete(App::get('path.cache') . '/portfolio');
     }
 }
Example #16
0
 /**
  * TODO: clear opcache
  */
 public function doClearCache(array $options = [])
 {
     // clear cache
     if (empty($options) || @$options['cache']) {
         App::cache()->flushAll();
         foreach (glob(App::get('path.cache') . '/*.cache') as $file) {
             @unlink($file);
         }
     }
     // clear temp folder
     if (@$options['temp']) {
         foreach (App::finder()->in(App::get('path.temp'))->depth(0)->ignoreDotFiles(true) as $file) {
             App::file()->delete($file->getPathname());
         }
     }
 }
Example #17
0
 /**
  * Tries to obtain package version from 'composer.json' or installation log.
  *
  * @param  $package
  * @return string
  */
 protected function getVersion($package)
 {
     if (!($path = $package->get('path'))) {
         throw new \RuntimeException(__('Package path is missing.'));
     }
     if (!file_exists($file = $path . '/composer.json')) {
         throw new \RuntimeException(__('\'composer.json\' is missing.'));
     }
     $package = json_decode(file_get_contents($file), true);
     if (isset($package['version'])) {
         return $package['version'];
     }
     if (file_exists(App::get('path.packages') . '/composer/installed.json')) {
         $installed = json_decode(file_get_contents($file), true);
         foreach ($installed as $package) {
             if ($package['name'] === $package->getName()) {
                 return $package['version'];
             }
         }
     }
     return '0.0.0';
 }
Example #18
0
<?php

use Pagekit\Application as App;
use Bixie\Portfolio\Event\RouteListener;
use Bixie\Portfolio\PortfolioImageHelper;
return ['name' => 'bixie/portfolio', 'type' => 'extension', 'main' => 'Bixie\\Portfolio\\PortfolioModule', 'autoload' => ['Bixie\\Portfolio\\' => 'src'], 'nodes' => ['portfolio' => ['name' => '@portfolio', 'label' => 'Portfolio', 'controller' => 'Bixie\\Portfolio\\Controller\\SiteController', 'protected' => true, 'frontpage' => true]], 'routes' => ['/portfolio' => ['name' => '@portfolio', 'controller' => ['Bixie\\Portfolio\\Controller\\PortfolioController']], '/api/portfolio' => ['name' => '@portfolio/api', 'controller' => ['Bixie\\Portfolio\\Controller\\ProjectApiController', 'Bixie\\Portfolio\\Controller\\ImageApiController']]], 'resources' => ['bixie/portfolio:' => ''], 'widgets' => ['widgets/portfolio-projects.php'], 'menu' => ['portfolio' => ['label' => 'Portfolio', 'icon' => 'bixie/portfolio:icon.svg', 'url' => '@portfolio/project', 'access' => 'portfolio: manage portfolio', 'active' => '@portfolio/project*'], 'portfolio: project' => ['label' => 'Projects', 'parent' => 'portfolio', 'url' => '@portfolio/project', 'access' => 'portfolio: manage portfolio', 'active' => '@portfolio/project*'], 'portfolio: settings' => ['label' => 'Settings', 'parent' => 'portfolio', 'url' => '@portfolio/settings', 'access' => 'portfolio: manage settings', 'active' => '@portfolio/settings*']], 'permissions' => ['portfolio: manage portfolio' => ['title' => 'Manage portfolio'], 'portfolio: manage settings' => ['title' => 'Manage settings']], 'settings' => '@portfolio/settings', 'config' => ['portfolio_title' => 'My portfolio', 'portfolio_text' => '<p>This is an overview of my latest projects.</p>', 'portfolio_image' => '', 'projects_per_page' => 20, 'project_ordering' => 'date|DESC', 'portfolio_image_align' => 'left', 'columns' => 1, 'columns_small' => 2, 'columns_medium' => '', 'columns_large' => 4, 'columns_xlarge' => 6, 'columns_gutter' => 20, 'filter_tags' => true, 'teaser' => ['show_title' => true, 'show_subtitle' => true, 'show_intro' => true, 'show_image' => true, 'show_client' => true, 'show_tags' => true, 'show_date' => true, 'show_data' => true, 'show_readmore' => true, 'show_thumbs' => true, 'template' => 'panel', 'panel_style' => 'uk-panel-box', 'overlay' => 'uk-overlay uk-overlay-hover', 'overlay_position' => '', 'overlay_effect' => 'uk-overlay-fade', 'overlay_image_effect' => 'uk-overlay-scale', 'content_align' => 'left', 'tags_align' => 'uk-flex-center', 'title_size' => 'uk-h3', 'title_color' => '', 'read_more' => 'Read more', 'link_image' => 'uk-button', 'read_more_style' => 'uk-button', 'readmore_align' => 'uk-text-center', 'thumbsize' => ['width' => 400, 'height' => ''], 'columns' => 1, 'columns_small' => 2, 'columns_medium' => '', 'columns_large' => 4, 'columns_xlarge' => 6, 'columns_gutter' => 20], 'project' => ['image_align' => 'left', 'metadata_position' => 'content-top', 'tags_align' => 'uk-flex-center', 'tags_position' => 'sidebar', 'show_navigation' => 'bottom', 'thumbsize' => ['width' => 400, 'height' => ''], 'overlay_title_size' => 'uk-h3', 'overlay' => 'uk-overlay uk-overlay-hover', 'overlay_position' => '', 'overlay_effect' => 'uk-overlay-fade', 'overlay_image_effect' => 'uk-overlay-scale', 'columns' => 1, 'columns_small' => 2, 'columns_medium' => '', 'columns_large' => 4, 'columns_xlarge' => 6, 'columns_gutter' => 20], 'cache_path' => str_replace(App::path(), '', App::get('path.cache') . '/portfolio'), 'date_format' => 'F Y', 'markdown' => true, 'datafields' => []], 'events' => ['boot' => function ($event, $app) {
    $app->subscribe(new RouteListener());
    $app->extend('view', function ($view) use($app) {
        return $view->addHelper(new PortfolioImageHelper($app));
    });
    //todo event to clear cache?
}, 'view.scripts' => function ($event, $scripts) use($app) {
    $scripts->register('uikit-grid', 'app/assets/uikit/js/components/grid.min.js', 'uikit');
    $scripts->register('uikit-lightbox', 'app/assets/uikit/js/components/lightbox.min.js', 'uikit');
}, 'console.init' => function ($event, $console) {
    $console->add(new Bixie\Portfolio\Console\Commands\TranslateCommand());
}]];
 /**
  * Initialize system.
  */
 public function onSystemInit()
 {
     App::auth()->setUserProvider(new UserProvider(App::get('auth.password')));
 }
Example #20
0
 /**
  * @Route("/", methods="POST")
  * @Route("/{id}", methods="POST", requirements={"id"="\d+"})
  * @Request({"user": "******", "password", "id": "int"}, csrf=true)
  */
 public function saveAction($data, $password = null, $id = 0)
 {
     try {
         // is new ?
         if (!($user = User::find($id))) {
             if ($id) {
                 App::abort(404, __('User not found.'));
             }
             if (!$password) {
                 App::abort(400, __('Password required.'));
             }
             $user = User::create(['registered' => new \DateTime()]);
         }
         $user->name = @$data['name'];
         $user->username = @$data['username'];
         $user->email = @$data['email'];
         $self = App::user()->id == $user->id;
         if ($self && @$data['status'] == User::STATUS_BLOCKED) {
             App::abort(400, __('Unable to block yourself.'));
         }
         if (@$data['email'] != $user->email) {
             $user->set('verified', false);
         }
         if (!empty($password)) {
             if (trim($password) != $password || strlen($password) < 3) {
                 throw new Exception(__('Invalid Password.'));
             }
             $user->password = App::get('auth.password')->hash($password);
         }
         $key = array_search(Role::ROLE_ADMINISTRATOR, @$data['roles'] ?: []);
         $add = false !== $key && !$user->isAdministrator();
         $remove = false === $key && $user->isAdministrator();
         if ($self && $remove || !App::user()->isAdministrator() && ($remove || $add)) {
             App::abort(403, 'Cannot add/remove Admin Role.');
         }
         unset($data['access'], $data['login'], $data['registered']);
         $user->validate();
         $user->save($data);
         return ['message' => 'success', 'user' => $user];
     } catch (Exception $e) {
         App::abort(400, $e->getMessage());
     }
 }
Example #21
0
 /**
  * @Request({"type": "string"}, csrf=true)
  */
 public function uploadAction($type)
 {
     $file = App::request()->files->get('file');
     if ($file === null || !$file->isValid()) {
         App::abort(400, __('No file uploaded.'));
     }
     $package = $this->loadPackage($file->getPathname());
     if (!$package->getName() || !$package->get('title') || !$package->get('version')) {
         App::abort(400, __('"composer.json" file not valid.'));
     }
     if ($package->get('type') !== 'pagekit-' . $type) {
         App::abort(400, __('No Pagekit %type%', ['%type%' => $type]));
     }
     $filename = str_replace('/', '-', $package->getName()) . '-' . $package->get('version') . '.zip';
     $file->move(App::get('path') . '/tmp/packages', $filename);
     return compact('package');
 }
 protected function request($url, $filter = [])
 {
     $config = App::module('analytics')->config();
     $service = App::get('analytics/oauth')->create('google', $config['credentials'], $config['token']);
     $result = json_decode($service->request($url), true);
     if ($filter) {
         $return = [];
         foreach ($filter as $key) {
             if (isset($result[$key])) {
                 $return[$key] = $result[$key];
             }
         }
     } else {
         $return = $result;
     }
     return $return;
 }
 public function extensionsAction()
 {
     return ['$view' => ['title' => __('Marketplace'), 'name' => 'installer:views/marketplace.php'], '$data' => ['title' => 'Extensions', 'type' => 'pagekit-extension', 'api' => App::get('system.api'), 'installed' => array_values(App::package()->all('pagekit-extension'))]];
 }
Example #24
0
<?php

use Pagekit\Application as App;
return ['name' => 'bixie/framework', 'type' => 'extension', 'main' => 'Bixie\\Framework\\FrameworkModule', 'fieldtypes' => 'fieldtypes', 'autoload' => ['Bixie\\Framework\\' => 'src'], 'routes' => ['/api/bixframework' => ['name' => '@bixframework/api', 'controller' => ['Bixie\\Framework\\Controller\\ImageApiController']]], 'resources' => ['bixie/framework:' => ''], 'permissions' => ['bixframework: upload files' => ['title' => 'Upload files']], 'settings' => 'settings-bixframework', 'config' => ['image_cache_path' => trim(str_replace(App::path(), '', App::get('path.storage') . '/bixframework'), '/')], 'events' => ['view.scripts' => function ($event, $scripts) use($app) {
    $scripts->register('framework-settings', 'bixie/framework:app/bundle/settings.js', '~extensions');
    $scripts->register('bixie-framework', 'bixie/framework:app/bundle/bixie-framework.js', ['vue']);
    //register fields
    $scripts->register('bixie-fieldtypes', 'bixie/framework:app/bundle/bixie-fieldtypes.js', ['vue', 'bixie-framework', 'uikit-tooltip']);
    foreach ($app->module('bixie/framework')->getFieldTypes() as $fieldType) {
        $fieldType->registerScripts($scripts);
    }
}, 'console.init' => function ($event, $console) {
    $console->add(new Bixie\Framework\Console\Commands\TranslateCommand());
}]];