Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust library changes #13

Merged
merged 2 commits into from Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions system/core.go
Expand Up @@ -27,7 +27,7 @@ type CsrfProtection struct {
}

type Application struct {
Config *toml.TomlTree
Config *toml.Tree
Template *template.Template
Store *sessions.CookieStore
DbMap *gorp.DbMap
Expand All @@ -49,7 +49,7 @@ func (application *Application) Init(filename *string) {
HttpOnly: true,
Secure: config.Get("cookie.secure").(bool),
}
dbConfig := config.Get("database").(*toml.TomlTree)
dbConfig := config.Get("database").(*toml.Tree)
application.DbMap = models.GetDbMap(
dbConfig.Get("user").(string),
dbConfig.Get("password").(string),
Expand Down
11 changes: 8 additions & 3 deletions system/middleware.go
Expand Up @@ -8,12 +8,11 @@ import (
"net/http"
"strings"

"gopkg.in/gorp.v1"
"github.com/go-utils/uslice"
"github.com/golang/glog"
"github.com/gorilla/sessions"
"github.com/haruyama/golang-goji-sample/models"
"github.com/zenazn/goji/web"
"gopkg.in/gorp.v1"
)

// Makes sure templates are stored in the context
Expand Down Expand Up @@ -86,7 +85,13 @@ func isValidToken(a, b string) bool {
var csrfProtectionMethodForNoXhr = []string{"POST", "PUT", "DELETE"}

func isCsrfProtectionMethodForNoXhr(method string) bool {
return uslice.StrHas(csrfProtectionMethodForNoXhr, strings.ToUpper(method))
m := strings.ToUpper(method)
for _, mm := range csrfProtectionMethodForNoXhr {
if m == mm {
return true
}
}
return false
}

func (application *Application) ApplyCsrfProtection(c *web.C, h http.Handler) http.Handler {
Expand Down