Ejemplo n.º 1
0
 /**
  * onBeforeRouting
  *
  * @param Event $event
  *
  * @return  void
  *
  * @throws \Exception
  */
 public function onBeforeRouting(Event $event)
 {
     $app = Ioc::getApplication();
     $uri = $app->initUri();
     $uri = new Uri(strtolower($uri->full));
     $host = $uri->getHost();
     $host = explode('.', $host);
     array_pop($host);
     array_pop($host);
     $alias = implode('.', $host);
     $alias = trim(str_replace('.', '', $alias));
     // If is main domain but logged in, go to admin
     if (!$alias && UserHelper::isLogin()) {
         $app->set('client', 'admin');
         return;
     }
     // Has subdomain, means it is users' blog
     if ($alias) {
         $blogMapper = new DataMapper('blogs');
         $blog = $blogMapper->findOne(['alias' => $alias]);
         if ($blog->isNull()) {
             throw new \Exception('Blog not found', 404);
         }
         Ioc::getContainer('front')->set('current.blog', $blog);
         $app->set('client', 'front');
         return;
     }
     // Main domain, got to site
     $app->set('client', 'site');
 }
Ejemplo n.º 2
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();
     $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;
 }
Ejemplo n.º 3
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();
 }
Ejemplo n.º 4
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 RegistrationModel();
     $view = new RegistrationHtmlView();
     $session = Ioc::getSession();
     $view['item'] = $session['register.form.data'] ?: array();
     $view['item'] = new Data($view['item']);
     return $view->render();
 }