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(); }