/**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     if (UserHelper::isLogin()) {
         Ioc::getApplication()->redirect(Router::build('admin:dashboard'));
     }
     $model = new LoginModel();
     $session = Ioc::getSession();
     $user = $this->input->getVar('user');
     $result = $model->login($user['username'], $user['password']);
     $package = $this->getPackage();
     $redirect = $session->get('login.redirect.url');
     if ($result) {
         $url = $redirect ? base64_decode($redirect) : $package->get('redirect.login');
         $msg = Language::translate('Login Success');
     } else {
         $router = Ioc::getRouter();
         $url = $router->build($this->package->getRoutingPrefix() . ':login');
         $msg = Language::translate('Login Fail');
     }
     $uri = new Uri($url);
     if (!$uri->getScheme()) {
         $url = $this->app->get('uri.base.full') . $url;
     }
     $session->remove('login.redirect.url');
     $this->setRedirect($url, $msg);
     return true;
 }
示例#2
0
 /**
  * Execute the controller.
  *
  * @throws \Exception
  * @return  mixed Return executed result.
  */
 public function execute()
 {
     $user = $this->input->getVar('registration');
     $user = new Data($user);
     $session = Ioc::getSession();
     $session['register.form.data'] = $user;
     $trans = Ioc::getDatabase()->getTransaction()->start();
     try {
         $this->validate($user);
         // User
         $user = $this->createUser($user);
         // Blog
         $blogCtrl = $this->createBlog($user);
         // Articles
         $this->createDefaultArticle($blogCtrl);
     } catch (ValidFailException $e) {
         $trans->rollback();
         $this->setRedirect(Router::buildHttp('user:registration'), $e->getMessage(), 'danger');
         return false;
     } catch (\Exception $e) {
         $trans->rollback();
         if (WINDWALKER_DEBUG) {
             throw $e;
         }
         $this->setRedirect(Router::buildHttp('user:registration'), 'Register fail', 'danger');
         return false;
     }
     $trans->commit();
     $session->remove('register.form.data');
     // OK let's login
     User::makeUserLogin($user->id);
     $this->setRedirect(Router::buildHttp('user:login'), 'Register success.', 'success');
     return true;
 }
示例#3
0
 /**
  * doExecute
  *
  * @return  bool
  */
 protected function doExecute()
 {
     $table = $this->getArgument(0);
     if (!$table) {
         throw new \InvalidArgumentException('No table');
     }
     $db = Ioc::getDatabase();
     $columns = $db->getTable($table)->getColumnDetails();
     if ($file = $this->getOption('o')) {
         if ($file == 1) {
             $file = '/form/fields/' . $table . '.php.tpl';
         }
         $file = new \SplFileInfo(WINDWALKER_TEMP . '/' . ltrim($file, '/\\'));
         if (!is_dir($file)) {
             Folder::create($file->getPath());
         }
         $output = '';
         foreach ($columns as $column) {
             $output .= $this->handleColumn($column) . "\n";
         }
         file_put_contents($file->getPathname(), $output);
         $this->out()->out('File output to: ' . $file->getPathname());
     } else {
         $this->out()->out('Start Generate Fields')->out('--------------------------------------------------')->out()->out();
         foreach ($columns as $column) {
             $this->out($this->handleColumn($column));
         }
     }
     return true;
 }
示例#4
0
 /**
  * initialise
  *
  * @return  void
  */
 protected function initialise()
 {
     Windwalker::prepareSystemPath($this->config);
     parent::initialise();
     // Start session
     Ioc::getSession()->start();
 }
示例#5
0
 protected function prepareData($data)
 {
     parent::prepareData($data);
     $input = Ioc::getInput();
     $data->function = $input->getString('function');
     $data->selector = $input->getString('selector');
 }
示例#6
0
 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container $container The DI container.
  *
  * @return  void
  */
 public function register(Container $container)
 {
     $closure = function (Container $container) {
         return new \S3($container->get('app')->get('amazon.access_key'), $container->get('app')->get('amazon.secret_key'));
     };
     Ioc::getContainer()->share('s3', $closure);
 }
