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; }
public function testMethods() { // Clear validations \model\ValidationService::Clear(); $appSettings = $this->setupAppsettings(); // Create app mockup object with properties $appMockup = new \stdClass(); $appMockup->htmlView = new \stdClass(); // Create ctrl helper class $ctrlHelper = new \model\CtrlHelperService($appMockup, $appSettings); // Ctrl to string method $CtrlString = $ctrlHelper->CtrlToString(new \controller\PageCtrl($ctrlHelper)); $this->assertEquals("page", $CtrlString); // ProcessUrl method // $ctrlHelper->ProcessUrl('/page/leading/somewhere'); Not testable // Execute controller method $ctrlHelper->ExecuteController(new DummyClass(), "DummyMethod", ["someParam"]); // A new flashmessage should be added. $this->assertTrue(\model\FlashMessageService::DoesExist()); // Clear flashmessage \model\FlashMessageService::Clear(); $riskyFile = '/etc/passwd'; // Load methods $this->assertFalse($ctrlHelper->LoadController($riskyFile)); $this->assertFalse($ctrlHelper->LoadBLLModel($riskyFile)); $this->assertFalse($ctrlHelper->LoadDALModel($riskyFile)); $this->assertFalse($ctrlHelper->LoadService($riskyFile)); $this->assertFalse($ctrlHelper->LoadView($riskyFile)); // Create methods $this->assertFalse($ctrlHelper->CreateController($riskyFile)); $this->assertFalse($ctrlHelper->CreateBLLModel($riskyFile)); $this->assertFalse($ctrlHelper->CreateDALModel($riskyFile)); $this->assertFalse($ctrlHelper->CreateService($riskyFile)); $this->assertFalse($ctrlHelper->CreateView($riskyFile)); }
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 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); }
private function DoLoginSuccess($user) { // Store logged in user object in sessions cookie $this->auth->KeepUserLoggedInForSession($user); // Check if user wants login to be remembered if ($this->formView->DoesUserWantLoginToBeRemembered()) { // Save persistent login on server $this->auth->SaveLoginOnServer($user); // Save persistent login on client $this->formView->SaveLoginOnClient($user); } // Set a login message to be displayed for the user. \model\FlashMessageService::Set($this->formView->GetLoggedInMessage()); $this->appController->ReloadPage(); }
public function Delete() { // Load file dependencies $this->ctrlHelper->LoadDALModel('UserDAL'); $this->ctrlHelper->LoadDALModel('LoginDAL'); // Create objects $pages = $this->ctrlHelper->CreateDALModel('PageDAL'); $auth = $this->ctrlHelper->CreateService('AuthService'); if ($auth->IsUserLoggedIn()) { // Get page id from params $pageId = $this->ctrlHelper->urlParameters[0]; // Create page to delete $page = new \model\Page($pageId); // Delete page $pages->Delete($page); // Display message to user \model\FlashMessageService::Add("Sidan raderades med ett lyckat resultat."); // Redirect $this->ctrlHelper->RedirectTo($this); } }
public static function ConvertErrorsToFlashMessages() { foreach (self::$validationErrorsArray as $errorMessage) { \model\FlashMessageService::Add($errorMessage, 'error'); } }
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); }
public function Login() { // Create view $loginView = $this->ctrlHelper->CreateView('LoginView'); // Load file dependencies $this->ctrlHelper->LoadBLLModel('User'); $this->ctrlHelper->LoadDALModel('UserDAL'); $this->ctrlHelper->LoadDALModel('LoginDAL'); $this->ctrlHelper->LoadService('UserClientService'); // Create Auth service $auth = $this->ctrlHelper->CreateService('AuthService'); // If user is already logged in if ($auth->IsUserLoggedIn()) { $this->ctrlHelper->RedirectTo("page"); } // If user wants to login if ($loginView->UserWantsToLogin()) { // Get login attempt $loginAttemptArray = $loginView->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 = $auth->Authenticate($loginAttemptUser)) { // Store logged in user object in sessions cookie $auth->KeepUserLoggedInForSession($user); if ($loginView->UserWantsLoginToBeRemembered()) { // Save persistent login on server $auth->SaveLoginOnServer($user); $loginView->SaveLoginOnClient($user); } \model\FlashMessageService::Add("Inloggningen lyckades."); $this->ctrlHelper->RedirectTo("page/show"); } else { // The user was denied access \model\FlashMessageService::Add("Fel användarnamn eller lösenord", "warning"); } } else { // Move errors to flash messages, witch will be displayed for user. \model\ValidationService::ConvertErrorsToFlashMessages(); } } $this->ctrlHelper->RedirectTo($this); }