/** * @param SessionModel $sessionModel * @return string */ public function showMemberView($sessionModel) { // Get agent from session and set to view. $this->memberView->SetUser($sessionModel->GetUser()); // If user created cookie,logged in or registered, show messages. $cookieView = new CookieView(); if ($cookieView->cookieExist()) { $this->memberView->cookieWelcome(); } $this->memberView->loginWelcome(); $this->memberView->registerWelcome(); $this->memberView->exampleSubmitUml(); try { //TODO Break out userSaveToZip to own function to remove nested IF. if ($this->memberView->userSubmitUml()) { $this->memberView->handleInput(); } else { if ($this->memberView->userSaveToServer()) { $this->saveUML(); } else { if ($umlPost = $this->memberView->userSaveToZip()) { $classArray = $this->interpretModel->validate($umlPost); if (count($classArray) === 0) { $this->memberView->canNotIntepretMSG(); } else { if ($classArray === null) { $this->guestView->toLongInputMSG(); } else { new SaveToZipView($classArray); } } } } } } catch (UmlStringToShortException $e) { $this->memberView->umlToShortMSG(); } catch (NoHTMLAllowedException $e) { $this->memberView->noHTMLMSG(); } return $this->memberView->showMemberContents(); }
private function onSubmit() { $username = $this->registerView->GetUsername(); $password1 = $this->registerView->GetPassword1(); $password2 = $this->registerView->GetPassword2(); try { $user = new User(); if ($password1 === $password2) { $this->registerModel->SetUsername($username); $hashedPassword = $this->registerModel->hashPassword($password1); $user->SetPassword($hashedPassword); } else { $this->registerView->msgPasswordNotSame(); return; } $user->SetUsername($username); $userRepository = new UserRepository(); $userRepository->add($user); $loginView = new LoginView(); $agent = $loginView->GetAgent(); $sessionModel = new SessionModel(); $sessionModel->SetValidSession($agent); $sessionModel->SetUser($username); NavView::redirectToUMLRegisterMSG($username); } catch (RegisterUsernameLengthException $e) { $this->registerView->msgUsernameLength(); } catch (RegexException $e) { $name = $e->getMessage(); $this->registerView->SetUsername($name); $this->registerView->msgUsernameWrongChar($name); } catch (RegisterException $e) { $this->registerView->msgPasswordLength(); } catch (DbUserExistException $e) { $this->registerView->msgUserExist(); } catch (RegisterUsernameMaxLengthException $e) { $this->registerView->msgUsernameMaxLength(); } catch (RegisterPasswordMaxLengthException $e) { $this->registerView->msgPasswordMaxLength(); } }
public function loginView() { // If user submit login. Then log in. if ($this->loginView->userSubmit()) { // Retrieve username and password string from LoginView from user post. $password = $this->loginView->GetPassword(); $username = $this->loginView->GetUsername(); $trueAgent = $this->loginView->GetAgent(); // Check userModel if user can log in. if ($this->loginModel->LogIn($username, $password, $trueAgent)) { // Create cookie if user clicked select box in login view. $this->sessionModel->SetUser($username); if ($this->loginView->wantCookie()) { $this->setCookie(); NavView::redirectToUMLMSG($username); } NavView::redirectToUMLMSG($username); } else { $this->loginView->FailedMSG($username, $password); } } return $this->loginView->show(); }