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 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');
 }