public function index_action()
 {
     if (Routing::getInstance()->isMethod("GET")) {
         echo View::render();
         return true;
     }
     $userModel = new UserModel();
     if ($userModel->checkUserExist($_REQUEST['username'])) {
         $data['error'] = 'Username already used.';
         echo View::render($data);
         return false;
     }
     foreach ($_REQUEST as $key => $item) {
         if (empty($item)) {
             $data['error'] = 'All fields must be provided';
             echo View::render($data);
             return false;
         }
     }
     if (!$userModel->save($_REQUEST)) {
         $data['error'] = 'Problem with DB Query.';
         echo View::render($data);
         return false;
     }
     $userData = $userModel->getUserByUsernameAndPassword($_REQUEST['username'], $_REQUEST['password']);
     Security::doLogin($userData);
     return header("Location:" . Routing::getInstance()->getBaseUrl());
 }
Esempio n. 2
0
 public function view($name, $data = array())
 {
     $detect = $this->detectDay();
     $data['day'] = $detect[0];
     $data['name_day'] = $detect[1];
     $data['logged'] = Auth::check();
     $data['user'] = Auth::get();
     $view = new View($name, $data);
     return $view->render();
 }
Esempio n. 3
0
 /**
  * @param string $actionID
  * @param array $params
  *
  * @return \lib\Response
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  */
 public function runAction($actionID, array $params = [])
 {
     $action = 'action' . ucwords($actionID);
     if (!method_exists($this, $action)) {
         throw new \RuntimeException(sprintf('Method [%s] not exist in class [%s]', $action, get_class($this)));
     }
     $content = $this->{$action}($params);
     if (null !== $this->layout) {
         $meta = isset($params['meta']) ? $params['meta'] : [];
         $currentMenu = isset($params['menu']) ? $params['menu'] : null;
         $layout = new View($this->layout, $meta, $currentMenu);
         $content = $layout->render(['content' => $content]);
     }
     $response = new Response();
     $response->setContent($content);
     return $response;
 }
Esempio n. 4
0
 public function login()
 {
     //        if(Security::isAuth()){
     //          return header("Location:".Routing::getInstance()->getBaseUrl());
     //        }
     //
     if (Routing::getInstance()->isMethod("GET")) {
         echo View::render();
         return true;
     }
     $userModel = new UserModel();
     $userData = $userModel->getUserByUsernameAndPassword($_REQUEST['username'], $_REQUEST['password']);
     if ($userData) {
         Security::doLogin($userData);
         if (isset($_REQUEST['remember_me'])) {
             Security::setRemember();
         }
         return header("Location:" . Routing::getInstance()->getBaseUrl());
     }
     return header("Location:" . Routing::getInstance()->getBaseUrl() . '/auth/login');
 }
Esempio n. 5
0
 public function newsList()
 {
     $newsModel = new NewsModel();
     $data['list'] = $newsModel->getList();
     echo View::render($data);
 }
Esempio n. 6
0
 public function actionAbout()
 {
     $view = new View('views/index/about');
     return $view->render();
 }
Esempio n. 7
0
 /**
  * @return string
  */
 public function actionList()
 {
     $view = new View('views/articles/list');
     return $view->render();
 }