Exemplo n.º 1
0
 public function start()
 {
     $request = new Request();
     $this->session = new SessionLogin();
     if ($this->session->isLogged()) {
         if ($request->urlAction === 'liveConnect') {
             try {
                 Messenger::send(LiveConnect::controller());
             } catch (\PDOException $e) {
                 Messenger::send(new Message($e->getCode(), $e->getMessage()));
             } catch (Exception $ex) {
                 Messenger::send($request->invalid(Request::INCORRECT_ACTION));
             }
         } else {
             if ($request->urlAction === 'logout') {
                 Messenger::send($this->logout());
             } else {
                 Messenger::send($request->invalid(Request::INCORRECT_ACTION));
             }
         }
     } else {
         if ($request->urlAction === 'login') {
             $this->login();
         } else {
             Messenger::send($request->invalid(Request::NO_SESSION));
         }
     }
 }
Exemplo n.º 2
0
 public static function newInstance($path = \simpleChat\Utility\ROOT_PATH)
 {
     $request = new Request();
     if ($request->isAjax()) {
         return new AjaxController();
     } else {
         if ($request->jsCode()) {
             return new JsController();
         } else {
             return new StandardController($path);
         }
     }
 }
Exemplo n.º 3
0
 public function login()
 {
     $request = new Request();
     if (!$this->isLogged()) {
         if (Validator::login($request->input('login'))) {
             $this->vars->setSession($request->input('login'));
             //Try to add user to database, if nickname is already in use
             //the exception will be thrown, PDOException can be thrown on
             //error as well.
             try {
                 $this->db->addNewUser($this->vars->getLogin(), $this->vars->getSessionID(), $this->vars->getSessionTime());
             } catch (Exception $e) {
                 $this->vars->destroySession();
                 throw new Exception($e->getMessage(), $e->getCode());
             }
             return new Message(200, 'Login ok');
         } else {
             throw new Exception('Incorrect login', 401);
         }
     } else {
         throw new Exception('User is already logged.', 400);
     }
 }