mirror of
https://github.com/h44z/wg-portal
synced 2025-02-26 05:49:14 +00:00
validate user in session (#32)
This commit is contained in:
parent
fbc0b26631
commit
57b57931b2
@ -192,3 +192,10 @@ func (s *Server) setFormInSession(c *gin.Context, formData interface{}) (Session
|
|||||||
|
|
||||||
return currentSession, nil
|
return currentSession, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) isUserStillValid(email string) bool {
|
||||||
|
if s.users.GetUser(email) == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
@ -141,6 +141,14 @@ func (s *Server) RequireAuthentication(scope string) gin.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if logged-in user is still valid
|
||||||
|
if !s.isUserStillValid(session.Email) {
|
||||||
|
_ = DestroySessionData(c)
|
||||||
|
c.Abort()
|
||||||
|
s.GetHandleError(c, http.StatusUnauthorized, "unauthorized", "session no longer available")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Continue down the chain to handler etc
|
// Continue down the chain to handler etc
|
||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user