示例#7
0
 /**
  * loadRouting
  *
  * @return  mixed
  */
 public static function loadRouting()
 {
     $app = Ioc::getApplication();
     if ($app->get('client') == 'site') {
         return parent::loadRouting();
     }
     return [];
 }
 /**
  * getUrl
  *
  * @return  string
  */
 protected function getUrl()
 {
     $package = PackageHelper::getPackage($this->package);
     $package = $package ?: Ioc::get('current.package');
     $route = $this->get('route', $this->route) ?: $this->view;
     $query = $this->get('query', $this->query);
     return $package->router->html($route, array_merge(array('layout' => 'modal', 'selector' => '#' . $this->getId() . '-wrap', 'function' => 'Natika.Field.Modal.select'), $query));
 }
示例#9
0
 /**
  * matchRequest
  *
  * @param array $query
  *
  * @return  boolean
  */
 protected function matchRequest($query = [])
 {
     $input = Ioc::getInput();
     if (!$query) {
         return true;
     }
     return !empty(ArrayHelper::query([$input->toArray()], $query));
 }
示例#10
0
 /**
  * onAfterRouting
  *
  * @param Event $event
  *
  * @return  void
  */
 public function onAfterRouting(Event $event)
 {
     $app = Ioc::getApplication();
     $controller = Ioc::get('main.controller');
     if ($controller->getPackage() instanceof AdminPackage) {
         // Check is logged-in or redirect to login page
         UserHelper::checkLogin();
     }
 }
示例#11
0
 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     if (UserHelper::isLogin()) {
         Ioc::getApplication()->redirect(Router::build('admin:dashboard'));
     }
     $model = new LoginModel();
     $view = new LoginHtmlView();
     $view['form'] = $model->getForm();
     return $view->render();
 }
示例#12
0
 /**
  * initialise
  *
  * @return  void
  */
 protected function initialise()
 {
     Windwalker::prepareSystemPath($this->config);
     parent::initialise();
     if (!$this->config->get('system.debug')) {
         SimpleErrorHandler::registerErrorHandler();
     }
     // Start session
     Ioc::getSession();
 }
示例#13
0
 /**
  * registerListeners
  *
  * @param Dispatcher $dispatcher
  *
  * @return  void
  */
 public function registerListeners(Dispatcher $dispatcher)
 {
     $config = Ioc::getConfig();
     $plugins = $config->get('plugins', array());
     foreach ($plugins as $plugin) {
         if (class_exists($plugin) && is_subclass_of($plugin, 'Vaseman\\Plugin\\AbstractPlugin') && $plugin::$isEnabled) {
             $dispatcher->addListener(new $plugin());
         }
     }
 }
示例#14
0
 /**
  * constructor.
  *
  * @param Command     $command
  * @param Container   $container
  * @param IOInterface $io
  */
 public function __construct(Command $command, Container $container = null, IOInterface $io = null)
 {
     $this->command = $command;
     $container = $container ?: Ioc::factory();
     $this->container = $container;
     $container->registerServiceProvider(new MuseProvider($this));
     $io = $io ?: $container->get('io');
     $io->setCommand($command);
     parent::__construct($io);
 }
 /**
  * onBeforeRouting
  *
  * @param Event $event
  *
  * @return  void
  *
  * @throws \Exception
  */
 public function onAfterRouting(Event $event)
 {
     $app = Ioc::getApplication();
     $controller = Ioc::get('main.controller');
     $route = $app->get('uri.route');
     if (trim($route, '/')) {
         return;
     }
     Ioc::getContainer()->share('main.controller', $controller);
 }
示例#16
0
 /**
  * loadGlobalProvider
  *
  * @return  Data
  */
 public static function loadGlobalProvider()
 {
     if (static::$data) {
         return static::$data;
     }
     $event = new Event('loadGlobalProvider');
     $event['data'] = new Data();
     Ioc::getDispatcher()->triggerEvent($event);
     return static::$data = $event['data'];
 }
示例#17
0
 /**
  * getList
  *
  * @param Query    $query
  * @param integer  $start
  * @param integer  $limit
  *
  * @return  \stdClass[]
  */
 public function getList(Query $query, $start = null, $limit = null)
 {
     $query->limit($start, $limit);
     if (WINDWALKER_DEBUG) {
         $profiler = Ioc::getProfiler();
         $profiler->mark(uniqid() . ' - ' . (string) $query->dump());
     }
     $select = $query->select;
     $select = str_replace('SELECT ', 'SQL_CALC_FOUND_ROWS ', $select);
     $query->clear('select')->select($select);
     return $this->db->getReader($query)->loadObjectList();
 }
