59 private $loadBalancer;
62 private $userOptionsLookup;
78 parent::__construct( $params );
80 if ( isset( $params[
'emailEnabled'] ) ) {
81 $this->emailEnabled = (bool)$params[
'emailEnabled'];
83 if ( isset( $params[
'newPasswordExpiry'] ) ) {
84 $this->newPasswordExpiry = (int)$params[
'newPasswordExpiry'];
86 if ( isset( $params[
'passwordReminderResendTime'] ) ) {
87 $this->passwordReminderResendTime = $params[
'passwordReminderResendTime'];
89 if ( isset( $params[
'allowRequiringEmailForResets'] ) ) {
90 $this->allowRequiringEmail = $params[
'allowRequiringEmailForResets'];
92 $this->loadBalancer = $loadBalancer;
93 $this->userOptionsLookup = $userOptionsLookup;
97 if ( $this->emailEnabled ===
null ) {
100 if ( $this->newPasswordExpiry ===
null ) {
103 if ( $this->passwordReminderResendTime ===
null ) {
104 $this->passwordReminderResendTime =
107 if ( $this->allowRequiringEmail ===
null ) {
108 $this->allowRequiringEmail =
116 'msg' =>
wfMessage(
'resetpass-temp-emailed' ),
130 if ( isset( $options[
'username'] ) && $this->emailEnabled ) {
149 if ( !$req || $req->username ===
null || $req->password ===
null ) {
153 $username = $this->userNameUtils->getCanonical(
154 $req->username, UserRigorOptions::RIGOR_USABLE );
155 if ( $username ===
false ) {
160 $row =
$dbr->selectRow(
163 'user_id',
'user_newpassword',
'user_newpass_time',
165 [
'user_name' => $username ],
173 if ( !$status->isOK() ) {
178 $pwhash = $this->
getPassword( $row->user_newpassword );
179 if ( !$pwhash->verify( $req->password ) ) {
190 $this->logger->info(
"{user} successfully logged in using temp password",
193 'requestIP' => $this->manager->getRequest()->getIP()
203 $username = $this->userNameUtils->getCanonical( $username, UserRigorOptions::RIGOR_USABLE );
204 if ( $username ===
false ) {
209 $row =
$dbr->selectRow(
211 [
'user_newpassword',
'user_newpass_time' ],
212 [
'user_name' => $username ],
231 $username = $this->userNameUtils->getCanonical( $username, UserRigorOptions::RIGOR_USABLE );
232 if ( $username ===
false ) {
236 list( $db, $options ) = \DBAccessObjectUtils::getDBOptions( $flags );
237 return (
bool)$this->loadBalancer->getConnectionRef( $db )->selectField(
240 [
'user_name' => $username ],
249 if ( get_class( $req ) !== TemporaryPasswordAuthenticationRequest::class ) {
251 return \StatusValue::newGood(
'ignored' );
255 return \StatusValue::newGood();
258 $username = $this->userNameUtils->getCanonical(
259 $req->username, UserRigorOptions::RIGOR_USABLE );
260 if ( $username ===
false ) {
261 return \StatusValue::newGood(
'ignored' );
264 $row = $this->loadBalancer->getConnectionRef(
DB_PRIMARY )->selectRow(
266 [
'user_id',
'user_newpass_time' ],
267 [
'user_name' => $username ],
272 return \StatusValue::newGood(
'ignored' );
275 $sv = \StatusValue::newGood();
276 if ( $req->password !==
null ) {
279 if ( $req->mailpassword ) {
280 if ( !$this->emailEnabled ) {
281 return \StatusValue::newFatal(
'passwordreset-emaildisabled' );
290 $this->passwordReminderResendTime
291 && $row->user_newpass_time
292 && time() < (
int)
wfTimestamp( TS_UNIX, $row->user_newpass_time )
293 + $this->passwordReminderResendTime * 3600
297 return \StatusValue::newFatal(
'throttled-mailpassword',
298 round( $this->passwordReminderResendTime, 3 ) );
301 if ( !$req->caller ) {
302 return \StatusValue::newFatal(
'passwordreset-nocaller' );
304 if ( !IPUtils::isValid( $req->caller ) ) {
307 return \StatusValue::newFatal(
'passwordreset-nosuchcaller', $req->caller );
316 $username = $req->username !==
null ?
317 $this->userNameUtils->getCanonical( $req->username, UserRigorOptions::RIGOR_USABLE ) :
false;
318 if ( $username ===
false ) {
322 $dbw = $this->loadBalancer->getConnectionRef(
DB_PRIMARY );
326 get_class( $req ) === TemporaryPasswordAuthenticationRequest::class
329 $newpassTime = $dbw->timestamp();
330 $sendMail = $req->mailpassword;
340 'user_newpassword' => $pwhash->toString(),
341 'user_newpass_time' => $newpassTime,
343 [
'user_name' => $username ],
349 $dbw->onTransactionCommitOrIdle(
350 function () use ( $req ) {
366 $reqs, TemporaryPasswordAuthenticationRequest::class
369 $ret = \StatusValue::newGood();
371 if ( $req->mailpassword ) {
372 if ( !$this->emailEnabled ) {
373 $ret->merge( \StatusValue::newFatal(
'emaildisabled' ) );
374 } elseif ( !$user->getEmail() ) {
375 $ret->merge( \StatusValue::newFatal(
'noemailcreate' ) );
389 $reqs, TemporaryPasswordAuthenticationRequest::class
391 if ( $req && $req->username !==
null && $req->password !==
null ) {
393 if ( $req->username !== $user->getName() ) {
395 $req->username = $user->getName();
398 if ( $req->mailpassword ) {
400 $this->manager->setAuthenticationSessionData(
'no-email',
true );
404 $ret->createRequest = $req;
412 $req =
$res->createRequest;
413 $mailpassword = $req->mailpassword;
414 $req->mailpassword =
false;
419 if ( $mailpassword ) {
421 $this->loadBalancer->getConnectionRef(
DB_PRIMARY )->onTransactionCommitOrIdle(
422 function () use ( $user, $creator, $req ) {
429 return $mailpassword ?
'byemail' :
null;
439 if ( $time !==
null ) {
441 if ( time() >= $expiry ) {
459 return \Status::newFatal(
'badipaddress' );
463 $this->
getHookRunner()->onUser__mailPasswordInternal( $creatingUser, $ip, $user );
465 $mainPageUrl = \Title::newMainPage()->getCanonicalURL();
466 $userLanguage = $this->userOptionsLookup->getOption( $user,
'language' );
467 $subjectMessage =
wfMessage(
'createaccount-title' )->inLanguage( $userLanguage );
468 $bodyMessage =
wfMessage(
'createaccount-text', $ip, $user->
getName(), $password,
469 '<' . $mainPageUrl .
'>', round( $this->newPasswordExpiry / 86400 ) )
470 ->inLanguage( $userLanguage );
472 $status = $user->
sendMail( $subjectMessage->text(), $bodyMessage->text() );
476 if ( !$status->isGood() ) {
477 $this->logger->warning(
'Could not send account creation email: ' .
478 $status->getWikiText(
false,
false,
'en' ) );
492 return \Status::newFatal(
'noname' );
494 $userLanguage = $this->userOptionsLookup->getOption( $user,
'language' );
495 $callerIsAnon = IPUtils::isValid( $req->caller );
496 $callerName = $callerIsAnon ? $req->caller :
User::newFromName( $req->caller )->getName();
497 $passwordMessage =
wfMessage(
'passwordreset-emailelement', $user->getName(),
498 $req->password )->inLanguage( $userLanguage );
499 $emailMessage =
wfMessage( $callerIsAnon ?
'passwordreset-emailtext-ip'
500 :
'passwordreset-emailtext-user' )->inLanguage( $userLanguage );
501 $body = $emailMessage->params( $callerName, $passwordMessage->text(), 1,
502 '<' . \Title::newMainPage()->getCanonicalURL() .
'>',
503 round( $this->newPasswordExpiry / 86400 ) )->text();
505 if ( $this->allowRequiringEmail && !$this->userOptionsLookup
506 ->getBoolOption( $user,
'requireemail' )
511 $body .=
wfMessage(
'passwordreset-emailtext-require-email' )
512 ->inLanguage( $userLanguage )
517 $emailTitle =
wfMessage(
'passwordreset-emailtitle' )->inLanguage( $userLanguage );
518 return $user->sendMail( $emailTitle->text(), $body );
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Represents an invalid password hash.
A class containing constants representing the names of configuration variables.
const PasswordReminderResendTime
Name constant for the PasswordReminderResendTime setting, for use with Config::get()
const EnableEmail
Name constant for the EnableEmail setting, for use with Config::get()
const NewPasswordExpiry
Name constant for the NewPasswordExpiry setting, for use with Config::get()
const AllowRequiringEmailForResets
Name constant for the AllowRequiringEmailForResets setting, for use with Config::get()
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getRequest()
Get the WebRequest object to use with this object.
getName()
Get the user name, or the IP of an anonymous user.
static newFromName( $name, $validate='valid')
sendMail( $subject, $body, $from=null, $replyto=null)
Send an e-mail to this user's account.