update auth/logout (#417)

This commit is contained in:
yubo 2020-11-24 18:56:18 +08:00 committed by GitHub
parent 86c0520076
commit d80ce1d8c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 17 deletions

1
.gitignore vendored
View File

@ -56,3 +56,4 @@ _test
tmp/ tmp/
main main
Makefile

View File

@ -100,28 +100,31 @@ func login(c *gin.Context) {
} }
func logout(c *gin.Context) { func logout(c *gin.Context) {
uuid := readCookieUser(c) func() {
if uuid == "" { uuid := readCookieUser(c)
c.String(200, "logout successfully") if uuid == "" {
return return
} }
username := models.UsernameByUUID(uuid)
username := models.UsernameByUUID(uuid) if username == "" {
if username == "" { return
c.String(200, "logout successfully") }
return writeCookieUser(c, "")
} go models.LoginLogNew(username, c.ClientIP(), "out")
}()
writeCookieUser(c, "")
if config.Config.SSO.Enable { if config.Config.SSO.Enable {
redirect := queryStr(c, "redirect", "/") redirect := queryStr(c, "redirect", "/")
c.Redirect(302, ssoc.LogoutLocation(redirect)) c.Redirect(302, ssoc.LogoutLocation(redirect))
} else { return
c.String(200, "logout successfully")
} }
go models.LoginLogNew(username, c.ClientIP(), "out") if redirect := queryStr(c, "redirect", ""); redirect != "" {
c.Redirect(302, redirect)
return
}
c.String(200, "logout successfully")
} }
type authRedirect struct { type authRedirect struct {
@ -131,7 +134,6 @@ type authRedirect struct {
func authAuthorizeV2(c *gin.Context) { func authAuthorizeV2(c *gin.Context) {
redirect := queryStr(c, "redirect", "/") redirect := queryStr(c, "redirect", "/")
log.Printf("---> redirect %s", redirect)
ret := &authRedirect{Redirect: redirect} ret := &authRedirect{Redirect: redirect}
username := cookieUsername(c) username := cookieUsername(c)