2017-03-12 19:37:53 +00:00
|
|
|
package middle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/justinas/nosurf"
|
|
|
|
"github.com/pressly/chi/middleware"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetBaseCtx(r *http.Request) map[string]interface{} {
|
|
|
|
val := map[string]interface{}{
|
|
|
|
"Config": GetConfig(r),
|
|
|
|
"ReqID": middleware.GetReqID(r.Context()),
|
|
|
|
"CSRFToken": nosurf.Token(r),
|
|
|
|
}
|
|
|
|
|
2017-03-13 15:04:00 +00:00
|
|
|
if sess := GetSession(r); sess != nil {
|
|
|
|
val["Session"] = sess
|
|
|
|
}
|
|
|
|
|
|
|
|
err := r.URL.Query().Get("err")
|
|
|
|
if err != "" {
|
|
|
|
val["PreviousError"] = err
|
|
|
|
}
|
|
|
|
|
2017-03-12 19:37:53 +00:00
|
|
|
return val
|
|
|
|
}
|
|
|
|
|
|
|
|
func CSRFProtect(next http.Handler) http.Handler {
|
|
|
|
return nosurf.New(next)
|
|
|
|
}
|