Add Ubuntu deployment: scripts, SSL, systemd and setup.sh

This commit is contained in:
shop
2026-06-25 16:47:01 +03:00
parent ee5688f722
commit 8a7f79a70c
19 changed files with 387 additions and 58 deletions
+11 -2
View File
@@ -58,27 +58,36 @@ func (s *Session) Validate(token string) (string, bool) {
return email, true
}
func (s *Session) SetCookie(w http.ResponseWriter, token string) {
func (s *Session) SetCookie(w http.ResponseWriter, r *http.Request, token string) {
http.SetCookie(w, &http.Cookie{
Name: cookieName,
Value: token,
Path: "/admin",
HttpOnly: true,
Secure: s.isSecure(r),
SameSite: http.SameSiteLaxMode,
MaxAge: int(sessionTTL.Seconds()),
})
}
func (s *Session) ClearCookie(w http.ResponseWriter) {
func (s *Session) ClearCookie(w http.ResponseWriter, r *http.Request) {
http.SetCookie(w, &http.Cookie{
Name: cookieName,
Value: "",
Path: "/admin",
HttpOnly: true,
Secure: s.isSecure(r),
MaxAge: -1,
})
}
func (s *Session) isSecure(r *http.Request) bool {
if r.TLS != nil {
return true
}
return strings.EqualFold(r.Header.Get("X-Forwarded-Proto"), "https")
}
func (s *Session) FromRequest(r *http.Request) (string, bool) {
c, err := r.Cookie(cookieName)
if err != nil {