aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2019-12-29 05:59:31 +0000
committerr <r@freesoftwareextremist.com>2019-12-29 05:59:31 +0000
commitede1bb42758d31e2537ba8545b3a403fc94f6cdb (patch)
tree159e09114154f44a21a2ef9a5f4c0f75f194e416
parent72dbe50341179d345f8cbd1bf5a97809037db364 (diff)
downloadbloat-ede1bb42758d31e2537ba8545b3a403fc94f6cdb.tar.gz
bloat-ede1bb42758d31e2537ba8545b3a403fc94f6cdb.zip
Use SetCookie function
-rw-r--r--service/transport.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/service/transport.go b/service/transport.go
index 20d96a5..bbf1f06 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -2,11 +2,11 @@ package service
import (
"context"
- "fmt"
"mime/multipart"
"net/http"
"path"
"strconv"
+ "time"
"web/model"
"github.com/gorilla/mux"
@@ -45,13 +45,18 @@ func NewHandler(s Service, staticDir string) http.Handler {
r.HandleFunc("/signin", func(w http.ResponseWriter, req *http.Request) {
instance := req.FormValue("instance")
- url, sessionId, err := s.GetAuthUrl(ctx, instance)
+ url, sessionID, err := s.GetAuthUrl(ctx, instance)
if err != nil {
s.ServeErrorPage(ctx, w, err)
return
}
- w.Header().Add("Set-Cookie", fmt.Sprintf("session_id=%s;max-age=%s", sessionId, cookieAge))
+ http.SetCookie(w, &http.Cookie{
+ Name: "session_id",
+ Value: sessionID,
+ Expires: time.Now().Add(365 * 24 * time.Hour),
+ })
+
w.Header().Add("Location", url)
w.WriteHeader(http.StatusFound)
}).Methods(http.MethodPost)
@@ -366,7 +371,11 @@ func NewHandler(s Service, staticDir string) http.Handler {
r.HandleFunc("/signout", func(w http.ResponseWriter, req *http.Request) {
// TODO remove session from database
- w.Header().Add("Set-Cookie", fmt.Sprintf("session_id=;max-age=0"))
+ http.SetCookie(w, &http.Cookie{
+ Name: "session_id",
+ Value: "",
+ Expires: time.Now(),
+ })
w.Header().Add("Location", "/")
w.WriteHeader(http.StatusFound)
}).Methods(http.MethodGet)