/**
  * Function for handling states associated with the login
  */
 public function doLogin()
 {
     //var_dump(self::$LoginView->isCorrectSession());
     if (self::$LoginView->theUserWantToLogout()) {
         self::$LoginView->setLogoutView();
         self::$LoginModel->logout();
         $tempUsername = self::$LoginView->removeKeepLogin();
         self::$LoginModel->removeUser($tempUsername);
     } else {
         if (self::$LoginView->theUserWantToLogin()) {
             self::$LoginView->setLoginView();
             $successfulLogin = self::$LoginModel->login(self::$LoginView->getUser());
             if ($successfulLogin && self::$LoginView->isKeepLoggedInChecked()) {
                 $randomizedPassword = self::$LoginModel->saveUser(self::$LoginView->getUser());
                 self::$LoginView->setKeepLogin($randomizedPassword);
             }
         } else {
             if (self::$LoginView->checkIfPersistentLoggedIn()) {
                 self::$LoginModel->loginSavedUser(self::$LoginView->getPersistentLoggedInUser());
                 self::$LoginView->setLoginWithCookiesView();
             } else {
                 if (!self::$LoginView->validCookies()) {
                     //            self::$LoginModel->logout();
                     self::$LoginView->removeKeepLogin();
                     self::$LoginView->setFailedLoginWithCookiesView();
                 }
             }
         }
     }
     if (self::$PrgView->isPost()) {
         self::$PrgView->reloadPage();
     }
 }
예제 #2
0
 /**
  * Called when user wishes to logout.
  * Calls \model\LoginModel to destroy session, and
  * \view\LoginView to delete cookies.
  *
  * Sets \view\LoginView message.
  */
 public function logout()
 {
     if ($this->logModel->isLoggedIn()) {
         $this->logModel->logout();
         $this->logView->deleteCredentialCookies();
         $this->logView->setMsgLogout();
     }
 }
 /**
  * Handle user input
  */
 public function listen()
 {
     if ($this->logView->isRegisteredCookieSet()) {
         $this->logView->setMsgRegistered();
         $this->logView->deleteRegisteredCookie();
         if ($this->logView->isCookieNameSet()) {
             $this->logView->setLoginName($this->logView->getCookieName());
         }
     }
     // Login
     if ($this->logView->loginButtonPost() && !$this->logModel->isLoggedIn()) {
         try {
             $this->login();
         } catch (LUsernameMissingException $e) {
             $this->logView->setMsgUsernameMissing();
         } catch (LPasswordMissingException $e) {
             $this->logView->setMsgPasswordMissing();
         } catch (LUsernameOrPasswordException $e) {
             $this->logView->setMsgUsernameOrPassword();
         }
     } else {
         if ($this->logView->logoutButtonPost() && $this->logModel->isLoggedIn()) {
             $this->logModel->logout();
             $this->logView->deleteCredentialCookies();
         } else {
             if ($this->logView->isPost()) {
                 $this->logView->redirect();
             } else {
                 if ($this->logView->isCookiesSet()) {
                     try {
                         $this->cookieLogin();
                     } catch (LWrongCookieInformationException $e) {
                         $this->logView->deleteCredentialCookies();
                         $this->logView->setMsgWrongCookieInfo();
                     }
                 }
             }
         }
     }
 }