* Much more easier to find it in the User class than in Preferences and it's general enough to be in that class.
* Rewrote the function for better readbility
* It now always return a Status object so that it's easier to interpret its result.
* Update the only caller in core (in Special:ChangeEmail) and moved the PrefsEmailAdit hook there
Change-Id: I55939bb5295e73594c3fdf7287dddbc16a233ce4
* @return Array (true on success or Status on failure, info string)
*/
public static function trySetUserEmail( User $user, $newaddr ) {
- global $wgEnableEmail, $wgEmailAuthentication;
- $info = ''; // none
+ wfDeprecated( __METHOD__, '1.20' );
- if ( $wgEnableEmail ) {
- $oldaddr = $user->getEmail();
- if ( ( $newaddr != '' ) && ( $newaddr != $oldaddr ) ) {
- # The user has supplied a new email address on the login page
- # new behaviour: set this new emailaddr from login-page into user database record
- $user->setEmail( $newaddr );
- if ( $wgEmailAuthentication ) {
- # Mail a temporary password to the dirty address.
- # User can come back through the confirmation URL to re-enable email.
- $type = $oldaddr != '' ? 'changed' : 'set';
- $result = $user->sendConfirmationMail( $type );
- if ( !$result->isGood() ) {
- return array( $result, 'mailerror' );
- }
- $info = 'eauth';
- }
- } elseif ( $newaddr != $oldaddr ) { // if the address is the same, don't change it
- $user->setEmail( $newaddr );
- }
- if ( $oldaddr != $newaddr ) {
- wfRunHooks( 'PrefsEmailAudit', array( $user, $oldaddr, $newaddr ) );
- }
+ $result = $user->setEmailWithConfirmation( $newaddr );
+ if ( $result->isGood() ) {
+ return array( true, $result->value );
+ } else {
+ return array( $result, 'mailerror' );
}
-
- return array( true, $info );
}
/**
wfRunHooks( 'UserSetEmail', array( $this, &$this->mEmail ) );
}
+ /**
+ * Set the user's e-mail address and a confirmation mail if needed.
+ *
+ * @param $str String New e-mail address
+ * @return Status
+ */
+ public function setEmailWithConfirmation( $str ) {
+ global $wgEnableEmail, $wgEmailAuthentication;
+
+ if ( !$wgEnableEmail ) {
+ return Status::newFatal( 'emaildisabled' );
+ }
+
+ $oldaddr = $this->getEmail();
+ if ( $str === $oldaddr ) {
+ return Status::newGood( true );
+ }
+
+ $this->setEmail( $str );
+
+ if ( $str !== '' && $wgEmailAuthentication ) {
+ # Send a confirmation request to the new address if needed
+ $type = $oldaddr != '' ? 'changed' : 'set';
+ $result = $this->sendConfirmationMail( $type );
+ if ( $result->isGood() ) {
+ # Say the the caller that a confirmation mail has been sent
+ $status->value = 'eauth';
+ }
+ } else {
+ $result = Status::newGood( true );
+ }
+
+ return $result;
+ }
+
/**
* Get the user's real name
* @return String User's real name
LoginForm::clearLoginThrottle( $user->getName() );
}
- list( $status, $info ) = Preferences::trySetUserEmail( $user, $newaddr );
- if ( $status !== true ) {
- if ( $status instanceof Status ) {
- $this->getOutput()->addHTML(
- '<p class="error">' .
- $this->getOutput()->parseInline( $status->getWikiText( $info ) ) .
- '</p>' );
- }
+ $oldaddr = $user->getEmail();
+ $status = $user->setEmailWithConfirmation( $newaddr );
+ if ( !$status->isGood() ) {
+ $this->getOutput()->addHTML(
+ '<p class="error">' .
+ $this->getOutput()->parseInline( $status->getWikiText( $info ) ) .
+ '</p>' );
return false;
}
+ wfRunHooks( 'PrefsEmailAudit', array( $user, $oldaddr, $newaddr ) );
+
$user->saveSettings();
- return $info ? $info : true;
+
+ return $status->value;
}
}
'invalidemailaddress' => 'The e-mail address cannot be accepted as it appears to have an invalid format.
Please enter a well-formatted address or empty that field.',
'cannotchangeemail' => 'Account e-mail addresses cannot be changed on this wiki.',
+'emaildisabled' => 'E-mails are disabled on this site.',
'accountcreated' => 'Account created',
'accountcreatedtext' => 'The user account for $1 has been created.',
'createaccount-title' => 'Account creation for {{SITENAME}}',
'emailconfirmlink',
'invalidemailaddress',
'cannotchangeemail',
+ 'emaildisabled',
'accountcreated',
'accountcreatedtext',
'createaccount-title',