Add a route to view current user session and clear it
This commit is contained in:
parent
bfcff4220d
commit
f5fe9320c6
15
api/users.go
15
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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue