62 parent::__construct( $params );
64 if ( isset( $params[
'emailEnabled'] ) ) {
65 $this->emailEnabled = (bool)$params[
'emailEnabled'];
67 if ( isset( $params[
'newPasswordExpiry'] ) ) {
68 $this->newPasswordExpiry = (int)$params[
'newPasswordExpiry'];
70 if ( isset( $params[
'passwordReminderResendTime'] ) ) {
71 $this->passwordReminderResendTime = $params[
'passwordReminderResendTime'];
73 if ( isset( $params[
'allowRequiringEmailForResets'] ) ) {
74 $this->allowRequiringEmail = $params[
'allowRequiringEmailForResets'];
81 if ( $this->emailEnabled ===
null ) {
82 $this->emailEnabled = $this->config->get(
'EnableEmail' );
84 if ( $this->newPasswordExpiry ===
null ) {
85 $this->newPasswordExpiry = $this->config->get(
'NewPasswordExpiry' );
87 if ( $this->passwordReminderResendTime ===
null ) {
88 $this->passwordReminderResendTime = $this->config->get(
'PasswordReminderResendTime' );
90 if ( $this->allowRequiringEmail ===
null ) {
91 $this->allowRequiringEmail = $this->config->get(
'AllowRequiringEmailForResets' );
98 'msg' =>
wfMessage(
'resetpass-temp-emailed' ),
112 if ( isset( $options[
'username'] ) && $this->emailEnabled ) {
131 if ( !$req || $req->username ===
null || $req->password ===
null ) {
136 if ( $username ===
false ) {
141 $row =
$dbr->selectRow(
144 'user_id',
'user_newpassword',
'user_newpass_time',
146 [
'user_name' => $username ],
154 if ( !$status->isOK() ) {
159 $pwhash = $this->
getPassword( $row->user_newpassword );
160 if ( !$pwhash->verify( $req->password ) ) {
171 $this->logger->info(
"{user} successfully logged in using temp password",
174 'requestIP' => $this->manager->getRequest()->getIP()
185 if ( $username ===
false ) {
190 $row =
$dbr->selectRow(
192 [
'user_newpassword',
'user_newpass_time' ],
193 [
'user_name' => $username ],
213 if ( $username ===
false ) {
217 list( $db, $options ) = \DBAccessObjectUtils::getDBOptions( $flags );
218 return (
bool)
wfGetDB( $db )->selectField(
221 [
'user_name' => $username ],
230 if ( get_class( $req ) !== TemporaryPasswordAuthenticationRequest::class ) {
232 return \StatusValue::newGood(
'ignored' );
236 return \StatusValue::newGood();
240 if ( $username ===
false ) {
241 return \StatusValue::newGood(
'ignored' );
246 [
'user_id',
'user_newpass_time' ],
247 [
'user_name' => $username ],
252 return \StatusValue::newGood(
'ignored' );
255 $sv = \StatusValue::newGood();
256 if ( $req->password !==
null ) {
259 if ( $req->mailpassword ) {
260 if ( !$this->emailEnabled ) {
261 return \StatusValue::newFatal(
'passwordreset-emaildisabled' );
270 $this->passwordReminderResendTime
271 && $row->user_newpass_time
272 && time() < (
int)
wfTimestamp( TS_UNIX, $row->user_newpass_time )
273 + $this->passwordReminderResendTime * 3600
277 return \StatusValue::newFatal(
'throttled-mailpassword',
278 round( $this->passwordReminderResendTime, 3 ) );
281 if ( !$req->caller ) {
282 return \StatusValue::newFatal(
'passwordreset-nocaller' );
284 if ( !IPUtils::isValid( $req->caller ) ) {
287 return \StatusValue::newFatal(
'passwordreset-nosuchcaller', $req->caller );
297 if ( $username ===
false ) {
305 get_class( $req ) === TemporaryPasswordAuthenticationRequest::class
308 $newpassTime = $dbw->timestamp();
309 $sendMail = $req->mailpassword;
319 'user_newpassword' => $pwhash->toString(),
320 'user_newpass_time' => $newpassTime,
322 [
'user_name' => $username ],
328 $dbw->onTransactionCommitOrIdle(
329 function () use ( $req ) {
345 $reqs, TemporaryPasswordAuthenticationRequest::class
348 $ret = \StatusValue::newGood();
350 if ( $req->mailpassword ) {
351 if ( !$this->emailEnabled ) {
352 $ret->merge( \StatusValue::newFatal(
'emaildisabled' ) );
353 } elseif ( !$user->getEmail() ) {
354 $ret->merge( \StatusValue::newFatal(
'noemailcreate' ) );
368 $reqs, TemporaryPasswordAuthenticationRequest::class
370 if ( $req && $req->username !==
null && $req->password !==
null ) {
372 if ( $req->username !== $user->getName() ) {
374 $req->username = $user->getName();
377 if ( $req->mailpassword ) {
379 $this->manager->setAuthenticationSessionData(
'no-email',
true );
383 $ret->createRequest = $req;
391 $req =
$res->createRequest;
392 $mailpassword = $req->mailpassword;
393 $req->mailpassword =
false;
398 if ( $mailpassword ) {
401 function () use ( $user, $creator, $req ) {
408 return $mailpassword ?
'byemail' :
null;
418 if ( $time !==
null ) {
420 if ( time() >= $expiry ) {
438 return \Status::newFatal(
'badipaddress' );
442 $this->
getHookRunner()->onUser__mailPasswordInternal( $creatingUser, $ip, $user );
444 $mainPageUrl = \Title::newMainPage()->getCanonicalURL();
445 $userLanguage = $user->
getOption(
'language' );
446 $subjectMessage =
wfMessage(
'createaccount-title' )->inLanguage( $userLanguage );
447 $bodyMessage =
wfMessage(
'createaccount-text', $ip, $user->
getName(), $password,
448 '<' . $mainPageUrl .
'>', round( $this->newPasswordExpiry / 86400 ) )
449 ->inLanguage( $userLanguage );
451 $status = $user->
sendMail( $subjectMessage->text(), $bodyMessage->text() );
455 if ( !$status->isGood() ) {
456 $this->logger->warning(
'Could not send account creation email: ' .
457 $status->getWikiText(
false,
false,
'en' ) );
471 return \Status::newFatal(
'noname' );
473 $userLanguage = $user->getOption(
'language' );
474 $callerIsAnon = IPUtils::isValid( $req->caller );
475 $callerName = $callerIsAnon ? $req->caller :
User::newFromName( $req->caller )->getName();
476 $passwordMessage =
wfMessage(
'passwordreset-emailelement', $user->getName(),
477 $req->password )->inLanguage( $userLanguage );
478 $emailMessage =
wfMessage( $callerIsAnon ?
'passwordreset-emailtext-ip'
479 :
'passwordreset-emailtext-user' )->inLanguage( $userLanguage );
480 $body = $emailMessage->params( $callerName, $passwordMessage->text(), 1,
481 '<' . \Title::newMainPage()->getCanonicalURL() .
'>',
482 round( $this->newPasswordExpiry / 86400 ) )->text();
484 if ( $this->allowRequiringEmail && !$user->getBoolOption(
'requireemail' ) ) {
488 $body .=
wfMessage(
'passwordreset-emailtext-require-email' )
489 ->inLanguage( $userLanguage )
494 $emailTitle =
wfMessage(
'passwordreset-emailtitle' )->inLanguage( $userLanguage );
495 return $user->sendMail( $emailTitle->text(), $body );
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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.
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,...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
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')
Static factory method for creation from username.
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user's current setting for a given option.
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.
sendMail( $subject, $body, $from=null, $replyto=null)
Send an e-mail to this user's account.
Interface for configuration instances.