3ec367a759
* Added new dep: gorilla/csrf * CSRF field in forms * CSRF variable in commontemplatevariables * New key for messages and user context Please change EnableSecureCSRF to false when testing locally and don't merge config/env.go with the changes
28 lignes
501 o
Go
28 lignes
501 o
Go
// +build !go1.7
|
|
|
|
package csrf
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/context"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func contextGet(r *http.Request, key string) (interface{}, error) {
|
|
if val, ok := context.GetOk(r, key); ok {
|
|
return val, nil
|
|
}
|
|
|
|
return nil, errors.Errorf("no value exists in the context for key %q", key)
|
|
}
|
|
|
|
func contextSave(r *http.Request, key string, val interface{}) *http.Request {
|
|
context.Set(r, key, val)
|
|
return r
|
|
}
|
|
|
|
func contextClear(r *http.Request) {
|
|
context.Clear(r)
|
|
}
|