diff --git a/core/modules/rest/src/Plugin/rest/resource/UserLoginResource.php b/core/modules/rest/src/Plugin/rest/resource/UserLoginResource.php index b801bcb..24c1e16 100644 --- a/core/modules/rest/src/Plugin/rest/resource/UserLoginResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/UserLoginResource.php @@ -19,7 +19,10 @@ * * @RestResource( * id = "user_login", - * label = @Translation("User Login") + * label = @Translation("User Login"), + * uri_paths = { + * "https://www.drupal.org/link-relations/create" = "/user/login", + * }, * ) */ class UserLoginResource extends ResourceBase { diff --git a/core/modules/rest/src/Plugin/rest/resource/UserLogout.php b/core/modules/rest/src/Plugin/rest/resource/UserLogout.php index cece0cf..0613e32 100644 --- a/core/modules/rest/src/Plugin/rest/resource/UserLogout.php +++ b/core/modules/rest/src/Plugin/rest/resource/UserLogout.php @@ -12,7 +12,7 @@ * id = "user_logout", * label = @Translation("Logout"), * uri_paths = { - * "canonical" = "/rest/user/logout", + * "https://www.drupal.org/link-relations/create" = "/user/logout", * } * ) */ @@ -25,6 +25,7 @@ class UserLogout extends ResourceBase { * The response. */ public function post() { + $this->userLogout(); return new ResourceResponse(NULL, 204); } diff --git a/core/modules/rest/src/Plugin/rest/resource/UserPasswordReset.php b/core/modules/rest/src/Plugin/rest/resource/UserPasswordReset.php index afc9464..76bc101 100644 --- a/core/modules/rest/src/Plugin/rest/resource/UserPasswordReset.php +++ b/core/modules/rest/src/Plugin/rest/resource/UserPasswordReset.php @@ -18,8 +18,8 @@ * id = "user_password_reset", * label = @Translation("Password reset"), * uri_paths = { - * "canonical" = "/rest/user/password/{name}/{langcode}" - * } + * "https://www.drupal.org/link-relations/create" = "/user/password/{name}/{langcode}", + * }, * ) */ class UserPasswordReset extends ResourceBase { diff --git a/core/modules/rest/src/Tests/UserLoginTest.php b/core/modules/rest/src/Tests/UserLoginTest.php index 3aa3362..9f32183 100644 --- a/core/modules/rest/src/Tests/UserLoginTest.php +++ b/core/modules/rest/src/Tests/UserLoginTest.php @@ -62,26 +62,31 @@ public function testLogin() { $url = Url::fromRoute('rest.user_login_status.GET.json'); $url->setRouteParameter('_format', 'json'); $this->httpRequest($url, 'GET', NULL, 'application/json'); - $this->assertResponseBody('200', '"' . UserLoginStatus::LOGGED_OUT . '"'); + $this->assertResponse(200); + $this->assertResponseBody('"' . UserLoginStatus::LOGGED_OUT . '"'); $payload = []; - $this->httpRequest('user_login', 'POST', json_encode($payload), 'application/json'); - $this->assertResponseBody('400', '{"error":"Missing credentials."}'); + $this->httpRequest('/user/login/', 'POST', json_encode($payload), 'application/json'); + $this->assertResponse(400); + $this->assertResponseBody('{"error":"Missing credentials."}'); $payload = ['pass' => $pass]; - $this->httpRequest('user_login', 'POST', json_encode($payload), 'application/json'); - $this->assertResponseBody('400', '{"error":"Missing credentials.name."}'); + $this->httpRequest('/user/login', 'POST', json_encode($payload), 'application/json'); + $this->assertResponse(400); + $this->assertResponseBody('{"error":"Missing credentials.name."}'); $payload = ['name' => $name, 'pass' => 'garbage']; - $this->httpRequest('user_login', 'POST', json_encode($payload), 'application/json'); - $this->assertResponseBody('400', '{"error":"Sorry, unrecognized username or password."}'); + $this->httpRequest('/user/login', 'POST', json_encode($payload), 'application/json'); + $this->assertResponse(400); + $this->assertResponseBody('{"error":"Sorry, unrecognized username or password."}'); $payload = ['name' => 'garbage', 'pass' => $pass]; - $this->httpRequest('user_login', 'POST', json_encode($payload), 'application/json'); - $this->assertResponseBody('400', '{"error":"Sorry, unrecognized username or password."}'); + $this->httpRequest('/user/login', 'POST', json_encode($payload), 'application/json'); + $this->assertResponse(400); + $this->assertResponseBody('{"error":"Sorry, unrecognized username or password."}'); $payload = ['name' => $name, 'pass' => $pass]; - $response = $this->httpRequest('user_login', 'POST', json_encode($payload), 'application/json'); + $response = $this->httpRequest('/user/login', 'POST', json_encode($payload), 'application/json'); $response = json_decode($response); $this->assertEqual($name, $response->current_user->name, "The user name is correct."); @@ -92,8 +97,8 @@ public function testLogin() { $this->assertResponseBody('"' . UserLoginStatus::LOGGED_IN . '"'); $payload = ['name' => $name, 'pass' => $pass]; - $this->httpRequest('user_logout', 'POST', json_encode($payload), 'application/json'); - $this->assertResponse('204'); + $this->httpRequest('/user/logout', 'POST', json_encode($payload), 'application/json'); + $this->assertResponse(204); $url = Url::fromRoute('rest.user_login_status.GET.json'); $url->setRouteParameter('_format', 'json');