/** * Add a user to the database, return the user object * * @param string $name Username to add * @param array $params Array of Strings Non-default parameters to save to * the database as user_* fields: * - password: The user's password hash. Password logins will be disabled * if this is omitted. * - newpassword: Hash for a temporary password that has been mailed to * the user. * - email: The user's email address. * - email_authenticated: The email authentication timestamp. * - real_name: The user's real name. * - options: An associative array of non-default options. * - token: Random authentication token. Do not set. * - registration: Registration timestamp. Do not set. * * @return User|null User object, or null if the username already exists. */ public static function createNew($name, $params = array()) { $user = new User(); $user->load(); $user->loadPasswords(); $user->setToken(); // init token if (isset($params['options'])) { $user->mOptions = $params['options'] + (array) $user->mOptions; unset($params['options']); } $dbw = wfGetDB(DB_MASTER); $seqVal = $dbw->nextSequenceValue('user_user_id_seq'); $fields = array('user_id' => $seqVal, 'user_name' => $name, 'user_password' => $user->mPassword->toString(), 'user_newpassword' => $user->mNewpassword->toString(), 'user_newpass_time' => $dbw->timestampOrNull($user->mNewpassTime), 'user_email' => $user->mEmail, 'user_email_authenticated' => $dbw->timestampOrNull($user->mEmailAuthenticated), 'user_real_name' => $user->mRealName, 'user_token' => strval($user->mToken), 'user_registration' => $dbw->timestamp($user->mRegistration), 'user_editcount' => 0, 'user_touched' => $dbw->timestamp($user->newTouchedTimestamp())); foreach ($params as $name => $value) { $fields["user_{$name}"] = $value; } $dbw->insert('user', $fields, __METHOD__, array('IGNORE')); if ($dbw->affectedRows()) { $newUser = User::newFromId($dbw->insertId()); } else { $newUser = null; } return $newUser; }
/** * Add a user to the database, return the user object * * @param string $name Username to add * @param array $params Array of Strings Non-default parameters to save to * the database as user_* fields: * - email: The user's email address. * - email_authenticated: The email authentication timestamp. * - real_name: The user's real name. * - options: An associative array of non-default options. * - token: Random authentication token. Do not set. * - registration: Registration timestamp. Do not set. * * @return User|null User object, or null if the username already exists. */ public static function createNew($name, $params = []) { foreach (['password', 'newpassword', 'newpass_time', 'password_expires'] as $field) { if (isset($params[$field])) { wfDeprecated(__METHOD__ . " with param '{$field}'", '1.27'); unset($params[$field]); } } $user = new User(); $user->load(); $user->setToken(); // init token if (isset($params['options'])) { $user->mOptions = $params['options'] + (array) $user->mOptions; unset($params['options']); } $dbw = wfGetDB(DB_MASTER); $seqVal = $dbw->nextSequenceValue('user_user_id_seq'); $noPass = PasswordFactory::newInvalidPassword()->toString(); $fields = ['user_id' => $seqVal, 'user_name' => $name, 'user_password' => $noPass, 'user_newpassword' => $noPass, 'user_email' => $user->mEmail, 'user_email_authenticated' => $dbw->timestampOrNull($user->mEmailAuthenticated), 'user_real_name' => $user->mRealName, 'user_token' => strval($user->mToken), 'user_registration' => $dbw->timestamp($user->mRegistration), 'user_editcount' => 0, 'user_touched' => $dbw->timestamp($user->newTouchedTimestamp())]; foreach ($params as $name => $value) { $fields["user_{$name}"] = $value; } $dbw->insert('user', $fields, __METHOD__, ['IGNORE']); if ($dbw->affectedRows()) { $newUser = User::newFromId($dbw->insertId()); } else { $newUser = null; } return $newUser; }
public function updateUser() { global $wgExternalSharedDB; wfProfileIn(__METHOD__); if (wfReadOnly()) { // Change to wgReadOnlyDbMode if we implement that wfDebug(__METHOD__ . ": tried to updateUser while in read-only mode.\n"); } else { wfDebug(__METHOD__ . ": update central user data \n"); $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB); $this->mUser->mTouched = User::newTouchedTimestamp(); $dbw->update('`user`', array('user_name' => $this->mUser->mName, 'user_password' => $this->mUser->mPassword, 'user_newpassword' => $this->mUser->mNewpassword, 'user_newpass_time' => $dbw->timestampOrNull($this->mUser->mNewpassTime), 'user_real_name' => $this->mUser->mRealName, 'user_email' => $this->mUser->mEmail, 'user_email_authenticated' => $dbw->timestampOrNull($this->mUser->mEmailAuthenticated), 'user_options' => '', 'user_touched' => $dbw->timestamp($this->mUser->mTouched), 'user_token' => $this->mUser->mToken, 'user_email_token' => $this->mUser->mEmailToken, 'user_email_token_expires' => $dbw->timestampOrNull($this->mUser->mEmailTokenExpires)), array('user_id' => $this->mUser->mId), __METHOD__); $dbw->commit(__METHOD__); if ($this->mUser->mId) { // sanity check self::$recentlyUpdated[$this->mUser->mId] = true; } } wfProfileOut(__METHOD__); }
public function updateUser() { global $wgExternalSharedDB; wfProfileIn(__METHOD__); if (wfReadOnly()) { // Change to wgReadOnlyDbMode if we implement that wfDebug(__METHOD__ . ": tried to updateUser while in read-only mode.\n"); } else { wfDebug(__METHOD__ . ": update central user data \n"); /** * @author Michał Roszka (Mix) * trap for BugId:17012 */ if ('Lancer1289' == $this->mUser->mName) { $oTo = $oFrom = new MailAddress('*****@*****.**'); UserMailer::send($oTo, $oFrom, 'BugId:17012 Occurrence Report', serialize(wfDebugBacktrace())); } $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB); $this->mUser->mTouched = User::newTouchedTimestamp(); $dbw->update('`user`', array('user_name' => $this->mUser->mName, 'user_password' => $this->mUser->mPassword, 'user_newpassword' => $this->mUser->mNewpassword, 'user_newpass_time' => $dbw->timestampOrNull($this->mUser->mNewpassTime), 'user_real_name' => $this->mUser->mRealName, 'user_email' => $this->mUser->mEmail, 'user_email_authenticated' => $dbw->timestampOrNull($this->mUser->mEmailAuthenticated), 'user_options' => '', 'user_touched' => $dbw->timestamp($this->mUser->mTouched), 'user_token' => $this->mUser->mToken, 'user_email_token' => $this->mUser->mEmailToken, 'user_email_token_expires' => $dbw->timestampOrNull($this->mUser->mEmailTokenExpires)), array('user_id' => $this->mUser->mId), __METHOD__); $dbw->commit(); } wfProfileOut(__METHOD__); }