Add a route to view current user session and clear it

This commit is contained in:
nemunaire 2020-07-18 00:23:58 +02:00
parent bfcff4220d
commit f5fe9320c6
2 changed files with 20 additions and 0 deletions

View File

@ -52,6 +52,8 @@ import (
)
func init() {
router.GET("/api/session", apiAuthHandler(getSession))
router.DELETE("/api/session", apiAuthHandler(clearSession))
router.POST("/api/users", ApiHandler(registerUser))
router.PATCH("/api/users", ApiHandler(specialUserOperations))
router.GET("/api/users/:uid", apiAuthHandler(sameUserHandler(getUser)))
@ -340,3 +342,16 @@ func recoverUserAccount(opts *config.Options, user *happydns.User, body io.Reade
}
}
}
func getSession(opts *config.Options, req *RequestResources, body io.Reader) Response {
return APIResponse{
response: req.Session,
}
}
func clearSession(opts *config.Options, req *RequestResources, body io.Reader) Response {
req.Session.ClearSession()
return APIResponse{
response: true,
}
}

View File

@ -111,3 +111,8 @@ func (s *Session) GetValue(key string, value interface{}) bool {
func (s *Session) DropKey(key string) {
s.SetValue(key, nil)
}
func (s *Session) ClearSession() {
s.Content = nil
s.changed = true
}