Example #1
0
 /**
  * Given a user object, this method will create a temporary password and save it to the
  * user's account.  Every time this is called, the reset password throttle is reset, which
  * means the method User::isPasswordReminderThrottled will return true for the next
  * $wgPasswordReminderResendTime hours
  *
  * @param User $targetUser
  *
  * @return String
  *
  * @throws MWException
  */
 public function resetPassword(User $targetUser)
 {
     $context = RequestContext::getMain();
     $currentUser = $context->getUser();
     $currentIp = $context->getRequest()->getIP();
     wfRunHooks('User::mailPasswordInternal', [$currentUser, $currentIp, $targetUser]);
     $tempPass = $targetUser->randomPassword();
     $targetUser->setNewpassword($tempPass, $resetThrottle = true);
     $targetUser->saveSettings();
     return $tempPass;
 }
 /**
  * @param User $u
  * @param bool $throttle
  * @param string $emailTitle Message name of email title
  * @param string $emailText Message name of email text
  * @return Status
  */
 function mailPasswordInternal($u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext')
 {
     global $wgNewPasswordExpiry;
     if ($u->getEmail() == '') {
         return Status::newFatal('noemail', $u->getName());
     }
     $ip = $this->getRequest()->getIP();
     if (!$ip) {
         return Status::newFatal('badipaddress');
     }
     $currentUser = $this->getUser();
     Hooks::run('User::mailPasswordInternal', array(&$currentUser, &$ip, &$u));
     $np = $u->randomPassword();
     $u->setNewpassword($np, $throttle);
     $u->saveSettings();
     $userLanguage = $u->getOption('language');
     $mainPage = Title::newMainPage();
     $mainPageUrl = $mainPage->getCanonicalURL();
     $m = $this->msg($emailText, $ip, $u->getName(), $np, '<' . $mainPageUrl . '>', round($wgNewPasswordExpiry / 86400))->inLanguage($userLanguage)->text();
     $result = $u->sendMail($this->msg($emailTitle)->inLanguage($userLanguage)->text(), $m);
     return $result;
 }