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 ],
143 if ( !$status->isOK() ) {
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 ) {
206 list( $db, $options ) = \DBAccessObjectUtils::getDBOptions( $flags );
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' );
244 $sv = \StatusValue::newGood();
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' );
273 if ( !\IP::isValid( $req->caller ) ) {
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
337 $ret = \StatusValue::newGood();
339 if ( $req->mailpassword ) {
340 if ( !$this->emailEnabled ) {
341 $ret->merge( \StatusValue::newFatal(
'emaildisabled' ) );
342 } elseif ( !$user->getEmail() ) {
343 $ret->merge( \StatusValue::newFatal(
'noemailcreate' ) );
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 ] );
433 $mainPageUrl = \Title::newMainPage()->getCanonicalURL();
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() );
444 if ( !$status->isGood() ) {
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' );
463 $callerIsAnon = \IP::isValid( $req->caller );
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,
470 '<' . \Title::newMainPage()->getCanonicalURL() .
'>',
471 round( $this->newPasswordExpiry / 86400 ) );
472 $emailTitle =
wfMessage(
'passwordreset-emailtitle' )->inLanguage( $userLanguage );
473 return $user->sendMail( $emailTitle->text(), $emailMessage->text() );
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.
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.