summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/app/handler/authentication/logout.go')
-rw-r--r--pkg/app/handler/authentication/logout.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/pkg/app/handler/authentication/logout.go b/pkg/app/handler/authentication/logout.go
new file mode 100644
index 0000000..87d17f4
--- /dev/null
+++ b/pkg/app/handler/authentication/logout.go
@@ -0,0 +1,29 @@
+package authentication
+
+import (
+ "glsamaker/pkg/database/connection"
+ "glsamaker/pkg/logger"
+ "glsamaker/pkg/models"
+ "net/http"
+)
+
+func Logout(w http.ResponseWriter, r *http.Request) {
+
+ sessionID, err := r.Cookie("session")
+
+ if err != nil || sessionID == nil {
+ // TODO Error
+ }
+
+ session := &models.Session{Id: sessionID.Value}
+ _, err = connection.DB.Model(session).WherePK().Delete()
+
+ if err != nil {
+ logger.Info.Println("Error deleting session")
+ logger.Error.Println("Error deleting session")
+ logger.Error.Println(err)
+ }
+
+ http.Redirect(w, r, "/", 301)
+
+}