static function createTemporaryUser($real_name, $email) { $user = new User(); $maxid = User::getMaxID(); $anonid = $maxid + 1; $username = "******"; $user->setName($username); $real_name = strip_tags($real_name); // make sure this hasn't already been created while ($user->idForName() > 0) { $anonid = rand(0, 100000); $username = "******"; $user->setName($username); } if ($real_name) { $user->setRealName($real_name); } else { $user->setRealName("Anonymous"); } if ($email) { $user->setEmail($email); } $user->setPassword(WH_ANON_USER_PASSWORD); $user->setOption("disablemail", 1); $user->addToDatabase(); return $user; }
/** * @param string $realname * @return bool */ private function setRealName($realname) { if ($this->user->getRealName() !== $realname) { $this->user->setRealName($realname); return true; } return false; }
/** * @dataProvider providePopulateUser * @param string $email Email to set * @param string $realname Realname to set * @param StatusValue $expect Expected return */ public function testPopulateUser($email, $realname, $expect) { $user = new \User(); $user->setEmail('*****@*****.**'); $user->setRealName('Fake Name'); $req = new UserDataAuthenticationRequest(); $req->email = $email; $req->realname = $realname; $this->assertEquals($expect, $req->populateUser($user)); if ($expect->isOk()) { $this->assertSame($email ?: '*****@*****.**', $user->getEmail()); $this->assertSame($realname ?: 'Fake Name', $user->getRealName()); } }
/** * Do all the synchronization between an ldap result and a Tuleap user. * * This method returns if it modified the user or not. This is usefull during * batch process in order to limit computing. * * @param User $user User * @param LDAPResult $lr Ldap result * * @return Boolean True if the method modified the user object */ public function sync(User $user, LDAPResult $lr) { $modified = false; $ldapEmail = $lr->getEmail(); $realname = ucwords(preg_replace('/^(\\w+).(\\w+)@.*/', '\\1 \\2', $ldapEmail)); if ($realname !== null && $user->getRealName() != substr($realname, 0, 32)) { $user->setRealName($realname); $modified = true; } if ($ldapEmail !== null && $user->getEmail() != $ldapEmail) { $user->setEmail($ldapEmail); $modified = true; } return $modified; }
public static function createFromResponse(\SimpleXMLElement $response) { $user = new User(); $user->setName((string) $response->name); $user->setRealName((string) $response->realname); $user->setUrl((string) $response->url); $user->setWeight((int) $response->weight); $images = array(); foreach ($response->image as $image) { $imageAttributes = $image->attributes(); if (!empty($imageAttributes->size)) { $images[(string) $imageAttributes->size] = (string) $image; } } $user->setImages($images); return $user; }
/** * Actually add a user to the database. * Give it a User object that has been initialised with a name. * * @param User $u * @param bool $autocreate True if this is an autocreation via auth plugin * @return Status Status object, with the User object in the value member on success * @private */ function initUser($u, $autocreate) { global $wgAuth; $status = $u->addToDatabase(); if (!$status->isOK()) { return $status; } if ($wgAuth->allowPasswordChange()) { $u->setPassword($this->mPassword); } $u->setEmail($this->mEmail); $u->setRealName($this->mRealName); $u->setToken(); $wgAuth->initUser($u, $autocreate); $u->saveSettings(); // Update user count DeferredUpdates::addUpdate(new SiteStatsUpdate(0, 0, 0, 0, 1)); // Watch user's userpage and talk page $u->addWatch($u->getUserPage(), WatchedItem::IGNORE_USER_RIGHTS); return Status::newGood($u); }
/** * Actually add a user to the database. * Give it a User object that has been initialised with a name. * * @param User $u * @param bool $autocreate True if this is an autocreation via auth plugin * @return Status Status object, with the User object in the value member on success * @private */ function initUser($u, $autocreate) { global $wgAuth; $status = $u->addToDatabase(); if (!$status->isOK()) { return $status; } if ($wgAuth->allowPasswordChange()) { $u->setPassword($this->mPassword); } $u->setEmail($this->mEmail); $u->setRealName($this->mRealName); $u->setToken(); Hooks::run('LocalUserCreated', array($u, $autocreate)); $oldUser = $u; $wgAuth->initUser($u, $autocreate); if ($oldUser !== $u) { wfWarn(get_class($wgAuth) . '::initUser() replaced the user object'); } $u->saveSettings(); // Update user count DeferredUpdates::addUpdate(new SiteStatsUpdate(0, 0, 0, 0, 1)); // Watch user's userpage and talk page $u->addWatch($u->getUserPage(), WatchedItem::IGNORE_USER_RIGHTS); return Status::newGood($u); }
/** * When a user logs in, optionally fill in preferences and such. * For instance, you might pull the email address or real name from the * external user database. * * The User object is passed by reference so it can be modified; don't * forget the & on your function declaration. * * @param User $user * @public */ public function updateUser(&$user) { global $smf_settings, $smf_member_id; // No id, you must be unauthorized. if ($smf_member_id == 0) { return false; } $username = $this->fixUsername($user->getName()); $request = $this->query("\n\t\t\tSELECT email_address, real_name\n\t\t\tFROM {$smf_settings['db_prefix']}members\n\t\t\tWHERE id_member = '{$smf_member_id}'\n\t\t\tLIMIT 1"); while ($row = mysql_fetch_assoc($request)) { $user->setRealName($row['real_name']); $user->setEmail($row['email_address']); $this->setAdminGroup($user); $user->setOption('smf_last_update', time()); $user->saveSettings(); } mysql_free_result($request); return true; }
/** * When a user logs in, update user with information from LDAP. * * @param User $user * @access public * TODO: fix the setExternalID stuff */ function updateUser(&$user) { global $wgLDAPRetrievePrefs, $wgLDAPPreferences; global $wgLDAPUseLDAPGroups; global $wgLDAPUniqueBlockLogin, $wgLDAPUniqueRenameUser; $this->printDebug("Entering updateUser", NONSENSITIVE); if ($this->authFailed) { $this->printDebug("User didn't successfully authenticate, exiting.", NONSENSITIVE); return; } $saveSettings = false; //If we aren't pulling preferences, we don't want to accidentally //overwrite anything. if (isset($wgLDAPRetrievePrefs[$_SESSION['wsDomain']]) && $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] || isset($wgLDAPPreferences[$_SESSION['wsDomain']])) { $this->printDebug("Setting user preferences.", NONSENSITIVE); if ('' != $this->lang) { $this->printDebug("Setting language.", NONSENSITIVE); $user->setOption('language', $this->lang); } if ('' != $this->nickname) { $this->printDebug("Setting nickname.", NONSENSITIVE); $user->setOption('nickname', $this->nickname); } if ('' != $this->realname) { $this->printDebug("Setting realname.", NONSENSITIVE); $user->setRealName($this->realname); } if ('' != $this->email) { $this->printDebug("Setting email.", NONSENSITIVE); $user->setEmail($this->email); $user->confirmEmail(); } if (isset($wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']]) && $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] || isset($wgLDAPUniqueRenameUser[$_SESSION['wsDomain']]) && $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']]) { if ('' != $this->externalid) { $user->setExternalID($this->externalid); } } $saveSettings = true; } if (isset($wgLDAPUseLDAPGroups[$_SESSION['wsDomain']]) && $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']]) { $this->printDebug("Setting user groups.", NONSENSITIVE); $this->setGroups($user); $saveSettings = true; } if ($saveSettings) { $this->printDebug("Saving user settings.", NONSENSITIVE); $user->saveSettings(); } }
/** * Create user account based on LDAP info. * * @param String $eduid * @param String $uid * @param String $cn * @param String $email * @return User */ function createAccount($eduid, $uid, $cn, $email) { if (trim($uid) == '' || trim($eduid) == '') { return false; } $user = new User(); $user->setUserName($this->generateLogin($uid)); $user->setLdapId($eduid); $user->setRealName($cn); $user->setEmail($email); // Generates a pseudo-random password. Its not full secure but its // better than nothing. $user->setPassword(md5((string) mt_rand(10000, 999999) . time())); // Default LDAP $user->setStatus($this->getLdap()->getLDAPParam('default_user_status')); $user->setRegisterPurpose('LDAP'); $user->setUnixStatus('S'); $user->setTimezone('GMT'); $user->setLanguageID($GLOBALS['Language']->getText('conf', 'language_id')); $um = $this->getUserManager(); $u = $um->createAccount($user); if ($u) { // Create an entry in the ldap user db $ldapUserDao = $this->getDao(); $ldapUserDao->createLdapUser($u->getId(), 0, $uid); return $u; } return false; }
function doPOST() { global $wgUser, $wgAuth; switch ($this->action) { default: throw new InvalidPOSTParamException(wfMsg('uadm-formsubmissionerrormsg')); case 'emailwelcomepreview': $this->pwdaction = 'emailwelcome'; $newParams = array('preview' => 'welcome') + $this->mParams; $newParams = array_intersect_key($newParams, $this->getParamsGET()); return $this->getURL($newParams); case 'adduser': break; } $this->validatePOSTParams(); if ($this->domain != 'local' && $this->domain != '') { if (!$wgAuth->canCreateAccounts()) { return $this->getPOSTRedirectURL(false, wfMsg('uadm-createextacctfailmsg')); } } $logRights = new LogPage('rights'); $user = new User(); $user->setName($wgAuth->getCanonicalName($this->username)); $user->setRealName($this->realname); $user->setEmail($this->email); $successWikiText = array(); $successWikiText[] = wfMsg('uadm-newusersuccessmsg', $this->username); $userPassword = ''; switch ($this->pwdaction) { case 'manual': try { $user->setPassword($this->password1); $userPassword = $this->password1; } catch (PasswordError $pe) { return $this->getPOSTRedirectURL(false, wfMsg('uadm-passworderrormsg') . $pe->getText()); } $successWikiText[] = wfMsg('uadm-passwordchangesuccessmsg', $this->username); break; case 'emailwelcome': $result = self::mailWelcomeAndPassword($user); if ($result->isGood()) { return $this->getPOSTRedirectURL(false, wfMsg('uadm-mailerror', $result->getMessage())); } $successWikiText[] = wfMsg('uadm-welcomeemailsuccessmsg', $this->username, $this->email); break; } $user->setToken(); $wgAuth->initUser($user, false); $abortError = ''; if (!wfRunHooks('AbortNewAccount', array($user, &$abortError))) { return $this->getPOSTRedirectURL(false, wfMsg('uadm-hookblocknewusermsg', $abortError)); } if (!$wgAuth->addUser($user, $userPassword, $this->email, $this->realname)) { return $this->getPOSTRedirectURL(false, wfMsg('uadm-wgauthaddfailmsg', $abortError)); } $user->addToDatabase(); $user->addNewUserLogEntry(); if (count($this->groups) > 0) { $userrightsPage = new UserrightsPage(); $userrightsPage->doSaveUserGroups($user, $this->groups, array(), $this->newuserreasonmsg); wfRunHooks('UserRights', array($user, $add, $remove)); $successWikiText[] = wfMsg('uadm-changestogroupsuccessmsg', $this->username); } $successWikiText = implode('<br/>', $successWikiText); wfRunHooks('AddNewAccount', array($user, true)); $ssUpdate = new SiteStatsUpdate(0, 0, 0, 0, 1); $ssUpdate->doUpdate(); # password log entry switch ($this->pwdaction) { case 'manual': $logRights->addEntry('uadm-changeduserpasswordlog', $user->getUserPage(), $this->newuserreasonmsg, array()); break; case 'emailwelcome': $logRights->addEntry('uadm-emailwelcomelog', $user->getUserPage(), $this->newuserreasonmsg, array()); break; } // Redirect to EditUser special page instead of AddUser to allow editing of // user just added return $this->getSpecialPageURL('EditUser', $this->username, array('statusmsg' => base64_encode($successWikiText), 'statusok' => true, 'returnto' => $this->returnto)); }
function getDocentsForCategory($title) { $html = ""; $results = array(); $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select(array('docentcategories', 'user'), array('user_id', 'user_name', 'user_real_name'), array('dc_user=user_id', 'dc_to' => $title->getDBKey())); while ($row = $dbr->fetchObject($res)) { $u = new User(); $u->setName($row->user_name); $u->setRealName($row->user_real_name); $results[] = $u; } $html = "<div id='docents'>"; if (sizeof($results) > 0) { $html .= "<h2><span id='docent_header'>" . wfMsg('docents') . "</span></h2><p>\n"; $first = true; foreach ($results as $u) { $display = $u->getRealName() == "" ? $u->getName() : $u->getRealName(); if ($first) { $first = false; } else { $html .= "<strong>•</strong>"; } $html .= " <a href='" . $u->getUserPage()->getFullURL() . "'>{$display}</a>\n"; } $html .= "</p>"; } else { $html .= "<h2><span id='docent_header'>" . wfMsg('docents') . "</span></h2><p>\n"; $html .= wfMsg('no_docents'); } $html .= "<div id='become_docent'><span>+</span>" . wfMsg('become_a_docent') . "</div></div>"; return $html; }
/** * Set users' fields from SAML attributes. * If the user does not exist in the MediaWiki database, * it is created. wgSamlCreateUser is not respected. * * @param User $user the user * @param string[][] $attr SAML attributes */ protected static function updateUser(User $user, $attr) { global $wgSamlRealnameAttr; global $wgSamlUsernameAttr; global $wgSamlMailAttr; global $wgContLang; $changed = false; if (isset($wgSamlRealnameAttr) && isset($attr[$wgSamlRealnameAttr]) && $attr[$wgSamlRealnameAttr] && $user->getRealName() !== reset($attr[$wgSamlRealnameAttr])) { $changed = true; $user->setRealName(reset($attr[$wgSamlRealnameAttr])); } if ($attr[$wgSamlMailAttr] && $user->getEmail() !== reset($attr[$wgSamlMailAttr])) { $changed = true; $user->setEmail(reset($attr[$wgSamlMailAttr])); $user->ConfirmEmail(); } if (!$user->getId()) { $user->setName($wgContLang->ucfirst(reset($attr[$wgSamlUsernameAttr]))); $user->setPassword(null); // prevent manual login until reset $user->addToDatabase(); } elseif ($changed) { $user->saveSettings(); } }
/** * Clears the user's password, sets an empty e-mail and marks as disabled * * @param User $user User account to close * @param string $changeReason Reason for change * @param string $mStatusMsg Main error message * @param string $mStatusMsg2 Secondary (non-critical) error message * @param boolean $keepEmail Optionally keep the email address in a * user option * @return boolean true on success, false on failure */ public static function closeAccount($user = '', $changeReason = '', &$mStatusMsg = '', &$mStatusMsg2 = '', $keepEmail = true) { if (empty($user)) { throw new Exception('User object is invalid.'); } $id = $user->getId(); # Set flag for Special:Contributions # NOTE: requires FlagClosedAccounts.php to be included separately if (defined('CLOSED_ACCOUNT_FLAG')) { $user->setRealName(CLOSED_ACCOUNT_FLAG); } else { # magic value not found, so lets at least blank it $user->setRealName(''); } // remove users avatar if (class_exists('Masthead')) { $avatar = Masthead::newFromUser($user); if (!$avatar->isDefault()) { if (!$avatar->removeFile(false)) { # dont quit here, since the avatar is a non-critical part of closing, but flag for later $mStatusMsg2 = wfMessage('editaccount-remove-avatar-fail')->plain(); } } } // close account and invalidate cache + cluster data Wikia::invalidateUser($user, true, $keepEmail, true); // if they are connected from facebook, disconnect them self::disconnectFromFacebook($user); if ($user->getEmail() == '') { $title = Title::newFromText('EditAccount', NS_SPECIAL); // Log what was done $log = new LogPage('editaccnt'); $log->addEntry('closeaccnt', $title, $changeReason, array($user->getUserPage())); // All clear! $mStatusMsg = wfMessage('editaccount-success-close', $user->mName)->plain(); wfRunHooks('EditAccountClosed', array($user)); return true; } else { // There were errors...inform the user about those $mStatusMsg = wfMessage('editaccount-error-close', $user->mName)->plain(); return false; } }
/** * When a user logs in, optionally fill in preferences and such. * For instance, you might pull the email address or real name from the * external user database. * * The User object is passed by reference so it can be modified; don't * forget the & on your function declaration. * * @param User $user * @access public */ function updateUser(&$user) { if (!is_resource($this->db)) { $this->openDB(); } $query = mysql_query("SELECT username,email,usergroup,additionalgroups FROM {$this->table_prefix}users WHERE username='******'", $this->db); $res = mysql_fetch_array($query); if ($res) { if (in_array($res['usergroup'], $this->admin_usergroups)) { $is_admin = true; } $memberships = explode(",", $res['additionalgroups']); for ($i = 0; $i < count($memberships); $i++) { if (in_array($memberships[$x], $this->admin_usergroups)) { $is_admin = true; } } if ($is_admin == true) { // If a user is not a sysop, make them a sysop if (!in_array("sysop", $user->getEffectiveGroups())) { $user->addGroup('sysop'); } } else { if (in_array("sysop", $user->getEffectiveGroups())) { $user->removeGroup('sysop'); return TRUE; } } $user->setEmail($res['email']); $user->setRealName($res['username']); return TRUE; } return false; }
/** * When creating a user account, initialize user with information from LDAP. * * @param User $user * @access public */ function initUser(&$user) { global $LDAPUseLDAPGroups; $this->printDebug("Entering initUser", 1); if ('local' == $_SESSION['LDAPDomain']) { $this->printDebug("User is using a local domain", 1); return; } //We are creating an LDAP user, it is very important that we do //NOT set a local password because it could compromise the //security of our domain. $user->mPassword = ''; if (isset($LDAPRetrievePrefs[$_SESSION['LDAPDomain']]) && $LDAPRetrievePrefs[$_SESSION['LDAPDomain']]) { if ('' != $this->lang) { $user->setOption('language', $this->lang); } if ('' != $this->nickname) { $user->setOption('nickname', $this->nickname); } if ('' != $this->realname) { $user->setRealName($this->realname); } if ('' != $this->email) { $user->setEmail($this->email); } } if (isset($LDAPUseLDAPGroups[$_SESSION['LDAPDomain']]) && $LDAPUseLDAPGroups[$_SESSION['LDAPDomain']]) { $this->setGroups($user); } $user->saveSettings(); }
function account_create($loginname = '', $pw = '', $ldap_id = '', $realname = '', $register_purpose = '', $email = '', $status = 'P', $confirm_hash = '', $mail_site = 0, $mail_va = 0, $timezone = 'GMT', $lang_id = 'en_US', $unix_status = 'N', $expiry_date = 0) { $um = UserManager::instance(); $user = new User(); $user->setUserName($loginname); $user->setRealName($realname); $user->setPassword($pw); $user->setLdapId($ldap_id); $user->setRegisterPurpose($register_purpose); $user->setEmail($email); $user->setStatus($status); $user->setConfirmHash($confirm_hash); $user->setMailSiteUpdates($mail_site); $user->setMailVA($mail_va); $user->setTimezone($timezone); $user->setLanguageID($lang_id); $user->setUnixStatus($unix_status); $user->setExpiryDate($expiry_date); $u = $um->createAccount($user); if ($u) { return $u->getId(); } else { return $u; } }
/** * When a user logs in, optionally fill in preferences and such. * For instance, you might pull the email address or real name from the * external user database. * * The User object is passed by reference so it can be modified; don't * forget the & on your function declaration. * * @param User $user * @public */ function updateUser(&$user) { if ($this->debug) { echo 'updateUser'; } $username = addslashes($user->getName()); $find_user_query = "SELECT\n\t\t\tuser_id,\n\t\t\tuser_accesslevel, user_email, \n\t\t\tuser_name_short, user_name\n\t\t\tFROM users WHERE lower(user_name_short)=lower('{$username}')"; $find_result = mysql_query($find_user_query, $this->database); // make sure that there is only one person with the username if (mysql_num_rows($find_result) == 1) { $userinfo = mysql_fetch_assoc($find_result); mysql_free_result($find_result); $user->setEmail($userinfo['user_email']); $user->confirmEmail(); $user->setRealName($userinfo['user_name']); // Accessrights if ($userinfo['user_accesslevel'] > 2) { $user->addGroup('sysop'); } $user->saveSettings(); return true; } return false; }
/** * When creating a user account, optionally fill in preferences and such. * For instance, you might pull the email address or real name from the * external user database. * * The User object is passed by reference so it can be modified; don't * forget the & on your function declaration. * * @param User $user * @access public */ function initUser(&$user) { global $G_SESSION; //unless you want the person to be nameless, you should probably populate // info about this user here if (isset($G_SESSION)) { $user->setRealName($G_SESSION->getRealName()); $user->setEmail($G_SESSION->getEmail()); } $user->mEmailAuthenticated = wfTimestampNow(); $user->setToken(); //turn on e-mail notifications by default $user->setOption('enotifwatchlistpages', 1); $user->setOption('enotifusertalkpages', 1); $user->setOption('enotifminoredits', 1); $user->setOption('enotifrevealaddr', 1); }
/** * When creating a user account, optionally fill in preferences and such. * For instance, you might pull the email address or real name from the * external user database. * * The User object is passed by reference so it can be modified; don't * forget the & on your function declaration. * * @param User $user * @access public */ function initUser(&$user) { //We are creating an LDAP user, it is very important that we do //NOT set a local password because it could compromise the //security of our domain. if ('local' == $_SESSION['wsDomain']) { return; } $user->setPassword(''); if ('' != $this->lang) { $user->setOption('language', $this->lang); } if ('' != $this->nickname) { $user->setOption('nickname', $this->nickname); } if ('' != $this->realname) { $user->setRealName($this->realname); } if ('' != $this->email) { $user->setEmail($this->email); } }
/** * Do all the synchronization between an ldap result and a Codendi user. * * This method returns if it modified the user or not. This is usefull during * batch process in order to limit computing. * * @param User $user Codendi user * @param LDAPResult $lr Ldap result * * @return Boolean True if the method modified the user object */ public function sync(User $user, LDAPResult $lr) { $modified = false; if ($lr->getCommonName() !== null && $user->getRealName() != substr($lr->getCommonName(), 0, 32)) { $user->setRealName($lr->getCommonName()); $modified = true; } if ($lr->getEmail() !== null && $user->getEmail() != $lr->getEmail()) { $user->setEmail($lr->getEmail()); $modified = true; } return $modified; }
/** * Updates the user's details according to what was given from the SSO * library. * Note that this will be called every time after authenticating * to the IdP. * * @param User $user * User object from MW * @param Array $attrs * Attribute array */ private function modifyUserIfNeeded(&$user, $attrs) { $username = $user->getName(); $dirty = false; /* * Email */ if (isset($attrs['email'])) { $new = $attrs['email']; $old = $user->getEmail(); if ($new != $old) { $user->setEmail($new); $user->confirmEmail(); wfDebugLog('MultiAuthPlugin', __METHOD__ . ': ' . "Updated email for user '{$username}' from '{$old}' to '{$new}'"); $dirty = true; } } /* * Fullname */ if (isset($attrs['fullname'])) { $new = $attrs['fullname']; $old = $user->getRealName(); if ($new != $old) { $user->setRealName($new); wfDebugLog('MultiAuthPlugin', __METHOD__ . ': ' . "Updated realName for user '{$username}' from '{$old}' to '{$new}'"); $dirty = true; } } if ($dirty) { $user->saveSettings(); } }
/** * Actually add a user to the database. * Give it a User object that has been initialised with a name. * * @param User $u * @return User * @access private */ function &initUser(&$u) { $u->addToDatabase(); $u->setPassword($this->mPassword); $u->setEmail($this->mEmail); $u->setRealName($this->mRealName); $u->setToken(); global $wgAuth; $wgAuth->initUser($u); if ($this->mRemember) { $r = 1; } else { $r = 0; } $u->setOption('rememberpassword', $r); return $u; }