/** * Handle user input. */ public function listen() { if ($this->regView->registerButtonPost()) { $username = $this->regView->getUsername(); $password = $this->regView->getPassword(); $passwordRepeat = $this->regView->getPasswordRepeat(); try { if ($this->regModel->verifyRegisterCredentials($username, $password, $passwordRepeat)) { $this->logView->setCookieUsername($this->regView->getUsername()); $this->regView->redirectToLogin(); } } catch (RUsernameAndPasswordLengthException $e) { $this->regView->setMsgUsernameAndPasswordException(); } catch (RPasswordLengthException $e) { $this->regView->setMsgPassWordLengthException(); } catch (RUsernameLengthException $e) { $this->regView->setMsgUsernameLengthException(); } catch (RPasswordMismatchException $e) { $this->regView->setMsgPasswordMismatchException(); } catch (RUserExistsException $e) { $this->regView->setMsgUserExistsException(); } catch (RInvalidCharactersException $e) { $this->regView->setMsgInvalidCharacterException(); } } }
public function doRegisterAction() { if ($this->registerView->userPressedRegister()) { try { $registrationCredentials = $this->registerView->getRegistrationCredentials(); if ($registrationCredentials == null) { return; } $this->registerModel->registerUser($registrationCredentials); $this->registerView->setRegistrationSuccess(); } catch (\common\UsernameTakenException $e) { $this->registerView->setRegistrationFailed(); } catch (\Exception $e) { $this->registerView->setDatabaseError(); } } }
/** * Attempts to authenticate * @param UserCredentials $uc * @return boolean */ public function doLogin(UserCredentials $uc, \model\RegisterModel $regModel) { $this->tempCredentials = $this->tempDAL->load($uc->getName()); $loginByUsernameAndPassword = false; $userData = $regModel->getUser($uc->getName()); if ($userData) { $userDataSep = explode("::", $userData); $pwDecrypt = password_verify(trim($uc->getPassword()), trim($userDataSep[1])); $loginByUsernameAndPassword = strcmp($uc->getName(), $userDataSep[0]) == 0 && $pwDecrypt; // $loginByUsernameAndPassword = (strcmp($uc->getName(), $userDataSep[0]) == 0) && (strcmp(trim($uc->getPassword()), trim($userDataSep[1])) == 0); } else { $loginByUsernameAndPassword = false; } $loginByTemporaryCredentials = $this->tempCredentials != null && $this->tempCredentials->isValid($uc->getTempPassword()); if ($loginByUsernameAndPassword || $loginByTemporaryCredentials) { $user = new LoggedInUser($uc); $_SESSION[self::$sessionUserLocation] = $user; return true; } return false; }
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(); } }