Compare commits

...

1 Commits

Author SHA1 Message Date
xAmast
25ee4226d3 feat: clear the session of a signin but non-existent user (#1246) 2022-10-29 20:18:02 +08:00
3 changed files with 9 additions and 6 deletions

View File

@@ -245,8 +245,7 @@ func (c *ApiController) Logout() {
util.LogInfo(c.Ctx, "API: [%s] logged out", user) util.LogInfo(c.Ctx, "API: [%s] logged out", user)
application := c.GetSessionApplication() application := c.GetSessionApplication()
c.SetSessionUsername("") c.ClearUserSession()
c.SetSessionData(nil)
if application == nil || application.Name == "app-built-in" || application.HomepageUrl == "" { if application == nil || application.Name == "app-built-in" || application.HomepageUrl == "" {
c.ResponseOk(user) c.ResponseOk(user)

View File

@@ -63,8 +63,7 @@ func (c *ApiController) GetSessionUsername() string {
if sessionData != nil && if sessionData != nil &&
sessionData.ExpireTime != 0 && sessionData.ExpireTime != 0 &&
sessionData.ExpireTime < time.Now().Unix() { sessionData.ExpireTime < time.Now().Unix() {
c.SetSessionUsername("") c.ClearUserSession()
c.SetSessionData(nil)
return "" return ""
} }
@@ -85,13 +84,17 @@ func (c *ApiController) GetSessionApplication() *object.Application {
return application return application
} }
func (c *ApiController) ClearUserSession() {
c.SetSessionUsername("")
c.SetSessionData(nil)
}
func (c *ApiController) GetSessionOidc() (string, string) { func (c *ApiController) GetSessionOidc() (string, string) {
sessionData := c.GetSessionData() sessionData := c.GetSessionData()
if sessionData != nil && if sessionData != nil &&
sessionData.ExpireTime != 0 && sessionData.ExpireTime != 0 &&
sessionData.ExpireTime < time.Now().Unix() { sessionData.ExpireTime < time.Now().Unix() {
c.SetSessionUsername("") c.ClearUserSession()
c.SetSessionData(nil)
return "", "" return "", ""
} }
scopeValue := c.GetSession("scope") scopeValue := c.GetSession("scope")

View File

@@ -98,6 +98,7 @@ func (c *ApiController) RequireSignedInUser() (*object.User, bool) {
user := object.GetUser(userId) user := object.GetUser(userId)
if user == nil { if user == nil {
c.ClearUserSession()
c.ResponseError(fmt.Sprintf(c.T("UserErr.DoNotExist"), userId)) c.ResponseError(fmt.Sprintf(c.T("UserErr.DoNotExist"), userId))
return nil, false return nil, false
} }