diff --git a/api/users.go b/api/users.go index d9ded1b..d6019e6 100644 --- a/api/users.go +++ b/api/users.go @@ -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, + } +} diff --git a/model/session.go b/model/session.go index f0508be..639215a 100644 --- a/model/session.go +++ b/model/session.go @@ -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 +}