From d80ce1d8c53871f53603237d07f3081b818d05c4 Mon Sep 17 00:00:00 2001 From: yubo Date: Tue, 24 Nov 2020 18:56:18 +0800 Subject: [PATCH] update auth/logout (#417) --- .gitignore | 1 + src/modules/rdb/http/router_auth.go | 36 +++++++++++++++-------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 36942256..41997358 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,4 @@ _test tmp/ main +Makefile diff --git a/src/modules/rdb/http/router_auth.go b/src/modules/rdb/http/router_auth.go index 2f2649f9..60034fbf 100644 --- a/src/modules/rdb/http/router_auth.go +++ b/src/modules/rdb/http/router_auth.go @@ -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)