X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiLogin.php;h=02aae06e808170c2a912bb2fb54b8f9c691362c3;hb=5360a3497f31ce5af167746bf33375da5f32e061;hp=03cd666e7e4c02cc205b2eb03855b435bf3cc26b;hpb=829b2e7d0169ba977cec42df6ee83eb60de51045;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index 03cd666e7e..02aae06e80 100644 --- a/includes/api/ApiLogin.php +++ b/includes/api/ApiLogin.php @@ -51,17 +51,17 @@ class ApiLogin extends ApiBase { // If we're in a mode that breaks the same-origin policy, no tokens can // be obtained if ( $this->lacksSameOriginSecurity() ) { - $this->getResult()->addValue( null, 'login', array( + $this->getResult()->addValue( null, 'login', [ 'result' => 'Aborted', 'reason' => 'Cannot log in when the same-origin policy is not applied', - ) ); + ] ); return; } $params = $this->extractRequestParams(); - $result = array(); + $result = []; // Make sure session is persisted $session = MediaWiki\Session\SessionManager::getGlobalSession(); @@ -69,11 +69,11 @@ class ApiLogin extends ApiBase { // Make sure it's possible to log in if ( !$session->canSetUser() ) { - $this->getResult()->addValue( null, 'login', array( + $this->getResult()->addValue( null, 'login', [ 'result' => 'Aborted', 'reason' => 'Cannot log in when using ' . $session->getProvider()->describe( Language::factory( 'en' ) ), - ) ); + ] ); return; } @@ -97,7 +97,7 @@ class ApiLogin extends ApiBase { $status = BotPassword::login( $params['name'], $params['password'], $this->getRequest() ); - if ( $status->isOk() ) { + if ( $status->isOK() ) { $session = $status->getValue(); $authRes = LoginForm::SUCCESS; $loginType = 'BotPassword'; @@ -112,13 +112,13 @@ class ApiLogin extends ApiBase { if ( $authRes === false ) { $context->setRequest( new DerivativeRequest( $this->getContext()->getRequest(), - array( + [ 'wpName' => $params['name'], 'wpPassword' => $params['password'], 'wpDomain' => $params['domain'], 'wpLoginToken' => $params['token'], 'wpRemember' => '' - ) + ] ) ); $loginForm = new LoginForm(); $loginForm->setContext( $context ); @@ -138,7 +138,7 @@ class ApiLogin extends ApiBase { // @todo FIXME: Split back and frontend from this hook. // @todo FIXME: This hook should be placed in the backend $injected_html = ''; - Hooks::run( 'UserLoginComplete', array( &$user, &$injected_html ) ); + Hooks::run( 'UserLoginComplete', [ &$user, &$injected_html ] ); $result['result'] = 'Success'; $result['lguserid'] = intval( $user->getId() ); @@ -208,8 +208,7 @@ class ApiLogin extends ApiBase { case LoginForm::THROTTLED: $result['result'] = 'Throttled'; - $throttle = $this->getConfig()->get( 'PasswordAttemptThrottle' ); - $result['wait'] = intval( $throttle['seconds'] ); + $result['wait'] = intval( $loginForm->mThrottleWait ); break; case LoginForm::USER_BLOCKED: @@ -231,12 +230,12 @@ class ApiLogin extends ApiBase { $this->getResult()->addValue( null, 'login', $result ); - LoggerFactory::getInstance( 'authmanager' )->info( 'Login attempt', array( + LoggerFactory::getInstance( 'authmanager' )->info( 'Login attempt', [ 'event' => 'login', 'successful' => $authRes === LoginForm::SUCCESS, 'loginType' => $loginType, 'status' => LoginForm::$statusCodes[$authRes], - ) ); + ] ); } public function mustBePosted() { @@ -248,27 +247,27 @@ class ApiLogin extends ApiBase { } public function getAllowedParams() { - return array( + return [ 'name' => null, - 'password' => array( + 'password' => [ ApiBase::PARAM_TYPE => 'password', - ), + ], 'domain' => null, - 'token' => array( + 'token' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => false, // for BC - ApiBase::PARAM_HELP_MSG => array( 'api-help-param-token', 'login' ), - ), - ); + ApiBase::PARAM_HELP_MSG => [ 'api-help-param-token', 'login' ], + ], + ]; } protected function getExamplesMessages() { - return array( + return [ 'action=login&lgname=user&lgpassword=password' => 'apihelp-login-example-gettoken', 'action=login&lgname=user&lgpassword=password&lgtoken=123ABC' => 'apihelp-login-example-login', - ); + ]; } public function getHelpUrls() {