Browse Source

auth set cookie

Dasflugen 5 years ago
parent
commit
a59cfc88e2
1 changed files with 13 additions and 0 deletions
  1. 13 0
      api/authorization.go

+ 13 - 0
api/authorization.go

@@ -11,6 +11,18 @@ type User struct{
 	Password string `json:"password"`
 }
 
+func (u User) SetCookie(w http.ResponseWriter, r *http.Request){
+	cookie := http.Cookie{
+		Name: u.Login,
+		Value: "logged in",
+		Domain: r.Host,
+		Path: "/",
+		MaxAge: 60*60,
+		HttpOnly: true,
+	}
+	http.SetCookie(rw, &cookie)
+}
+
 func LoginRoute(w http.ResponseWriter, r *http.Request){
 	showAPIRequest(r)
 	var userGroups []string
@@ -46,6 +58,7 @@ func LoginRoute(w http.ResponseWriter, r *http.Request){
 				}
 			}
 		}
+		user.SetCookie(w, r)
 		json.NewEncoder(w).Encode(userGroups)
 		return
 	}