Skip to content

Commit

Permalink
Logout POST action (#10582) (#10585)
Browse files Browse the repository at this point in the history
* Change logout to POST

* Update for redirect

* Revert octicon to font

Signed-off-by: jolheiser <[email protected]>
  • Loading branch information
jolheiser committed Mar 3, 2020
1 parent e4a876c commit 6f5656a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion integrations/signout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestSignOut(t *testing.T) {

session := loginUser(t, "user2")

req := NewRequest(t, "GET", "/user/logout")
req := NewRequest(t, "POST", "/user/logout")
session.MakeRequest(t, req, http.StatusFound)

// try to view a private repo, should fail
Expand Down
2 changes: 1 addition & 1 deletion routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/recover_account", user.ResetPasswdPost)
m.Get("/forgot_password", user.ForgotPasswd)
m.Post("/forgot_password", user.ForgotPasswdPost)
m.Get("/logout", user.SignOut)
m.Post("/logout", user.SignOut)
})
// ***** END: User *****

Expand Down
2 changes: 1 addition & 1 deletion templates/base/head_navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
{{end}}

<div class="divider"></div>
<a class="item" href="{{AppSubUrl}}/user/logout">
<a class="item link-action" href data-url="{{AppSubUrl}}/user/logout" data-redirect="{{AppSubUrl}}/">
<i class="octicon octicon-sign-out"></i>
{{.i18n.Tr "sign_out"}}<!-- Sign Out -->
</a>
Expand Down
3 changes: 3 additions & 0 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2740,11 +2740,14 @@ function showAddAllPopup() {

function linkAction() {
const $this = $(this);
const redirect = $this.data('redirect');
$.post($this.data('url'), {
_csrf: csrf
}).done((data) => {
if (data.redirect) {
window.location.href = data.redirect;
} else if (redirect) {
window.location.href = redirect;
} else {
window.location.reload();
}
Expand Down

0 comments on commit 6f5656a

Please sign in to comment.