Esempio n. 1
0
 public static function updateUser()
 {
     // Process updating of user information
     $authenticatedUser = array_key_exists('authenticatedUser', $_SESSION) ? $_SESSION['authenticatedUser'] : null;
     $users = WebUserDB::getUsersBy('hockName', $_SESSION['arguments']);
     if (empty($users)) {
         UserController::showHome();
     } elseif ($_SERVER["REQUEST_METHOD"] == "GET") {
         $_SESSION['webuser'] = $users[0];
         $user = $users[0];
         if (!is_null($authenticatedUser)) {
             if (strcmp($user->getUserName(), $authenticatedUser->getUserName()) == 0) {
                 UserView::showUpdate();
             } else {
                 UserController::showHome();
             }
         } else {
             UserController::showHome();
         }
     } else {
         $user = $_SESSION['webuser'];
         if (!is_null($authenticatedUser)) {
             if (strcmp($user->getUserName(), $authenticatedUser->getUserName()) == 0) {
                 //$oldpw = (array_key_exists('oldPassword', $_POST))?$_POST['oldPassword']:null;
                 $parms = $users[0]->getParameters();
                 //if(is_null($oldpw) || strcmp($oldpw, $parms['password'])
                 //This is set up so that any empty parameters in update will be ignored.
                 //Only things entered will actually be updated
                 //username
                 $parms['userName'] = array_key_exists('userName', $_POST) ? empty($_POST['userName']) ? $authenticatedUser->getUserName() : $_POST['userName'] : $authenticatedUser->getUserName();
                 //password
                 $parms['password'] = array_key_exists('password', $_POST) ? empty($_POST['password']) ? $authenticatedUser->getPassword() : $_POST['password'] : $authenticatedUser->getPassword();
                 //confirmedpw
                 $parms['confirmedpw'] = array_key_exists('confirmedpw', $_POST) ? empty($_POST['confirmedpw']) ? $authenticatedUser->getConfirmedPW() : $_POST['confirmedpw'] : $authenticatedUser->getConfirmedPW();
                 //email
                 $parms['email'] = array_key_exists('email', $_POST) ? empty($_POST['email']) ? $authenticatedUser->getEmail() : $_POST['email'] : $authenticatedUser->getEmail();
                 //url
                 $parms['url'] = array_key_exists('url', $_POST) ? empty($_POST['url']) ? $authenticatedUser->getURL() : $_POST['url'] : $authenticatedUser->getURL();
                 $user = new WebUser($parms);
                 $user->setUserId($users[0]->getUserId());
                 $user = WebUserDB::updateUser($user);
                 if ($user->getErrorCount() != 0) {
                     $_SESSION['webuser'] = $user;
                     UserView::showUpdate();
                 } else {
                     $_SESSION['authenticatedUser'] = $user;
                     UserController::showHome();
                 }
             } else {
                 UserController::showHome();
             }
         } else {
             UserController::showHome();
         }
     }
 }
Esempio n. 2
0
 public static function getUsersArray($rowSets)
 {
     // Returns an array of User objects extracted from $rowSets
     $users = array();
     if (!empty($rowSets)) {
         foreach ($rowSets as $userRow) {
             $user = new WebUser($userRow);
             $user->setUserId($userRow['userId']);
             $user->setConfirmedPW($userRow['password']);
             $user->clearError('confirmedpw');
             array_push($users, $user);
         }
     }
     return $users;
 }