示例#18
0
 /**
  * checkLogin
  *
  * @return  boolean
  */
 public static function checkLogin()
 {
     if (User::get()->notNull()) {
         return true;
     }
     $session = Ioc::getSession();
     $current = Ioc::getConfig()->get('uri.current');
     $current = base64_encode($current);
     $session->set('login.redirect.url', $current);
     Ioc::getApplication()->redirect(Router::buildHttp('user:login'));
     return true;
 }
示例#19
0
 /**
  * getItems
  *
  * @return  \stdClass[]
  */
 protected function getItems()
 {
     $db = Ioc::getDatabase();
     $query = $this->get('query', $this->get('sql'));
     if (is_callable($query)) {
         $handler = $query;
         $query = $db->getQuery(true);
         call_user_func($handler, $query, $this);
     }
     if (!$query) {
         return array();
     }
     return (array) $db->setQuery($query)->loadAll();
 }
示例#20
0
 /**
  * onViewBeforeRender
  *
  * @param Event $event
  *
  * @return  void
  */
 public function onViewBeforeRender(Event $event)
 {
     $data = $event['data'];
     $data->user = $data->user ?: User::get();
     $articleMapper = new ArticleMapper();
     $data->articles = $data->articles ?: $articleMapper->find(['state' => 1], 'ordering');
     foreach ($data->articles as $article) {
         $article->link = $article->url ?: Router::html('forum@article', ['id' => $article->id, 'alias' => $article->alias]);
     }
     // Template
     $config = Ioc::getConfig();
     if ($config['natika.theme']) {
         $event['view']->getRenderer()->addPath(WINDWALKER_TEMPLATES . '/theme/' . $config['natika.theme'] . '/' . $event['view']->getName(), Priority::HIGH);
     }
 }
 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     $model = new BlogsModel();
     $model['user.id'] = User::get()->id;
     $data['activeMenu'] = $this->input->get('activeMenu', 'none');
     $data['hideMenu'] = $this->input->get('hideMenu', 0);
     $data['widget'] = new Data();
     // $data['widget']['sidebar'] = (new SidebarController($this->input, $this->app))->execute();
     $data['blog'] = Blog::get();
     $data['blogs'] = $model->getItems();
     $data['user'] = User::get();
     $data['profiler'] = WINDWALKER_DEBUG ? Ioc::getProfiler() : null;
     $this->data = $data;
     return $this->doExecute();
 }
示例#22
0
 /**
  * getBlog
  *
  * @return  Data
  */
 public static function get()
 {
     if (static::$blog) {
         return static::$blog;
     }
     $session = Ioc::getSession();
     $blogId = $session->get('current.blog');
     $blogModel = new BlogModel();
     $user = User::get();
     if ($user->isNull()) {
         throw new \RuntimeException('No user');
     }
     $blog = $blogModel->getCurrentBlog($user->id, $blogId);
     $blog->params = json_decode($blog->params);
     $session->set('current.blog', $blog->id);
     return static::$blog = $blog;
 }
 /**
  * getForm
  *
  * @param string|FieldDefinitionInterface $definition
  * @param string                          $control
  * @param bool|mixed                      $loadData
  *
  * @return Form
  */
 public function getForm($definition = null, $control = null, $loadData = false)
 {
     $form = new Form($control);
     if (is_string($definition)) {
         $definition = $this->getFieldDefinition($definition);
     }
     $form->defineFormFields($definition);
     if ($loadData === true) {
         $form->bind($this->getFormDefaultData());
     } elseif ($loadData) {
         $form->bind($loadData);
     }
     $renderer = $this->get('field.renderer', $this->formRenderer);
     if (class_exists($renderer)) {
         $form->setRenderer(new $renderer());
     }
     Ioc::getDispatcher()->triggerEvent('onModelAfterGetForm', array('form' => $form, 'model' => $this, 'control' => $control, 'definition' => $definition));
     return $form;
 }
