Ejemplo n.º 1
0
 public function execute()
 {
     if (!Session::has('user')) {
         $this->template->setHeaderLogin('login', __DIR__);
     }
     $this->template->setBody('Home/Views/home');
     $this->template->render();
 }
Ejemplo n.º 2
0
 public function execute()
 {
     if (Session::has('username')) {
         $this->response->redirect('/');
     }
     $this->template->setBody('User/Views/login');
     $this->template->render();
 }
Ejemplo n.º 3
0
 /**
  *  Validates user input in Register form and saves customer into database.
  */
 public function execute()
 {
     $this->userVO->setEmail($this->request->getPost('email'));
     $this->userVO->setUserName($this->request->getPost('username'));
     $this->userVO->setUserPassword($this->userService->hashPassword($this->request->getPost('password')));
     if ($this->validate()) {
         try {
             $this->userDAO->save($this->userVO);
             UserVO::setMessage('Thank you for registering on our website!');
             Session::set('username', $this->userVO->getUserName());
             $this->response->redirect('/');
         } catch (\Exception $e) {
             echo $e->getMessage();
         }
     } else {
         throw new \Exception('Password and Confirm Password fields should be the same.');
     }
 }
Ejemplo n.º 4
0
 /**
  *  Logs in customer.
  */
 public function execute()
 {
     $user = $this->userDAO->getByUserEmail($this->request->getPost('email'));
     try {
         if (!$user->getEmail()) {
             throw new \Exception('User with specified email does not exist.');
         }
         $isPasswordVerified = $this->userService->verify($this->request->getPost('password'), $user->getUserPassword());
         if (!$isPasswordVerified) {
             throw new \Exception('Invalid username/password. Check your credentials.');
         }
         $this->userService->verify($this->request->getPost('password'), $user->getUserPassword());
         Session::setMessage('You have successfully logged in!');
         Session::set('username', $user->getUserName());
         $this->response->redirect('/');
     } catch (\Exception $e) {
         echo $e->getMessage();
     }
 }
Ejemplo n.º 5
0
 /**
  * @param mixed $message
  */
 public static function setMessage($message)
 {
     Session::set('message', $message);
 }
Ejemplo n.º 6
0
 /**
  *  Logs out user.
  */
 public function execute()
 {
     Session::destroy();
     $this->response->redirect('/');
 }
Ejemplo n.º 7
0
 /**
  * App constructor.
  *
  * @param \App\Router $router
  * @param ActionFactoryInterface $actionFactory
  */
 public function __construct(Router $router, ActionFactoryInterface $actionFactory)
 {
     Session::start();
     $this->router = $router;
     $this->actionFactory = $actionFactory;
 }