69 parent::__construct( $params );
71 if ( isset( $params[
'emailEnabled'] ) ) {
72 $this->emailEnabled = (bool)$params[
'emailEnabled'];
74 if ( isset( $params[
'newPasswordExpiry'] ) ) {
75 $this->newPasswordExpiry = (int)$params[
'newPasswordExpiry'];
77 if ( isset( $params[
'passwordReminderResendTime'] ) ) {
78 $this->passwordReminderResendTime = $params[
'passwordReminderResendTime'];
80 if ( isset( $params[
'allowRequiringEmailForResets'] ) ) {
81 $this->allowRequiringEmail = $params[
'allowRequiringEmailForResets'];
87 if ( $this->emailEnabled ===
null ) {
88 $this->emailEnabled = $this->config->get(
'EnableEmail' );
90 if ( $this->newPasswordExpiry ===
null ) {
91 $this->newPasswordExpiry = $this->config->get(
'NewPasswordExpiry' );
93 if ( $this->passwordReminderResendTime ===
null ) {
94 $this->passwordReminderResendTime = $this->config->get(
'PasswordReminderResendTime' );
96 if ( $this->allowRequiringEmail ===
null ) {
97 $this->allowRequiringEmail = $this->config->get(
'AllowRequiringEmailForResets' );
104 'msg' =>
wfMessage(
'resetpass-temp-emailed' ),
118 if ( isset( $options[
'username'] ) && $this->emailEnabled ) {
137 if ( !$req || $req->username ===
null || $req->password ===
null ) {
141 $username = $this->userNameUtils->getCanonical( $req->username, UserNameUtils::RIGOR_USABLE );
142 if ( $username ===
false ) {
147 $row =
$dbr->selectRow(
150 'user_id',
'user_newpassword',
'user_newpass_time',
152 [
'user_name' => $username ],
160 if ( !$status->isOK() ) {
165 $pwhash = $this->
getPassword( $row->user_newpassword );
166 if ( !$pwhash->verify( $req->password ) ) {
177 $this->logger->info(
"{user} successfully logged in using temp password",
180 'requestIP' => $this->manager->getRequest()->getIP()
190 $username = $this->userNameUtils->getCanonical( $username, UserNameUtils::RIGOR_USABLE );
191 if ( $username ===
false ) {
196 $row =
$dbr->selectRow(
198 [
'user_newpassword',
'user_newpass_time' ],
199 [
'user_name' => $username ],
218 $username = $this->userNameUtils->getCanonical( $username, UserNameUtils::RIGOR_USABLE );
219 if ( $username ===
false ) {
223 list( $db, $options ) = \DBAccessObjectUtils::getDBOptions( $flags );
224 return (
bool)$this->loadBalancer->getConnectionRef( $db )->selectField(
227 [
'user_name' => $username ],
236 if ( get_class( $req ) !== TemporaryPasswordAuthenticationRequest::class ) {
238 return \StatusValue::newGood(
'ignored' );
242 return \StatusValue::newGood();
245 $username = $this->userNameUtils->getCanonical( $req->username, UserNameUtils::RIGOR_USABLE );
246 if ( $username ===
false ) {
247 return \StatusValue::newGood(
'ignored' );
250 $row = $this->loadBalancer->getConnectionRef(
DB_PRIMARY )->selectRow(
252 [
'user_id',
'user_newpass_time' ],
253 [
'user_name' => $username ],
258 return \StatusValue::newGood(
'ignored' );
261 $sv = \StatusValue::newGood();
262 if ( $req->password !==
null ) {
265 if ( $req->mailpassword ) {
266 if ( !$this->emailEnabled ) {
267 return \StatusValue::newFatal(
'passwordreset-emaildisabled' );
276 $this->passwordReminderResendTime
277 && $row->user_newpass_time
278 && time() < (
int)
wfTimestamp( TS_UNIX, $row->user_newpass_time )
279 + $this->passwordReminderResendTime * 3600
283 return \StatusValue::newFatal(
'throttled-mailpassword',
284 round( $this->passwordReminderResendTime, 3 ) );
287 if ( !$req->caller ) {
288 return \StatusValue::newFatal(
'passwordreset-nocaller' );
290 if ( !IPUtils::isValid( $req->caller ) ) {
293 return \StatusValue::newFatal(
'passwordreset-nosuchcaller', $req->caller );
302 $username = $req->username !==
null ?
303 $this->userNameUtils->getCanonical( $req->username, UserNameUtils::RIGOR_USABLE ) :
false;
304 if ( $username ===
false ) {
308 $dbw = $this->loadBalancer->getConnectionRef(
DB_PRIMARY );
312 get_class( $req ) === TemporaryPasswordAuthenticationRequest::class
315 $newpassTime = $dbw->timestamp();
316 $sendMail = $req->mailpassword;
326 'user_newpassword' => $pwhash->toString(),
327 'user_newpass_time' => $newpassTime,
329 [
'user_name' => $username ],
335 $dbw->onTransactionCommitOrIdle(
336 function () use ( $req ) {
352 $reqs, TemporaryPasswordAuthenticationRequest::class
355 $ret = \StatusValue::newGood();
357 if ( $req->mailpassword ) {
358 if ( !$this->emailEnabled ) {
359 $ret->merge( \StatusValue::newFatal(
'emaildisabled' ) );
360 } elseif ( !$user->getEmail() ) {
361 $ret->merge( \StatusValue::newFatal(
'noemailcreate' ) );
375 $reqs, TemporaryPasswordAuthenticationRequest::class
377 if ( $req && $req->username !==
null && $req->password !==
null ) {
379 if ( $req->username !== $user->getName() ) {
381 $req->username = $user->getName();
384 if ( $req->mailpassword ) {
386 $this->manager->setAuthenticationSessionData(
'no-email',
true );
390 $ret->createRequest = $req;
398 $req =
$res->createRequest;
399 $mailpassword = $req->mailpassword;
400 $req->mailpassword =
false;
405 if ( $mailpassword ) {
407 $this->loadBalancer->getConnectionRef(
DB_PRIMARY )->onTransactionCommitOrIdle(
408 function () use ( $user, $creator, $req ) {
415 return $mailpassword ?
'byemail' :
null;
425 if ( $time !==
null ) {
427 if ( time() >= $expiry ) {
445 return \Status::newFatal(
'badipaddress' );
449 $this->
getHookRunner()->onUser__mailPasswordInternal( $creatingUser, $ip, $user );
451 $mainPageUrl = \Title::newMainPage()->getCanonicalURL();
452 $userLanguage = $user->
getOption(
'language' );
453 $subjectMessage =
wfMessage(
'createaccount-title' )->inLanguage( $userLanguage );
454 $bodyMessage =
wfMessage(
'createaccount-text', $ip, $user->
getName(), $password,
455 '<' . $mainPageUrl .
'>', round( $this->newPasswordExpiry / 86400 ) )
456 ->inLanguage( $userLanguage );
458 $status = $user->
sendMail( $subjectMessage->text(), $bodyMessage->text() );
462 if ( !$status->isGood() ) {
463 $this->logger->warning(
'Could not send account creation email: ' .
464 $status->getWikiText(
false,
false,
'en' ) );
478 return \Status::newFatal(
'noname' );
480 $userLanguage = $user->getOption(
'language' );
481 $callerIsAnon = IPUtils::isValid( $req->caller );
482 $callerName = $callerIsAnon ? $req->caller :
User::newFromName( $req->caller )->getName();
483 $passwordMessage =
wfMessage(
'passwordreset-emailelement', $user->getName(),
484 $req->password )->inLanguage( $userLanguage );
485 $emailMessage =
wfMessage( $callerIsAnon ?
'passwordreset-emailtext-ip'
486 :
'passwordreset-emailtext-user' )->inLanguage( $userLanguage );
487 $body = $emailMessage->params( $callerName, $passwordMessage->text(), 1,
488 '<' . \Title::newMainPage()->getCanonicalURL() .
'>',
489 round( $this->newPasswordExpiry / 86400 ) )->text();
492 ->getBoolOption( $user,
'requireemail' )
497 $body .=
wfMessage(
'passwordreset-emailtext-require-email' )
498 ->inLanguage( $userLanguage )
503 $emailTitle =
wfMessage(
'passwordreset-emailtitle' )->inLanguage( $userLanguage );
504 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.
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')
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user's current setting for a given option.
sendMail( $subject, $body, $from=null, $replyto=null)
Send an e-mail to this user's account.