mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-22 20:59:21 +02:00
Use SetCookie function
This commit is contained in:
parent
72dbe50341
commit
ede1bb4275
|
@ -2,11 +2,11 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
"web/model"
|
"web/model"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"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) {
|
r.HandleFunc("/signin", func(w http.ResponseWriter, req *http.Request) {
|
||||||
instance := req.FormValue("instance")
|
instance := req.FormValue("instance")
|
||||||
url, sessionId, err := s.GetAuthUrl(ctx, instance)
|
url, sessionID, err := s.GetAuthUrl(ctx, instance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.ServeErrorPage(ctx, w, err)
|
s.ServeErrorPage(ctx, w, err)
|
||||||
return
|
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.Header().Add("Location", url)
|
||||||
w.WriteHeader(http.StatusFound)
|
w.WriteHeader(http.StatusFound)
|
||||||
}).Methods(http.MethodPost)
|
}).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) {
|
r.HandleFunc("/signout", func(w http.ResponseWriter, req *http.Request) {
|
||||||
// TODO remove session from database
|
// 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.Header().Add("Location", "/")
|
||||||
w.WriteHeader(http.StatusFound)
|
w.WriteHeader(http.StatusFound)
|
||||||
}).Methods(http.MethodGet)
|
}).Methods(http.MethodGet)
|
||||||
|
|
Loading…
Reference in New Issue