1
0
mirror of https://github.com/bingohuang/docker-labs.git synced 2025-07-15 02:37:27 +08:00

Add MaxAge to securecookie

This commit is contained in:
Marcos Lilljedahl 2017-03-14 17:08:02 -03:00
parent 2c7af720c0
commit ec03c5ed69

View File

@ -37,7 +37,7 @@ type recaptchaResponse struct {
Success bool `json:"success"` Success bool `json:"success"`
} }
var s = securecookie.New([]byte(config.HashKey), nil) var s = securecookie.New([]byte(config.HashKey), nil).MaxAge(int((1 * time.Hour).Seconds()))
func IsHuman(req *http.Request, rw http.ResponseWriter) bool { func IsHuman(req *http.Request, rw http.ResponseWriter) bool {
if os.Getenv("GOOGLE_RECAPTCHA_DISABLED") != "" { if os.Getenv("GOOGLE_RECAPTCHA_DISABLED") != "" {
@ -45,9 +45,9 @@ func IsHuman(req *http.Request, rw http.ResponseWriter) bool {
} }
if cookie, _ := req.Cookie("session_id"); cookie != nil { if cookie, _ := req.Cookie("session_id"); cookie != nil {
fmt.Println(cookie)
var value string var value string
if err := s.Decode("session_id", cookie.Value, &value); err != nil { if err := s.Decode("session_id", cookie.Value, &value); err != nil {
fmt.Println(err)
return false return false
} }
return true return true
@ -83,7 +83,7 @@ func IsHuman(req *http.Request, rw http.ResponseWriter) bool {
http.SetCookie(rw, &http.Cookie{ http.SetCookie(rw, &http.Cookie{
Name: "session_id", Name: "session_id",
Value: encoded, Value: encoded,
Expires: time.Now().Add(3 * time.Hour), Expires: time.Now().Add(1 * time.Hour),
}) })
return true return true