From bfe5b86004791823b198be76084aa128d262b290 Mon Sep 17 00:00:00 2001 From: Justin Nuß Date: Thu, 24 Jul 2014 15:19:59 +0200 Subject: Add file upload for attachments --- modules/middleware/context.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'modules/middleware') diff --git a/modules/middleware/context.go b/modules/middleware/context.go index c641449a..6b47e94f 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -323,7 +323,6 @@ func (f *Flash) Success(msg string) { // InitContext initializes a classic context for a request. func InitContext() martini.Handler { return func(res http.ResponseWriter, r *http.Request, c martini.Context, rd *Render) { - ctx := &Context{ c: c, // p: p, @@ -332,7 +331,6 @@ func InitContext() martini.Handler { Cache: setting.Cache, Render: rd, } - ctx.Data["PageStartTime"] = time.Now() // start session @@ -374,6 +372,14 @@ func InitContext() martini.Handler { ctx.Data["IsAdmin"] = ctx.User.IsAdmin } + // If request sends files, parse them here otherwise the Query() can't be parsed and the CsrfToken will be invalid. + if strings.Contains(r.Header.Get("Content-Type"), "multipart/form-data") { + if err = ctx.Req.ParseMultipartForm(setting.AttachmentMaxSize << 20); err != nil { // 32MB max size + ctx.Handle(500, "issue.Comment(ctx.Req.ParseMultipartForm)", err) + return + } + } + // get or create csrf token ctx.Data["CsrfToken"] = ctx.CsrfToken() ctx.Data["CsrfTokenHtml"] = template.HTML(``) -- cgit v1.2.3 From a41a1fe60da5b02891640dd5f99758015b78bcc9 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 24 Jul 2014 12:49:40 -0400 Subject: Mirror fix --- cmd/web.go | 2 +- modules/middleware/context.go | 6 +----- modules/setting/setting.go | 1 + 3 files changed, 3 insertions(+), 6 deletions(-) (limited to 'modules/middleware') diff --git a/cmd/web.go b/cmd/web.go index d3ce68d3..0af79c3c 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -206,7 +206,7 @@ func runWeb(*cli.Context) { r.Post("/:org/teams/new", bindIgnErr(auth.CreateTeamForm{}), org.NewTeamPost) r.Get("/:org/teams/:team/edit", org.EditTeam) - r.Get("/:org/team/:team",org.SingleTeam) + r.Get("/:org/team/:team", org.SingleTeam) r.Get("/:org/settings", org.Settings) r.Post("/:org/settings", bindIgnErr(auth.OrgSettingForm{}), org.SettingsPost) diff --git a/modules/middleware/context.go b/modules/middleware/context.go index c641449a..6bd529cd 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -139,10 +139,6 @@ func (ctx *Context) Handle(status int, title string, err error) { ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status))) } -func (ctx *Context) Debug(msg string, args ...interface{}) { - log.Debug(msg, args...) -} - func (ctx *Context) GetCookie(name string) string { cookie, err := ctx.Req.Cookie(name) if err != nil { @@ -356,7 +352,7 @@ func InitContext() martini.Handler { ctx.Session.SessionRelease(res) if flash := ctx.Flash.Encode(); len(flash) > 0 { - ctx.SetCookie("gogs_flash", ctx.Flash.Encode(), 0) + ctx.SetCookie("gogs_flash", flash, 0) } }) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index f03aa8ae..717e81ad 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -341,6 +341,7 @@ func newSessionService() { log.Fatal("Init session system failed, provider: %s, %v", SessionProvider, err) } + go SessionManager.GC() log.Info("Session Service Enabled") } -- cgit v1.2.3