public static function getUser($i_id = -1) { $returnUser = null; if (true == array_key_exists("{$i_id}", self::$instances)) { $returnUser = self::$instances[$i_id]; } else { $returnUser = new User(self::XML_FILE, 0, true); if (-1 != $i_id) { $returnUser->setProperty('id', $i_id); parent::loadObjectData($returnUser); } } return $returnUser; }
public function testDestruct_Event_StorageWrite() { // test read, write from storage on creation and destruction $storage = $this->getMock('IStorage'); $storage->expects($this->once())->method('read')->will($this->returnValue(array('name' => 'John Doe', 'age' => 41))); $storage->expects($this->once())->method('write')->with($this->equalTo('user'), $this->equalTo(array('name' => 'John Doe', 'age' => 41, 'city' => 'NY'))); $emitter = $this->getMock('IEventEmitter'); $emitter->expects($this->any())->method('notify'); // create the user, add attribute, delete the user $user = new User($storage, $emitter); $user->setProperty('city', 'NY'); $user->__destruct(); unset($user); }
/** * A common function which is used to save the userdata from the post-data. * @param panel - The panel for which to save data. * @return array - An array containing $error and $okmsg. */ function phorum_controlcenter_user_save($panel) { $PHORUM = $GLOBALS['PHORUM']; $error = ""; $okmsg = ""; // Setup the default userdata fields that may be changed // from the control panel interface. $userdata = array( 'signature' => NULL, 'hide_email' => NULL, 'hide_activity' => NULL, 'password' => NULL, 'tz_offset' => NULL, 'is_dst' => NULL, 'user_language' => NULL, 'threaded_list' => NULL, 'threaded_read' => NULL, 'email_notify' => NULL, 'show_signature' => NULL, 'pm_email_notify' => NULL, 'email' => NULL, 'email_temp' => NULL, 'user_template' => NULL, 'moderation_email'=> NULL, ); // Add custom profile fields as acceptable fields. foreach ($PHORUM["PROFILE_FIELDS"] as $field) { $userdata[$field["name"]] = NULL; } // Update userdata with $_POST information. foreach ($_POST as $key => $val) { if (array_key_exists($key, $userdata)) { $userdata[$key] = $val; } } // Remove unused profile fields. foreach ($userdata as $key => $val) { if (is_null($val)) { unset($userdata[$key]); } } // Set static userdata. $userdata["user_id"] = $PHORUM["user"]["user_id"]; $userdata["fk_campsite_user_id"] = $PHORUM["user"]["fk_campsite_user_id"]; // Run a hook, so module writers can update and check the userdata. $userdata = phorum_hook("cc_save_user", $userdata); // Set $error, in case the before_register hook did set an error. if (isset($userdata['error'])) { $error=$userdata['error']; unset($userdata['error']); // Try to update the userdata in the database. } elseif (!phorum_user_save($userdata)) { // Updating the user failed. $error = $PHORUM["DATA"]["LANG"]["ErrUserAddUpdate"]; } else { // Sync the campsite user require_once('../../admin-files/localizer/Localizer.php'); require_once('../../classes/User.php'); $campsiteUser = new User($userdata["fk_campsite_user_id"]); if ($campsiteUser->exists()) { if (array_key_exists('password', $userdata)) { $campsiteUser->setPassword($userdata["password"]); } elseif (array_key_exists('email', $userdata)) { $campsiteUser->setProperty('EMail', $userdata["email"]); } } // Updating the user was successful. $okmsg = $PHORUM["DATA"]["LANG"]["ProfileUpdatedOk"]; // Let the userdata be reloaded. phorum_user_set_current_user($userdata["user_id"]); // If a new password was set, let's create a new session. if (isset($userdata["password"]) && !empty($userdata["password"])) { phorum_user_create_session(); } // Copy data from the updated user back into the template data. // Leave PANEL and forum_id alone (these are injected into the // userdata in the template from this script). foreach ($GLOBALS["PHORUM"]["DATA"]["PROFILE"] as $key => $val) { if ($key == "PANEL" || $key == "forum_id") continue; if (isset($GLOBALS["PHORUM"]["user"][$key])) { $GLOBALS["PHORUM"]["DATA"]["PROFILE"][$key] = $GLOBALS["PHORUM"]["user"][$key]; } else { $GLOBALS["PHORUM"]["DATA"]["PROFILE"][$key] = ""; } } } return array($error, $okmsg); }
$editUser->setPassword($password); $liveUserValues['passwd'] = $password; } $userData = array( 'Name', 'Title', 'Gender', 'Age', 'EMail', 'City', 'StrAddress', 'State', 'CountryCode', 'Phone', 'Fax', 'Contact', 'Phone2', 'PostalCode', 'Employer', 'EmployerType', 'Position' ); // save user data foreach ($userData as $value) { $liveUserValues[$value] = Input::Get($value, 'string', null); $editUser->setProperty($value, $liveUserValues[$value], false); } $backLink = "/$ADMIN/users/edit.php?$typeParam&User="******"$1"', $editUser->getUserName()); Log::Message($logtext, $g_user->getUserId(), 56); // sync base data to the corresponding phorum user $isPhorumUser = Phorum_user::GetByUserName($editUser->getUserName());
/** * Performs the action; returns true on success, false on error. * * @param $p_context - the current context object * @return bool */ public function takeAction(CampContext &$p_context) { $p_context->default_url->reset_parameter('f_'.$this->m_name); $p_context->url->reset_parameter('f_'.$this->m_name); if (PEAR::isError($this->m_error)) { return false; } $metaUser = $p_context->user; if (!$metaUser->defined) { $this->m_properties['type'] = 'add'; if (!MetaAction::ValidateInput($this->m_properties, 'name', 1, $this->m_error, 'The user name was not filled in.', ACTION_EDIT_USER_ERR_NO_NAME)) { return false; } if (!MetaAction::ValidateInput($this->m_properties, 'uname', 1, $this->m_error, 'The user login name was not filled in.', ACTION_EDIT_USER_ERR_NO_USER_NAME)) { return false; } if (!MetaAction::ValidateInput($this->m_properties, 'password', 6, $this->m_error, 'The user password was not filled in or was too short.', ACTION_EDIT_USER_ERR_NO_PASSWORD)) { return false; } if (!MetaAction::ValidateInput($this->m_properties, 'passwordagain', 6, $this->m_error, 'The password confirmation was not filled in or was too short.', ACTION_EDIT_USER_ERR_NO_PASSWORD_CONFIRMATION)) { return false; } if (!MetaAction::ValidateInput($this->m_properties, 'email', 8, $this->m_error, 'The user email was not filled in or was invalid.', ACTION_EDIT_USER_ERR_NO_EMAIL)) { return false; } if (SystemPref::Get('PLUGIN_RECAPTCHA_SUBSCRIPTIONS_ENABLED') == 'Y') { $captcha = Captcha::factory('ReCAPTCHA'); if (!$captcha->validate()) { $this->m_error = new PEAR_Error('The code you entered is not the same as the one shown.', ACTION_SUBMIT_COMMENT_ERR_INVALID_CAPTCHA_CODE); return false; } } } else { $this->m_properties['type'] = 'edit'; if (isset($this->m_properties['password'])) { if (!MetaAction::ValidateInput($this->m_properties, 'password', 6, $this->m_error, 'The user password was not filled in or was too short.', ACTION_EDIT_USER_ERR_NO_PASSWORD)) { return false; } if (!MetaAction::ValidateInput($this->m_properties, 'passwordagain', 6, $this->m_error, 'The password confirmation was not filled in or was too short.', ACTION_EDIT_USER_ERR_NO_PASSWORD_CONFIRMATION)) { return false; } } } if (isset($this->m_properties['password']) && $this->m_properties['password'] != $this->m_properties['passwordagain']) { $this->m_error = new PEAR_Error("The password and password confirmation do not match.", ACTION_EDIT_USER_ERR_PASSWORD_MISMATCH); return false; } if (!$metaUser->defined) { if (User::UserNameExists($this->m_properties['uname']) || Phorum_user::UserNameExists($this->m_properties['uname'])) { $this->m_error = new PEAR_Error("The login name already exists, please choose a different one.", ACTION_EDIT_USER_ERR_DUPLICATE_USER_NAME); return false; } if (User::EmailExists($this->m_properties['email'])) { $this->m_error = new PEAR_Error("Another user is registered with this e-mail address, please choose a different one.", ACTION_EDIT_USER_ERR_DUPLICATE_EMAIL); return false; } $user = new User(); $phorumUser = new Phorum_user(); if (!$user->create($this->m_data) || !$phorumUser->create($this->m_properties['uname'], $this->m_properties['password'], $this->m_properties['email'], $user->getUserId())) { $user->delete(); $phorumUser->delete(); $this->m_error = new PEAR_Error("There was an internal error creating the account (code 1).", ACTION_EDIT_USER_ERR_INTERNAL); return false; } setcookie("LoginUserId", $user->getUserId(), null, '/'); $user->initLoginKey(); setcookie("LoginUserKey", $user->getKeyId(), null, '/'); $p_context->user = new MetaUser($user->getUserId()); } else { $user = new User($metaUser->identifier); if (!$user->exists()) { $this->m_error = new PEAR_Error("There was an internal error updating the account (code 2).", ACTION_EDIT_USER_ERR_INTERNAL); return false; } $phorumUser = Phorum_user::GetByUserName($user->getUserName()); if (is_null($phorumUser)) { $phorumUser = new Phorum_user(); if (!$phorumUser->create($user->getUserName(), $user->getPassword(), $user->getEmail(), $user->getUserId(), true)) { $this->m_error = new PEAR_Error("There was an internal error updating the account (code 3).", ACTION_EDIT_USER_ERR_INTERNAL); return false; } } foreach ($this->m_properties as $property=>$value) { if (!isset(MetaActionEdit_User::$m_fields[$property]['db_field'])) { continue; } $dbProperty = MetaActionEdit_User::$m_fields[$property]['db_field']; if ($property != 'password' && $property != 'passwordagain') { $user->setProperty($dbProperty, $value, false); if ($property == 'email') { $phorumUser->setProperty('email', $value, false); } } elseif ($property == 'password') { $user->setPassword($this->m_properties['password'], false); $phorumUser->setPassword($this->m_properties['password'], false); } } if (!$user->commit() || !$phorumUser->commit()) { $this->m_error = new PEAR_Error("There was an internal error updating the account (code 4).", ACTION_EDIT_USER_ERR_INTERNAL); return false; } } foreach ($this->m_properties as $property=>$value) { $p_context->default_url->reset_parameter('f_user_'.$property); $p_context->url->reset_parameter('f_user_'.$property); } $this->m_error = ACTION_OK; return true; }