private function ProcessActions() { // Try to register try { // If user wants to register if ($this->registrationView->UserWantsToRegister()) { // Get Registration attempt $registrationAttemptArray = $this->registrationView->GetRegistrationAttempt(); // Create new userRegistration model from registration attempt $userRegistrationAttempt = new \model\UserRegistration($registrationAttemptArray['username'], $registrationAttemptArray['password'], $registrationAttemptArray['passwordRepeat']); // If there are no validation errors, proceed. if (\model\ValidationService::IsValid()) { // Create new user $newUser = new \model\User(null, $userRegistrationAttempt->GetUserName(), $userRegistrationAttempt->GetPassword()); // Add user in DAL $this->users->Add($newUser); // Set new message to display for user. \model\FlashMessageService::Set('Registered new user.'); // Store last login uname for login page $this->auth->SetLoginUsername($newUser); // New user registered successfully. Redirect to login page $this->appController->ReloadPage(); } } } catch (\Exception $exception) { // Store exceptions in applications exceptions container model \model\ExceptionsService::AddException($exception); } // Return registration failure return false; }
private function RenderMsg() { // Get exception messages if there are any. if (\model\ExceptionsService::HasExceptions()) { echo $this->LoadTemplate('MessageTpl', [\model\ExceptionsService::GetLastExceptionMessage()]); } else { if (\model\FlashMessageService::DoesExist()) { echo $this->LoadTemplate('MessageTpl', \model\FlashMessageService::GetAll()); } } }
public function __construct() { // Setup html view $this->htmlView = new HtmlView(); // Setup app helper service $this->ctrlHelper = new CtrlHelperService($this, new AppSettings(self::$APP_SETTINGS_ARRAY)); // Load global requirements $this->ctrlHelper->LoadBLLModel('Page'); $this->ctrlHelper->LoadDALModel('PageDAL'); try { // Parse and process url $this->ctrlHelper->ProcessUrl($this->htmlView->GetUrl()); // Execute controller $this->ctrlHelper->ExecuteController($this->controllerObj, $this->methodStr, $this->parameters); } catch (\Exception $exception) { // Store exceptions in applications exceptions container model \Model\ExceptionsService::AddException($exception); $this->htmlView->Render(""); } }
public function ProcessActions() { // Try to authenticate try { // If user is logged in and wants to logout if ($this->formView->UserWantsToLogout() && $this->auth->IsUserLoggedIn()) { $this->Logout(); } else { if ($this->formView->UserWantsToLogin() && !$this->auth->IsUserLoggedIn()) { // Get login attempt $loginAttemptArray = $this->formView->GetLoginAttempt(); // Create new user from login attempt $loginAttemptUser = new \model\User(NULL, $loginAttemptArray['username'], $loginAttemptArray['password'], false); // If there are no validation errors, proceed. if (\model\ValidationService::IsValid()) { // Try to authenticate user if ($user = $this->auth->Authenticate($loginAttemptUser)) { $this->DoLoginSuccess($user); } else { // The user was denied access throw new \Exception("Wrong name or password"); } } } else { if ($this->formView->IsLoginSavedOnClient() && !$this->auth->IsUserLoggedIn()) { // Get client login info $userInfoArray = $this->formView->GetLoginSavedOnClient(); $user = new \model\user(NULL, $userInfoArray['username'], NULL, false, false, $userInfoArray['token'], false); if ($this->auth->AuthenticatePersistent($user)) { $this->DoLoginSuccess($user); } } } } } catch (\Exception $exception) { // Store exceptions in applications exceptions container model \Model\ExceptionsService::AddException($exception); } // Return login failure return false; }
public function GetHTML() { $messageToUser = ''; // Get exception messages if there are any. if (\model\ExceptionsService::HasExceptions()) { foreach (\model\ExceptionsService::GetAllExceptionMessages() as $message) { $messageToUser .= $message . "<br>"; } } else { if (!\model\ValidationService::IsValid()) { foreach (\model\ValidationService::GetValidationErrors() as $message) { $messageToUser .= $message . "<br>"; } } else { if (\model\FlashMessageService::DoesExist()) { $messageToUser .= \model\FlashMessageService::Get(); } } } // Get output return $this->GetRegisterFormOutput($messageToUser); }
public function GetHTML() { $messageToUser = ''; // Get exception messages if there are any. if (\model\ExceptionsService::HasExceptions()) { $messageToUser = \model\ExceptionsService::GetLastExceptionMessage(); } else { if (!\model\ValidationService::IsValid()) { foreach (\model\ValidationService::GetValidationErrors() as $message) { $messageToUser .= $message . "<br>"; } } else { if (\model\FlashMessageService::DoesExist()) { $messageToUser = \model\FlashMessageService::Get(); } } } // Get login or logout form output return $this->auth->IsUserLoggedIn() ? $this->GetLogoutFormOutput($messageToUser) : $this->GetLoginFormOutput($messageToUser); }