示例#24
0
 /**
  * Vue Resource.
  *
  * @see  Configuration           https://github.com/vuejs/vue-resource/blob/master/docs/config.md
  * @see  HTTP Requests/Response  https://github.com/vuejs/vue-resource/blob/master/docs/http.md
  * @see  Creating Resources      https://github.com/vuejs/vue-resource/blob/master/docs/resource.md
  * @see  Code Recipes            https://github.com/vuejs/vue-resource/blob/master/docs/recipes.md
  *
  * @param array $options
  * @param array $headers
  */
 public static function resource(array $options = [], array $headers = [])
 {
     if (!static::inited(__METHOD__)) {
         static::core();
         static::addJS(static::phoenixName() . '/js/vue/vue-resource.min.js');
         $defaultOptions = ['root' => Ioc::getUriData()->path];
         $options = static::getJSObject($defaultOptions, $options);
         $defaultHealders = ['common' => ['X-Csrf-Token' => CsrfProtection::getFormToken()]];
         $headers = static::mergeOptions($defaultHealders, $headers);
         $headers = array_intersect_key($headers, array_flip(['common', 'custom', 'delete', 'patch', 'post', 'put']));
         $js[] = "// Init Vue-resource http settings.";
         $js[] = "Vue.http.options = Object.assign({}, Vue.http.options, {$options});";
         foreach ($headers as $key => $headerLines) {
             if (count($headerLines)) {
                 $js[] = "Vue.http.headers.{$key} = Object.assign({}, Vue.http.headers.{$key}, " . static::getJSObject($headerLines) . ");";
             }
         }
         static::internalJS(implode("\n", $js));
     }
 }
示例#25
0
    /**
     * Execute the controller.
     *
     * @return  mixed Return executed result.
     *
     * @throws  \LogicException
     * @throws  \RuntimeException
     */
    public function execute()
    {
        $query = $this->input->getString('query');
        $query = trim($query);
        if (!$query) {
            return;
        }
        $queries = explode(' ', $query);
        $mapper = new DataMapper('users');
        $conditions = [];
        $q = Ioc::getDatabase()->getQuery(true);
        foreach ($queries as $query) {
            if (!trim($query)) {
                continue;
            }
            $query = $q->quote('%' . $query . '%');
            $conditions[] = 'username LIKE ' . $query;
            $conditions[] = 'fullname LIKE ' . $query;
            $conditions[] = 'email LIKE ' . $query;
        }
        $conditions = new QueryElement('()', $conditions, ' OR ');
        $users = $mapper->find([(string) $conditions], 'username', 0, 10);
        $suggestions = [];
        $tmpl = <<<VALUE
<div>
\t<img width="48" height="48" class="find-author-avatar pull-left" src="%s" alt=""/>
\t<div class="find-author-name">%s <small>%s</small></div>
\t<small>%s</small>
\t<div class="clearfix"></div>
</div>
VALUE;
        foreach ($users as $user) {
            $suggestions[] = ['value' => sprintf($tmpl, UserHelper::getAvatar($user->id), $user->fullname, $user->username, $user->email), 'data' => $user->username];
        }
        $response = new Response();
        $response->setBody(json_encode(['suggestions' => $suggestions]));
        $response->setMimeType('text/json');
        $response->respond();
        exit;
        return true;
    }
示例#26
0
 /**
  * Do this execute.
  *
  * @return  mixed
  */
 protected function doExecute()
 {
     $this->io->out('[<comment>SQL</comment>] Running migrations');
     $package = 'gen_' . $this->config['replace.package.name.lower'];
     if (!PackageHelper::getPackage($package)) {
         $packageClass = sprintf('%s%s\\%sPackage', $this->config['replace.package.namespace'], $this->config['replace.package.name.cap'], $this->config['replace.package.name.cap']);
         PackageHelper::getInstance()->addPackage($package, $packageClass);
     }
     $dir = WINDWALKER_SOURCE . '/' . str_replace('\\', '/', MvcHelper::getPackageNamespace($packageClass, 1)) . '/Migration';
     /** @var WindwalkerConsole $app */
     $app = Ioc::getApplication();
     // A dirty work to call migration command.
     /** @var IOInterface $io */
     $io = clone $this->io->getIO();
     $io->setArguments(array('migration', 'migrate'));
     $io->setOption('d', $dir);
     $io->setOption('seed', null);
     $io->setOption('s', null);
     $io->setOption('no-backup', true);
     $app->getRootCommand()->setIO($io)->execute();
 }
