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 getUserByUsername($username)
 {
     try {
         $db = $this->connection();
         $sql = "SELECT * FROM " . self::$dbTable . " WHERE " . self::$userName . " = ?";
         $params = array($username);
         $query = $db->prepare($sql);
         $query->execute($params);
         $result = $query->fetch();
         if ($result) {
             $user = new User();
             $user->SetUsername($result[self::$userName]);
             $user->SetHash($result[self::$password]);
             $user->SetUserID($result[self::$userID]);
             return $user;
         } else {
             return NULL;
         }
     } catch (\PDOException $e) {
         throw new \Exception();
     }
 }