function testUserCreateDelete() { $user = Phorum_user::GetByUserName('bob'); if ($user) { if (!$user->delete()) { $this->fail("Could not delete pre-existing user"); return; } } $user = new Phorum_user(); $user->create('bob', '*****@*****.**'); if (!$user->exists()) { $this->fail("Could not create user."); } if (!$user->delete()) { $this->fail("Could not delete user"); } }
/** * Create the first message for an article, which is a blank message * with the title of the article as the subject. * * @param Article $p_article * @param int $p_forumId * @return mixed * The comment created (or the one that already exists) on success, * or false on error. */ private function CreateFirstComment($p_article, $p_forumId) { // Check if the first post already exists. $articleNumber = $p_article->getArticleNumber(); $languageId = $p_article->getLanguageId(); $firstPost = ArticleComment::GetCommentThreadId($articleNumber, $languageId); if ($firstPost) { return new Phorum_message($firstPost); } // Get article creator $user = new User($p_article->getCreatorId()); if ($user->exists()) { $userId = $user->getUserId(); $userEmail = $user->getEmail(); $userPasswd = $user->getPassword(); $userName = $user->getUserName(); $userRealName = $user->getRealName(); // Create phorum user if necessary $phorumUser = Phorum_user::GetByUserName($userName); if (!is_object($phorumUser)) { $phorumUser = new Phorum_user(); } if (!$phorumUser->CampUserExists($userId) && !$phorumUser->create($userName, $userPasswd, $userEmail, $userId)) { return null; } } else { $userId = null; $userEmail = ''; $userRealName = ''; } // Create the comment. $title = $p_article->getTitle(); $commentObj = new Phorum_message(); if ($commentObj->create($p_forumId, $title, '', 0, 0, $userRealName, $userEmail, is_null($userId) ? 0 : $userId)) { // Link the message to the current article. ArticleComment::Link($articleNumber, $languageId, $commentObj->getMessageId(), true); return $commentObj; } else { return null; } } // method CreateFirstComment
$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()); if($isPhorumUser) { $editUser->syncPhorumUser(); } if ($editUser->isAdmin() && $customizeRights && $canManage) { $rightsFields = $editUser->GetDefaultConfig(); $permissions = array(); foreach ($rightsFields as $field=>$value) { $val = Input::Get($field, 'string', 'off'); $permissionEnabled = ($val == 'off') ? false : true; $permissions[$field] = $permissionEnabled; } } if ($editUser->isAdmin() && $customizeRights && $canManage) {
/** * Sync campsite and phorum users. */ public function syncPhorumUser() { $phorumUser = Phorum_user::GetByUserName($this->m_data['UName']); if ($phorumUser->setPassword($this->m_data['Password']) && $phorumUser->setEmail($this->m_data['EMail'])) { if (function_exists("camp_load_translation_strings")) { camp_load_translation_strings("api"); } $logtext = getGS('Base data synchronized to phorum user for "$1" ($2)', $this->m_data['Name'], $this->m_data['UName']); Log::Message($logtext, null, 161); } } // fn syncPhorumUser
camp_html_display_error(getGS('Invalid security token!')); exit; } read_user_common_parameters(); // $uType, $userOffs, $ItemsPerPage, search parameters verify_user_type(); compute_user_rights($g_user, $canManage, $canDelete); if (!$canDelete) { camp_html_display_error(getGS('You do not have the right to delete user accounts.')); exit; } $userId = Input::Get('User', 'int', 0); $editUser = new User($userId); if (!$editUser->exists()) { camp_html_display_error(getGS('No such user account.')); exit; } $uName = $editUser->getUserName(); $editUser->delete(); if ($phorumUser = Phorum_user::GetByUserName($uName)) { $phorumUser->delete(); } reset_user_search_parameters(); $typeParam = 'uType=' . urlencode($uType); camp_html_add_msg(getGS('User account $1 was deleted successfully.', $uName), "ok"); camp_html_goto_page("/$ADMIN/users/?$typeParam"); ?>
/** * 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; }