public function execute() { if (!$this->hasAnyRoutes()) { $this->dieUsage('No password reset routes are available.', 'moduledisabled'); } $params = $this->extractRequestParams() + ['user' => null, 'email' => null]; $this->requireOnlyOneParameter($params, 'user', 'email'); $passwordReset = new PasswordReset($this->getConfig(), AuthManager::singleton()); $status = $passwordReset->isAllowed($this->getUser(), $params['capture']); if (!$status->isOK()) { $this->dieStatus(Status::wrap($status)); } $status = $passwordReset->execute($this->getUser(), $params['user'], $params['email'], $params['capture']); if (!$status->isOK()) { $status->value = null; $this->dieStatus(Status::wrap($status)); } $result = $this->getResult(); $result->addValue(['resetpassword'], 'status', 'success'); if ($params['capture']) { $passwords = $status->getValue() ?: []; ApiResult::setArrayType($passwords, 'kvp', 'user'); ApiResult::setIndexedTagName($passwords, 'p'); $result->addValue(['resetpassword'], 'passwords', $passwords); } }
public static function getByStatus($status) { global $db; $sql = "SELECT * FROM statuses WHERE LOWER(status)=?"; $values = array(strtolower($status)); $stat = $db->qwv($sql, $values); return Status::wrap($stat); }
/** * Show the success page. * * @param string $type Condition of return to; see `executeReturnTo` * @param string|Message $title Page's title * @param string $msgname * @param string $injected_html * @param StatusValue|null $extraMessages */ protected function showSuccessPage($type, $title, $msgname, $injected_html, $extraMessages) { $out = $this->getOutput(); $out->setPageTitle($title); if ($msgname) { $out->addWikiMsg($msgname, wfEscapeWikiText($this->getUser()->getName())); } if ($extraMessages) { $extraMessages = Status::wrap($extraMessages); $out->addWikiText($extraMessages->getWikiText()); } $out->addHTML($injected_html); $helper = new LoginHelper($this->getContext()); $helper->showReturnToPage($type, $this->mReturnTo, $this->mReturnToQuery, $this->mStickHTTPS); }
/** * Display the form. * @param false|Status|StatusValue $status A form submit status, as in HTMLForm::trySubmit() */ protected function displayForm($status) { if ($status instanceof StatusValue) { $status = Status::wrap($status); } $form = $this->getAuthForm($this->authRequests, $this->authAction); $form->prepareForm()->displayForm($status); }
public static function provideAllowsAuthenticationDataChange() { $ignored = \Status::newGood('ignored'); $ignored->warning('authmanager-change-not-supported'); $okFromPrimary = StatusValue::newGood(); $okFromPrimary->warning('warning-from-primary'); $okFromSecondary = StatusValue::newGood(); $okFromSecondary->warning('warning-from-secondary'); return [[StatusValue::newGood(), StatusValue::newGood(), \Status::newGood()], [StatusValue::newGood(), StatusValue::newGood('ignore'), \Status::newGood()], [StatusValue::newGood('ignored'), StatusValue::newGood(), \Status::newGood()], [StatusValue::newGood('ignored'), StatusValue::newGood('ignored'), $ignored], [StatusValue::newFatal('fail from primary'), StatusValue::newGood(), \Status::newFatal('fail from primary')], [$okFromPrimary, StatusValue::newGood(), \Status::wrap($okFromPrimary)], [StatusValue::newGood(), StatusValue::newFatal('fail from secondary'), \Status::newFatal('fail from secondary')], [StatusValue::newGood(), $okFromSecondary, \Status::wrap($okFromSecondary)]]; }
public static function provideProviderAllowsAuthenticationDataChange() { $err = \StatusValue::newGood(); $err->error('arbitrary-warning'); return [[AuthenticationRequest::class, 'UTSysop', \Status::newGood(), \StatusValue::newGood('ignored'), \StatusValue::newGood('ignored')], [PasswordAuthenticationRequest::class, 'UTSysop', \Status::newGood(), \StatusValue::newGood('ignored'), \StatusValue::newGood('ignored')], [TemporaryPasswordAuthenticationRequest::class, 'UTSysop', \Status::newGood(), \StatusValue::newGood(), \StatusValue::newGood()], [TemporaryPasswordAuthenticationRequest::class, 'uTSysop', \Status::newGood(), \StatusValue::newGood(), \StatusValue::newGood()], [TemporaryPasswordAuthenticationRequest::class, 'UTSysop', \Status::wrap($err), \StatusValue::newGood(), $err], [TemporaryPasswordAuthenticationRequest::class, 'UTSysop', \Status::newFatal('arbitrary-error'), \StatusValue::newGood(), \StatusValue::newFatal('arbitrary-error')], [TemporaryPasswordAuthenticationRequest::class, 'DoesNotExist', \Status::newGood(), \StatusValue::newGood(), \StatusValue::newGood('ignored')], [TemporaryPasswordAuthenticationRequest::class, '<invalid>', \Status::newGood(), \StatusValue::newGood(), \StatusValue::newGood('ignored')]]; }
/** * Process the form. At this point we know that the user passes all the criteria in * userCanExecute(), and if the data array contains 'Username', etc, then Username * resets are allowed. * @param array $data * @throws MWException * @throws ThrottledError|PermissionsError * @return Status */ public function onSubmit(array $data) { if (isset($data['Capture']) && !$this->getUser()->isAllowed('passwordreset')) { // The user knows they don't have the passwordreset permission, // but they tried to spoof the form. That's naughty throw new PermissionsError('passwordreset'); } $username = isset($data['Username']) ? $data['Username'] : null; $email = isset($data['Email']) ? $data['Email'] : null; $capture = !empty($data['Capture']); $this->method = $username ? 'username' : 'email'; $this->result = Status::wrap($this->passwordReset->execute($this->getUser(), $username, $email, $capture)); if ($capture && $this->result->isOK()) { $this->passwords = $this->result->getValue(); } if ($this->result->hasMessage('actionthrottledtext')) { throw new ThrottledError(); } return $this->result; }