diff --git a/handler/user/session/terminate/terminate.go b/handler/user/session/terminate/terminate.go new file mode 100644 index 0000000..95caf0a --- /dev/null +++ b/handler/user/session/terminate/terminate.go @@ -0,0 +1,23 @@ +package userSessionTerminateHandler + +import ( + "github.com/fossyy/filekeeper/session" + userView "github.com/fossyy/filekeeper/view/user" + "net/http" +) + +func DELETE(w http.ResponseWriter, r *http.Request) { + id := r.PathValue("id") + + _, mySession, _ := session.GetSession(r) + otherSession, _ := session.Get(id) + otherSession.Delete() + session.RemoveSessionInfo(mySession.Email, otherSession.ID) + + component := userView.SessionTable(session.GetSessions(mySession.Email)) + err := component.Render(r.Context(), w) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + return + } +} diff --git a/routes/routes.go b/routes/routes.go index be92670..6ff4877 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -17,6 +17,7 @@ import ( uploadHandler "github.com/fossyy/filekeeper/handler/upload" "github.com/fossyy/filekeeper/handler/upload/initialisation" userHandler "github.com/fossyy/filekeeper/handler/user" + userSessionTerminateHandler "github.com/fossyy/filekeeper/handler/user/session/terminate" userHandlerTotpSetup "github.com/fossyy/filekeeper/handler/user/totp" "github.com/fossyy/filekeeper/middleware" "net/http" @@ -92,6 +93,10 @@ func SetupRoutes() *http.ServeMux { middleware.Auth(userHandler.GET, w, r) }) + handler.HandleFunc("DELETE /user/session/terminate/{id}", func(w http.ResponseWriter, r *http.Request) { + middleware.Auth(userSessionTerminateHandler.DELETE, w, r) + }) + handler.HandleFunc("GET /user/totp/setup", func(w http.ResponseWriter, r *http.Request) { middleware.Auth(userHandlerTotpSetup.GET, w, r) }) diff --git a/view/user/user.templ b/view/user/user.templ index f6f2084..8888dcf 100644 --- a/view/user/user.templ +++ b/view/user/user.templ @@ -109,7 +109,7 @@ templ content(title string, user types.User, ListSession []*session.SessionInfo) -
+ for _, ses := range ListSession {