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/
main
Makefile

View File

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