Example #1
0
 public function redirect()
 {
     $requestPath = Request::getRequestPath();
     $requestPath = ltrim($requestPath, '/');
     $bean = Url::findUrl($requestPath);
     if (!$bean) {
         throw new Error('The request URL is not exists', 404);
     } else {
         header('Location: ' . $bean->url);
     }
 }
Example #2
0
 /**
  * 
  * Parses request and returns the requested controller/view
  */
 public function run()
 {
     $request = new Request();
     $requestedRoute = trim($request->getServer('REQUEST_URI'));
     $routeParts = explode('/', $requestedRoute);
     $requestMethod = strtolower($request->getServer('REQUEST_METHOD'));
     $controllersPath = $this->_config['controllersPath'];
     $viewPaths = $this->_config['viewsPath'];
     $controllerName = empty($routeParts[1]) ? 'Index' : ucfirst($routeParts[1]);
     $controllerFile = $controllersPath . DIRECTORY_SEPARATOR . $controllerName . '.php';
     $viewFile = $viewPaths . DIRECTORY_SEPARATOR . strtolower($controllerName) . '.phtml';
     if (file_exists($controllerFile)) {
         include $controllerFile;
         try {
             $controller = new $controllerName($request);
             $controller->{$requestMethod}();
             if (file_exists($viewFile)) {
                 $content = file_get_contents($viewFile);
                 echo '<!DOCTYPE HTML>
                         <head>
                             <meta http-equiv="content-type" content="text/html; charset=utf-8">
                             <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css">
                             <link rel="stylesheet" href="/css/styles.css">
                         </head>
                         <body>' . $controller->displayErrors() . $content . '</body>
                       </html>';
             } else {
                 die(sprintf('View not found in %s', $viewFile));
             }
         } catch (\Exception $e) {
             // @todo handle exception
             die($e->getMessage());
         }
     } else {
         header('HTTP/1.0 404 Not Found');
         die('Document not found');
     }
 }
Example #3
0
 /**
  * @return bool|void
  * @throws \Exception
  * @throws \SmartyException
  */
 public function action_register()
 {
     if (!\Request::current()->is_ajax()) {
         \Assets::js('register', base_UI . 'js/Auth/register.js');
         $this->response->body($this->template->fetch('Auth/register.tpl'));
     } else {
         $attrs = ['email', 'pass', 'pass2', 'first_name', 'birthday'];
         foreach ($attrs as $item) {
             if (!isset($_POST[$item])) {
                 $this->response->body(json_encode(['code' => -3]));
                 return;
             }
         }
         if ($userInfo = User::model()->findByAttributes(['email' => $_POST['email']])) {
             $this->response->body(json_encode(['code' => -4]));
             return;
         }
         if ($_POST['pass'] !== $_POST['pass2']) {
             $this->response->body(json_encode(['code' => -1]));
             return;
         }
         //Create new account
         $_POST['last_login'] = time();
         $user_id = \Auth\Base::create($_POST);
         if ($user_id == false) {
             $this->response->body(json_encode(['code' => -2]));
             return true;
         } else {
             $this->response->body(json_encode(['code' => true]));
             return true;
         }
     }
 }