/** * @return string HTML */ public function doControl() { // if the user has clicked the submit button if ($this->loginFormView->isSubmitted()) { try { $username = $this->loginFormView->getUsername(); $password = $this->loginFormView->getPassword(); if ($this->loginModel->validate($username, $password)) { if ($this->loginFormView->clickedRemember()) { $this->loginModel->setCookies(); $message = $this->loginFormView->remberMeMsg(); } else { $message = $this->loginFormView->loggedInMsg(); } if ($this->loginModel->isRefreshed()) { $message = $this->loginFormView->refreshPageMsg(); } $this->adminView->setMessage($message); return $this->adminView->getAdminHTML(); } } catch (\Exception $e) { $this->loginFormView->setMessage($e->getMessage()); return $this->loginFormView->getForm(); } } //if the user logged out if ($this->adminView->logOutClicked() && $this->loginModel->isLoggedIn()) { $this->loginModel->logOut(); $message = $this->loginFormView->loggedOutMsg(); $this->loginFormView->setMessage($message); $this->loginModel->unsetCookies(); return $this->loginFormView->getForm(); } //if the user has saved cookies if ($this->loginModel->hasSavedCookies()) { try { $username = $this->loginModel->getCookieUsername(); $password = $this->loginModel->getCookiePassword(); $cookiTime = $this->loginModel->getCookieTime(); if ($this->loginModel->validateCookies($username, $password, $cookiTime)) { $message = $this->loginFormView->cookieMsg(); $this->adminView->setMessage($message); return $this->adminView->getAdminHTML(); } } catch (\Exception $e) { $this->loginFormView->setMessage($e->getMessage()); $this->loginModel->unsetCookies(); return $this->loginFormView->getForm(); } } //if user is logged in if ($this->loginModel->isLoggedIn()) { return $this->adminView->getAdminHTML(); } return $this->loginFormView->getForm(); }