Esempio n. 1
0
 public static function postUser(PHPWS_User $user, $set_username = true)
 {
     if (!$user->id || $user->authorize == PHPWS_Settings::get('users', 'local_script') && $set_username) {
         $user->_prev_username = $user->username;
         $result = $user->setUsername($_POST['username']);
         if (PHPWS_Error::isError($result)) {
             $error['USERNAME_ERROR'] = $result->getMessage();
         }
         if ($user->_prev_username != $user->username && (empty($_POST['password1']) || empty($_POST['password2']))) {
             $error['PASSWORD_ERROR'] = dgettext('users', 'Passwords must be reentered on user name change.');
         }
     }
     if (!isset($error['USERNAME_ERROR']) && isset($_POST['display_name'])) {
         $result = $user->setDisplayName($_POST['display_name']);
         if (PHPWS_Error::isError($result)) {
             $error['DISPLAY_ERROR'] = $result->getMessage();
         }
     }
     if (!$user->isUser() || (!empty($_POST['password1']) || !empty($_POST['password2']))) {
         $result = $user->checkPassword($_POST['password1'], $_POST['password2']);
         if (PHPWS_Error::isError($result)) {
             $error['PASSWORD_ERROR'] = $result->getMessage();
         } else {
             $user->setPassword($_POST['password1']);
         }
     }
     $result = $user->setEmail($_POST['email']);
     if (PHPWS_Error::isError($result)) {
         $error['EMAIL_ERROR'] = $result->getMessage();
     }
     if (Current_User::isLogged() && Current_User::allow('users', 'settings') && isset($_POST['authorize'])) {
         $user->setAuthorize($_POST['authorize']);
     }
     if (isset($_POST['language'])) {
         $locale = preg_replace('/\\W/', '', $_POST['language']);
         setcookie('phpws_default_language', $locale, time() + CORE_COOKIE_TIMEOUT);
     }
     if (isset($error)) {
         return $error;
     } else {
         return true;
     }
 }