Files
filekeeper/handler/user/session/terminate/terminate.go

28 lines
712 B
Go

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)
if session.GetSessionInfo(mySession.Email, otherSession.ID) == nil {
w.WriteHeader(http.StatusUnauthorized)
return
}
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
}
}