Add Ubuntu deployment: scripts, SSL, systemd and setup.sh
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user