示例#27
0
 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     $model = new LoginModel();
     $user = $this->input->getVar('user');
     $result = $model->login($user['username'], $user['password']);
     $package = $this->getPackage();
     if ($result) {
         $url = $package->get('redirect.login');
         $msg = Language::translate('pkg.user.login.success');
     } else {
         $router = Ioc::getRouter();
         $url = $router->build($this->package->getRoutingPrefix() . ':login');
         $msg = Language::translate('pkg.user.login.fail');
     }
     $uri = new Uri($url);
     if (!$uri->getScheme()) {
         $url = $this->app->get('uri.base.full') . $url;
     }
     $this->setRedirect($url, $msg);
     return true;
 }
示例#28
0
 /**
  * Execute the controller.
  *
  * @throws \Exception
  * @return  mixed Return executed result.
  */
 public function execute()
 {
     $session = Ioc::getSession();
     $user = $this->input->getVar('user', array());
     $user = new Data($user);
     $user->id = User::get()->id;
     $user->username = User::get()->username;
     // Store Session
     $temp = clone $user;
     unset($temp->password);
     unset($temp->password2);
     $session->set('profile.edit.data', $temp);
     try {
         if (!$this->validate($user)) {
             return false;
         }
         $record = new Record('users');
         $record->load($user->id);
         $record->bind($user);
         $record->check()->store(true);
     } catch (ValidFailException $e) {
         $this->setRedirect(Router::buildHttp('admin:profile', ['id' => $user->id ?: '']), $e->getMessage(), 'danger');
         return true;
     } catch (\Exception $e) {
         if (WINDWALKER_DEBUG) {
             throw $e;
         }
         $this->setRedirect(Router::buildHttp('admin:profile', ['id' => $user->id ?: '']), 'Save fail', 'danger');
         return true;
     }
     // Save success, reset user session
     unset($user->password);
     unset($user->password2);
     $session->set('user', $user);
     $session->remove('profile.edit.data');
     $this->setRedirect(Router::buildHttp('admin:profile'), 'Save Success', 'success');
     return true;
 }
示例#29
0
 /**
  * Execute the controller.
  *
  * @throws \Exception
  * @return  mixed Return executed result.
  */
 public function execute()
 {
     $user = User::get($this->input->get('user_id'));
     $blog = $this->input->getVar('blog');
     $blog = new Data($blog);
     $blog->params = $this->input->getByPath('blog.params', array(), null);
     $isNew = !$blog->id;
     $blog->state = 1;
     $blog->alias = OutputFilter::stringURLSafe($blog->alias);
     if ($isNew) {
         $blog->params['css'] = $this->getDefaultCss();
     }
     if (!$this->validate($blog)) {
         return false;
     }
     $trans = Ioc::getDatabase()->getTransaction()->start();
     try {
         $blog->params = json_encode($blog->params);
         $this->blog = (new DataMapper('blogs'))->saveOne($blog, 'id');
         if ($isNew) {
             $author['user'] = $user->id;
             $author['blog'] = $this->blog->id;
             $author['owner'] = 1;
             $author['admin'] = 1;
             $this->author = (new DataMapper('authors'))->createOne($author);
         }
         $trans->commit();
     } catch (\Exception $e) {
         $trans->rollback();
         if (WINDWALKER_DEBUG) {
             throw $e;
         }
         $this->setRedirect(Router::buildHttp('admin:blog', ['id' => $blog->id ?: '']), 'Save fail', 'danger');
         return true;
     }
     $this->setRedirect(Router::buildHttp('admin:blogs'), 'Save Success', 'success');
     return true;
 }
示例#30
0
 /**
  * getItems
  *
  * @return  \stdClass[]
  */
 protected function getItems()
 {
     $db = Ioc::getDatabase();
     $query = $db->getQuery(true);
     $table = $this->get('table', $this->table);
     if (!$table) {
         return array();
     }
     if ($this->get('published')) {
         $query->where($query->quoteName($this->get('stateField', 'state')) . ' >= 1');
     }
     if ($ordering = $this->get('ordering', $this->ordering)) {
         $query->order($ordering);
     }
     $select = $this->get('select', '*');
     $query->select($select)->from($table);
     $this->postQuery($query);
     $postQuery = $this->get('postQuery');
     if (is_callable($postQuery)) {
         call_user_func($postQuery, $query, $this);
     }
     return (array) $db->setQuery($query)->loadAll();
 }