57 parent::__construct( $params );
59 if ( isset( $params[
'emailEnabled'] ) ) {
60 $this->emailEnabled = (bool)$params[
'emailEnabled'];
62 if ( isset( $params[
'newPasswordExpiry'] ) ) {
63 $this->newPasswordExpiry = (int)$params[
'newPasswordExpiry'];
65 if ( isset( $params[
'passwordReminderResendTime'] ) ) {
66 $this->passwordReminderResendTime = $params[
'passwordReminderResendTime'];
73 if ( $this->emailEnabled ===
null ) {
74 $this->emailEnabled = $this->config->get(
'EnableEmail' );
76 if ( $this->newPasswordExpiry ===
null ) {
77 $this->newPasswordExpiry = $this->config->get(
'NewPasswordExpiry' );
79 if ( $this->passwordReminderResendTime ===
null ) {
80 $this->passwordReminderResendTime = $this->config->get(
'PasswordReminderResendTime' );
87 'msg' =>
wfMessage(
'resetpass-temp-emailed' ),
101 if ( isset( $options[
'username'] ) && $this->emailEnabled ) {
120 if ( !$req || $req->username ===
null || $req->password ===
null ) {
125 if ( $username ===
false ) {
130 $row =
$dbr->selectRow(
133 'user_id',
'user_newpassword',
'user_newpass_time',
135 [
'user_name' => $username ],
148 $pwhash = $this->
getPassword( $row->user_newpassword );
149 if ( !$pwhash->verify( $req->password ) ) {
160 $this->logger->info(
"{user} successfully logged in using temp password",
163 'requestIP' => $this->manager->getRequest()->getIP()
174 if ( $username ===
false ) {
179 $row =
$dbr->selectRow(
181 [
'user_newpassword',
'user_newpass_time' ],
182 [
'user_name' => $username ],
202 if ( $username ===
false ) {
207 return (
bool)
wfGetDB( $db )->selectField(
210 [
'user_name' => $username ],
219 if ( get_class( $req ) !== TemporaryPasswordAuthenticationRequest::class ) {
221 return \StatusValue::newGood(
'ignored' );
225 return \StatusValue::newGood();
229 if ( $username ===
false ) {
230 return \StatusValue::newGood(
'ignored' );
235 [
'user_id',
'user_newpass_time' ],
236 [
'user_name' => $username ],
241 return \StatusValue::newGood(
'ignored' );
245 if ( $req->password !==
null ) {
248 if ( $req->mailpassword ) {
249 if ( !$this->emailEnabled ) {
250 return \StatusValue::newFatal(
'passwordreset-emaildisabled' );
259 $this->passwordReminderResendTime
260 && $row->user_newpass_time
261 && time() <
wfTimestamp( TS_UNIX, $row->user_newpass_time )
262 + $this->passwordReminderResendTime * 3600
266 return \StatusValue::newFatal(
'throttled-mailpassword',
267 round( $this->passwordReminderResendTime, 3 ) );
270 if ( !$req->caller ) {
271 return \StatusValue::newFatal(
'passwordreset-nocaller' );
276 return \StatusValue::newFatal(
'passwordreset-nosuchcaller', $req->caller );
286 if ( $username ===
false ) {
294 get_class( $req ) === TemporaryPasswordAuthenticationRequest::class
297 $newpassTime = $dbw->timestamp();
298 $sendMail = $req->mailpassword;
308 'user_newpassword' => $pwhash->toString(),
309 'user_newpass_time' => $newpassTime,
311 [
'user_name' => $username ],
317 $dbw->onTransactionCommitOrIdle(
318 function () use ( $req ) {
334 $reqs, TemporaryPasswordAuthenticationRequest::class
339 if ( $req->mailpassword ) {
340 if ( !$this->emailEnabled ) {
342 } elseif ( !$user->getEmail() ) {
357 $reqs, TemporaryPasswordAuthenticationRequest::class
359 if ( $req && $req->username !==
null && $req->password !==
null ) {
361 if ( $req->username !== $user->getName() ) {
363 $req->username = $user->getName();
366 if ( $req->mailpassword ) {
368 $this->manager->setAuthenticationSessionData(
'no-email',
true );
372 $ret->createRequest = $req;
380 $req =
$res->createRequest;
381 $mailpassword = $req->mailpassword;
382 $req->mailpassword =
false;
387 if ( $mailpassword ) {
390 function () use ( $user, $creator, $req ) {
397 return $mailpassword ?
'byemail' :
null;
407 if ( $time !==
null ) {
409 if ( time() >= $expiry ) {
427 return \Status::newFatal(
'badipaddress' );
431 \Hooks::run(
'User::mailPasswordInternal', [ &$creatingUser, &$ip, &$user ] );
434 $userLanguage = $user->
getOption(
'language' );
435 $subjectMessage =
wfMessage(
'createaccount-title' )->inLanguage( $userLanguage );
436 $bodyMessage =
wfMessage(
'createaccount-text', $ip, $user->
getName(), $password,
437 '<' . $mainPageUrl .
'>', round( $this->newPasswordExpiry / 86400 ) )
438 ->inLanguage( $userLanguage );
440 $status = $user->
sendMail( $subjectMessage->text(), $bodyMessage->text() );
445 $this->logger->warning(
'Could not send account creation email: ' .
446 $status->getWikiText(
false,
false,
'en' ) );
460 return \Status::newFatal(
'noname' );
462 $userLanguage = $user->getOption(
'language' );
464 $callerName = $callerIsAnon ? $req->caller :
User::newFromName( $req->caller )->getName();
465 $passwordMessage =
wfMessage(
'passwordreset-emailelement', $user->getName(),
466 $req->password )->inLanguage( $userLanguage );
467 $emailMessage =
wfMessage( $callerIsAnon ?
'passwordreset-emailtext-ip'
468 :
'passwordreset-emailtext-user' )->inLanguage( $userLanguage );
469 $emailMessage->params( $callerName, $passwordMessage->text(), 1,
471 round( $this->newPasswordExpiry / 86400 ) );
472 $emailTitle =
wfMessage(
'passwordreset-emailtitle' )->inLanguage( $userLanguage );
473 return $user->sendMail( $emailTitle->text(), $emailMessage->text() );