Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return new CSRF values in JSON response for login/logout. #3860

Merged
merged 2 commits into from
Feb 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,17 @@ public function actionLogout(): Response
// Passing false here for reasons.
Craft::$app->getUser()->logout(false);

if (Craft::$app->getRequest()->getAcceptsJson()) {
return $this->asJson([
$request = Craft::$app->getRequest();
if ($request->getAcceptsJson()) {
$return = [
'success' => true
]);
];

if (Craft::$app->getConfig()->getGeneral()->enableCsrfProtection) {
$return['csrfTokenValue'] = $request->getCsrfToken();
}

return $this->asJson($return);
}

// Redirect to the login page if this is a CP request
Expand Down Expand Up @@ -1631,11 +1638,18 @@ private function _handleSuccessfulLogin(bool $setNotice): Response
$userSession->removeReturnUrl();

// If this was an Ajax request, just return success:true
if (Craft::$app->getRequest()->getAcceptsJson()) {
return $this->asJson([
$request = Craft::$app->getRequest();
if ($request->getAcceptsJson()) {
$return = [
'success' => true,
'returnUrl' => $returnUrl
]);
];

if (Craft::$app->getConfig()->getGeneral()->enableCsrfProtection) {
$return['csrfTokenValue'] = $request->getCsrfToken();
}

return $this->asJson($return);
}

if ($setNotice) {
Expand Down