Example #1
0
 /**
  * @param $user User
  * @param $pass string
  * @param $newaddr string
  * @return bool|string true or string on success, false on failure
  */
 protected function attemptChange(User $user, $pass, $newaddr)
 {
     if ($newaddr != '' && !Sanitizer::validateEmail($newaddr)) {
         $this->error('invalidemailaddress');
         return false;
     }
     $throttleCount = LoginForm::incLoginThrottle($user->getName());
     if ($throttleCount === true) {
         $this->error('login-throttled');
         return false;
     }
     global $wgRequirePasswordforEmailChange;
     if ($wgRequirePasswordforEmailChange && !$user->checkTemporaryPassword($pass) && !$user->checkPassword($pass)) {
         $this->error('wrongpassword');
         return false;
     }
     if ($throttleCount) {
         LoginForm::clearLoginThrottle($user->getName());
     }
     $oldaddr = $user->getEmail();
     $status = $user->setEmailWithConfirmation($newaddr);
     if (!$status->isGood()) {
         $this->getOutput()->addHTML('<p class="error">' . $this->getOutput()->parseInline($status->getWikiText('mailerror')) . '</p>');
         return false;
     }
     wfRunHooks('PrefsEmailAudit', array($user, $oldaddr, $newaddr));
     $user->saveSettings();
     return $status->value;
 }
 /**
  * @param User $user
  * @param string $pass
  * @param string $newaddr
  * @return Status
  */
 private function attemptChange(User $user, $pass, $newaddr)
 {
     global $wgAuth;
     if ($newaddr != '' && !Sanitizer::validateEmail($newaddr)) {
         return Status::newFatal('invalidemailaddress');
     }
     $throttleCount = LoginForm::incLoginThrottle($user->getName());
     if ($throttleCount === true) {
         $lang = $this->getLanguage();
         $throttleInfo = $this->getConfig()->get('PasswordAttemptThrottle');
         return Status::newFatal('changeemail-throttled', $lang->formatDuration($throttleInfo['seconds']));
     }
     if ($this->getConfig()->get('RequirePasswordforEmailChange') && !$user->checkTemporaryPassword($pass) && !$user->checkPassword($pass)) {
         return Status::newFatal('wrongpassword');
     }
     if ($throttleCount) {
         LoginForm::clearLoginThrottle($user->getName());
     }
     $oldaddr = $user->getEmail();
     $status = $user->setEmailWithConfirmation($newaddr);
     if (!$status->isGood()) {
         return $status;
     }
     Hooks::run('PrefsEmailAudit', array($user, $oldaddr, $newaddr));
     $user->saveSettings();
     $wgAuth->updateExternalDB($user);
     return $status;
 }
Example #3
0
	/**
	 * Try to set a user's email address.
	 * This does *not* try to validate the address.
	 * Caller is responsible for checking $wgAuth and 'editmyprivateinfo'
	 * right.
	 *
	 * @deprecated in 1.20; use User::setEmailWithConfirmation() instead.
	 * @param $user User
	 * @param string $newaddr New email address
	 * @return Array (true on success or Status on failure, info string)
	 */
	public static function trySetUserEmail( User $user, $newaddr ) {
		wfDeprecated( __METHOD__, '1.20' );

		$result = $user->setEmailWithConfirmation( $newaddr );
		if ( $result->isGood() ) {
			return array( true, $result->value );
		} else {
			return array( $result, 'mailerror' );
		}
	}
 /**
  * @param User $user
  * @param string $newaddr
  * @return Status
  */
 private function attemptChange(User $user, $newaddr)
 {
     $authManager = AuthManager::singleton();
     if ($newaddr != '' && !Sanitizer::validateEmail($newaddr)) {
         return Status::newFatal('invalidemailaddress');
     }
     if ($newaddr === $user->getEmail()) {
         return Status::newFatal('changeemail-nochange');
     }
     $oldaddr = $user->getEmail();
     $status = $user->setEmailWithConfirmation($newaddr);
     if (!$status->isGood()) {
         return $status;
     }
     Hooks::run('PrefsEmailAudit', [$user, $oldaddr, $newaddr]);
     $user->saveSettings();
     MediaWiki\Auth\AuthManager::callLegacyAuthPlugin('updateExternalDB', [$user]);
     return $status;
 }