Beispiel #1
0
 function testAuthorizeUser()
 {
     $info = new UserInfo($this->data);
     $store = new UserDB();
     $store->updateUser($info);
     $result = $store->authorizeUser($info);
     $this->assertEquals($info->userid, $result->userid);
     $this->assertEquals($info->username, $result->username);
     $fake = new UserInfo(array('username' => 'test', 'password' => 1111));
     $result = $store->authorizeUser($fake);
     $this->assertEquals(null, $result);
 }
 public static function post()
 {
     if (isset($_POST['edit'])) {
         $page = new Page();
         $page->data['title'] = 'Profiel';
         ProfileController::buildProfileTopView($page, true, false);
         $page->addView('profile/ProfileEnabledFormBottomView');
         ProfileController::buildMembershipDetailsView($page);
         $page->showWithMenu();
     } elseif (isset($_POST['save'])) {
         $page = new Page();
         $page->data['title'] = 'Profiel';
         $errMsgs = ProfileTopViewValidator::validate($_POST);
         if (empty($errMsgs)) {
             //If no error: create a new user from posted data and try to save it
             $newUser = ProfileController::createUserFromPost();
             try {
                 UserDB::updateUser($_SESSION['Stippers']['Profile']['user'], $newUser);
                 $page->data['SuccessMessageNoDescriptionWithLinkView']['successTitle'] = 'Gegevens succesvol bijgewerkt';
                 $page->data['SuccessMessageNoDescriptionWithLinkView']['redirectUrl'] = $_SERVER['REQUEST_URI'];
                 $page->addView('success/SuccessMessageNoDescriptionWithLinkView');
             } catch (UserDBException $ex) {
                 //Show correct error message for errors
                 if ($ex->getCode() == UserDBException::USEROUTOFDATE) {
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['errorTitle'] = 'Gegevens niet bijgewerkt';
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['errorDescription'] = 'Iemand anders heeft je gegevens in tussentijd al gewijzigd.';
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['tryAgainUrl'] = $_SERVER['REQUEST_URI'];
                     $page->addView('error/ErrorMessageWithDescriptionWithLinkView');
                 } else {
                     ProfileController::buildProfileTopView($page, true, true);
                     if ($ex->getCode() == UserDBException::EMAILALREADYEXISTS) {
                         $page->data['ProfileTopView']['errMsgs']['global'] = '<h2 class="error_message" id="profile_form_error_message">Dit e-mailadres is al in gebruik.</h2>';
                     } else {
                         $page->data['ProfileTopView']['errMsgs']['global'] = '<h2 class="error_message" id="profile_form_error_message">Kan gegevens niet bijwerken, probeer het opnieuw.</h2>';
                     }
                     $page->addView('profile/ProfileEnabledFormBottomView');
                 }
             }
         } else {
             //If we had an error we show the views with enabled controls and take data from POST
             ProfileController::buildProfileTopView($page, true, true);
             $page->addView('profile/ProfileEnabledFormBottomView');
             $page->data['ProfileTopView']['errMsgs'] = array_merge($page->data['ProfileTopView']['errMsgs'], $errMsgs);
             ProfileController::buildMembershipDetailsView($page);
         }
         $page->showWithMenu();
     } else {
         ProfileController::get();
     }
 }
 public static function post()
 {
     //Redirect to manageuser page if back to results button was clicked
     if (isset($_POST['back_to_search_results'])) {
         header('Location: manageuser', true, 303);
     } elseif (isset($_POST['cancel'])) {
         EditUserController::get();
     } elseif (isset($_POST['edit'])) {
         $page = new Page();
         $page->data['title'] = 'Gebruiker bewerken';
         EditUserController::buildEditUserTopView($page, true, false);
         if ($_SESSION['Stippers']['user']->isAdmin) {
             EditUserController::buildEditUserAdminView($page, true, false);
         }
         if ($_SESSION['Stippers']['user']->isAdmin || $_SESSION['Stippers']['user']->isMoneyManager) {
             EditUserController::buildEditUserMoneyManagerView($page);
         }
         $page->addView('editUser/EditUserEnabledFormBottomView');
         EditUserController::buildMembershipDetailsView($page);
         $page->showWithMenu();
     } else {
         $page = new Page();
         $page->data['title'] = 'Gebruiker bewerken';
         $errMsgs = EditUserTopViewValidator::validate($_POST);
         if (empty($errMsgs)) {
             //If no error: create a new user from posted data and try to save it
             $newUser = EditUserController::createUserFromPost();
             try {
                 UserDB::updateUser($_SESSION['Stippers']['EditUser']['user'], $newUser);
                 $page->data['SuccessMessageNoDescriptionWithLinkView']['successTitle'] = 'Gebruiker succesvol bijgewerkt';
                 $page->data['SuccessMessageNoDescriptionWithLinkView']['redirectUrl'] = $_SERVER['REQUEST_URI'];
                 $page->addView('success/SuccessMessageNoDescriptionWithLinkView');
             } catch (UserDBException $ex) {
                 //Show correct error message for errors
                 if ($ex->getCode() == UserDBException::USEROUTOFDATE) {
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['errorTitle'] = 'Gebruiker niet bijgewerkt';
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['errorDescription'] = 'Iemand anders heeft de gebruiker in tussentijd al gewijzigd.';
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['tryAgainUrl'] = $_SERVER['REQUEST_URI'];
                     $page->addView('error/ErrorMessageWithDescriptionWithLinkView');
                 } else {
                     EditUserController::buildEditUserTopView($page, true, true);
                     if ($ex->getCode() == UserDBException::EMAILALREADYEXISTS) {
                         $page->data['EditUserTopView']['errMsgs']['global'] = '<h2 class="error_message" id="edit_user_form_error_message">Dit e-mailadres is al in gebruik.</h2>';
                     } else {
                         $page->data['EditUserTopView']['errMsgs']['global'] = '<h2 class="error_message" id="edit_user_form_error_message">Kan gebruiker niet bijwerken, probeer het opnieuw.</h2>';
                     }
                     EditUserController::buildMembershipDetailsView($page);
                     if ($_SESSION['Stippers']['user']->isAdmin) {
                         EditUserController::buildEditUserAdminView($page, true, true);
                     }
                     if ($_SESSION['Stippers']['user']->isAdmin || $_SESSION['Stippers']['user']->isMoneyManager) {
                         EditUserController::buildEditUserMoneyManagerView($page);
                     }
                     $page->addView('editUser/EditUserEnabledFormBottomView');
                 }
             } catch (Exception $ex) {
                 EditUserController::buildEditUserTopView($page, true, true);
                 if ($ex->getCode() == UserDBException::EMAILALREADYEXISTS) {
                     $page->data['EditUserTopView']['errMsgs']['global'] = '<h2 class="error_message" id="edit_user_form_error_message">Dit e-mailadres is al in gebruik.</h2>';
                 } else {
                     $page->data['EditUserTopView']['errMsgs']['global'] = '<h2 class="error_message" id="edit_user_form_error_message">Kan gebruiker niet bijwerken, probeer het opnieuw.</h2>';
                 }
                 EditUserController::buildMembershipDetailsView($page);
                 if ($_SESSION['Stippers']['user']->isAdmin) {
                     EditUserController::buildEditUserAdminView($page, true, true);
                 }
                 if ($_SESSION['Stippers']['user']->isAdmin || $_SESSION['Stippers']['user']->isMoneyManager) {
                     EditUserController::buildEditUserMoneyManagerView($page);
                 }
                 $page->addView('editUser/EditUserEnabledFormBottomView');
             }
         } else {
             //If we had an error we show the views with enabled controls and take data from POST
             EditUserController::buildEditUserTopView($page, true, true);
             $page->data['EditUserTopView']['errMsgs'] = array_merge($page->data['EditUserTopView']['errMsgs'], $errMsgs);
             EditUserController::buildMembershipDetailsView($page);
             if ($_SESSION['Stippers']['user']->isAdmin) {
                 EditUserController::buildEditUserAdminView($page, true, true);
             }
             if ($_SESSION['Stippers']['user']->isAdmin || $_SESSION['Stippers']['user']->isMoneyManager) {
                 EditUserController::buildEditUserMoneyManagerView($page);
             }
             $page->addView('editUser/EditUserEnabledFormBottomView');
         }
         $page->showWithMenu();
     }
 }