diff --git a/core/modules/rest/src/Plugin/ResourceBase.php b/core/modules/rest/src/Plugin/ResourceBase.php index d0d22a3..0babfb7 100644 --- a/core/modules/rest/src/Plugin/ResourceBase.php +++ b/core/modules/rest/src/Plugin/ResourceBase.php @@ -216,4 +216,18 @@ protected function getBaseRoute($canonical_path, $method) { return $route; } + /** + * Throws an exception if the current user triggers flood control. + * + * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException + */ + protected function restFloodControl($config, $event) { + $limit = $config->get('user_limit'); + $interval = $config->get('user_window'); + if (!\Drupal::flood()->isAllowed($name, $limit, $interval)) { + return TRUE; + } + return FALSE; + } + } diff --git a/core/modules/rest/src/Plugin/rest/resource/UserLoginResource.php b/core/modules/rest/src/Plugin/rest/resource/UserLoginResource.php index be8aa64..966897e 100644 --- a/core/modules/rest/src/Plugin/rest/resource/UserLoginResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/UserLoginResource.php @@ -36,12 +36,12 @@ public function post(array $operation = array()) { case 'login': if (!empty($operation['credentials'])) { - return $this->userLogin($operation['credentials']); + return $this->login($operation['credentials']); } return new ResourceResponse('Missing name and pass.', 400, array()); case 'logout': - return $this->userLogout();; + return $this->logout(); } } @@ -55,7 +55,7 @@ public function post(array $operation = array()) { * @return \Drupal\rest\ResourceResponse * The HTTP response object */ - protected function userLogin(array $credentials = array()) { + protected function login(array $credentials = array()) { // Verify that the username is filled. if (!array_key_exists('name', $credentials)) { return new ResourceResponse('Missing username.', 400, array()); @@ -66,7 +66,7 @@ protected function userLogin(array $credentials = array()) { } // Flood control. - if ($this->restLoginCookieFloodControl()) { + if ($this->restFloodControl(\Drupal::config('user.flood'), 'rest.login_cookie')) { return new ResourceResponse('Blocked.', 400, array()); } @@ -85,25 +85,9 @@ protected function userLogin(array $credentials = array()) { * * @return ResourceResponse */ - protected function userLogout() { + protected function logout() { user_logout(); return new ResourceResponse('Logged out!', 200, array()); } - - /** - * Throws an exception if the current user triggers flood control. - * - * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException - */ - protected function restLoginCookieFloodControl() { - $limit = \Drupal::config('user.flood')->get('user_limit'); - $interval = \Drupal::config('user.flood')->get('user_window'); - if (!\Drupal::flood()->isAllowed('rest.login_cookie', $limit, $interval)) { - return TRUE; - } - return FALSE; - } - - } \ No newline at end of file