diff options
author | Frédéric Guillot <fred@miniflux.net> | 2018-09-03 14:26:40 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2018-09-03 14:26:40 -0700 |
commit | eee1f3190355224eef63a4dcdef8c36eb3ca3738 (patch) | |
tree | 009b7ca67b96d9be473d8ddf2c8c95f22a6749d1 /ui | |
parent | 88e81d4d800ff6433518522954197d75203a25c2 (diff) |
Refactor HTTP context handling
Diffstat (limited to 'ui')
60 files changed, 228 insertions, 350 deletions
diff --git a/ui/about.go b/ui/about.go index 1815532..e11ab52 100644 --- a/ui/about.go +++ b/ui/about.go @@ -7,8 +7,8 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/response/html" + "miniflux.app/http/request" "miniflux.app/ui/session" "miniflux.app/ui/view" "miniflux.app/version" @@ -16,16 +16,14 @@ import ( // About shows the about page. func (c *Controller) About(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("version", version.Version) view.Set("build_date", version.BuildDate) view.Set("menu", "settings") diff --git a/ui/bookmark_entries.go b/ui/bookmark_entries.go index 09b9bf6..08385f6 100644 --- a/ui/bookmark_entries.go +++ b/ui/bookmark_entries.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -18,9 +17,7 @@ import ( // ShowStarredPage renders the page with all starred entries. func (c *Controller) ShowStarredPage(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -47,8 +44,8 @@ func (c *Controller) ShowStarredPage(w http.ResponseWriter, r *http.Request) { return } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("total", count) view.Set("entries", entries) diff --git a/ui/category_create.go b/ui/category_create.go index 8f7019f..20d280a 100644 --- a/ui/category_create.go +++ b/ui/category_create.go @@ -2,12 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" + "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/ui/session" "miniflux.app/ui/view" @@ -15,16 +15,14 @@ import ( // CreateCategory shows the form to create a new category. func (c *Controller) CreateCategory(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("menu", "categories") view.Set("user", user) view.Set("countUnread", c.store.CountUnreadEntries(user.ID)) diff --git a/ui/category_edit.go b/ui/category_edit.go index 6651a0a..0ab4b1b 100644 --- a/ui/category_edit.go +++ b/ui/category_edit.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/ui/form" @@ -17,11 +16,10 @@ import ( // EditCategory shows the form to modify a category. func (c *Controller) EditCategory(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -33,7 +31,7 @@ func (c *Controller) EditCategory(w http.ResponseWriter, r *http.Request) { return } - category, err := c.store.Category(ctx.UserID(), categoryID) + category, err := c.store.Category(request.UserID(r), categoryID) if err != nil { html.ServerError(w, err) return diff --git a/ui/category_entries.go b/ui/category_entries.go index cee4fc9..ac39fa1 100644 --- a/ui/category_entries.go +++ b/ui/category_entries.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -18,9 +17,7 @@ import ( // CategoryEntries shows all entries for the given category. func (c *Controller) CategoryEntries(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -32,7 +29,7 @@ func (c *Controller) CategoryEntries(w http.ResponseWriter, r *http.Request) { return } - category, err := c.store.Category(ctx.UserID(), categoryID) + category, err := c.store.Category(request.UserID(r), categoryID) if err != nil { html.ServerError(w, err) return @@ -64,8 +61,8 @@ func (c *Controller) CategoryEntries(w http.ResponseWriter, r *http.Request) { return } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("category", category) view.Set("total", count) view.Set("entries", entries) diff --git a/ui/category_list.go b/ui/category_list.go index 4ec9795..3dc17ca 100644 --- a/ui/category_list.go +++ b/ui/category_list.go @@ -7,17 +7,15 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/response/html" "miniflux.app/ui/session" + "miniflux.app/http/request" "miniflux.app/ui/view" ) // CategoryList shows the page with all categories. func (c *Controller) CategoryList(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -29,8 +27,8 @@ func (c *Controller) CategoryList(w http.ResponseWriter, r *http.Request) { return } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("categories", categories) view.Set("total", len(categories)) view.Set("menu", "categories") diff --git a/ui/category_remove.go b/ui/category_remove.go index 6cdb0e4..033d9e3 100644 --- a/ui/category_remove.go +++ b/ui/category_remove.go @@ -2,12 +2,11 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" @@ -16,9 +15,7 @@ import ( // RemoveCategory deletes a category from the database. func (c *Controller) RemoveCategory(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -30,7 +27,7 @@ func (c *Controller) RemoveCategory(w http.ResponseWriter, r *http.Request) { return } - category, err := c.store.Category(ctx.UserID(), categoryID) + category, err := c.store.Category(request.UserID(r), categoryID) if err != nil { html.ServerError(w, err) return diff --git a/ui/category_save.go b/ui/category_save.go index 9a1dcf5..2ae4383 100644 --- a/ui/category_save.go +++ b/ui/category_save.go @@ -7,10 +7,10 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" + "miniflux.app/http/request" "miniflux.app/logger" "miniflux.app/model" "miniflux.app/ui/form" @@ -20,9 +20,7 @@ import ( // SaveCategory validate and save the new category into the database. func (c *Controller) SaveCategory(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -30,8 +28,8 @@ func (c *Controller) SaveCategory(w http.ResponseWriter, r *http.Request) { categoryForm := form.NewCategoryForm(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("form", categoryForm) view.Set("menu", "categories") view.Set("user", user) diff --git a/ui/category_update.go b/ui/category_update.go index 892ad13..0553d97 100644 --- a/ui/category_update.go +++ b/ui/category_update.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" @@ -20,9 +19,7 @@ import ( // UpdateCategory validates and updates a category. func (c *Controller) UpdateCategory(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -34,7 +31,7 @@ func (c *Controller) UpdateCategory(w http.ResponseWriter, r *http.Request) { return } - category, err := c.store.Category(ctx.UserID(), categoryID) + category, err := c.store.Category(request.UserID(r), categoryID) if err != nil { html.ServerError(w, err) return @@ -47,8 +44,8 @@ func (c *Controller) UpdateCategory(w http.ResponseWriter, r *http.Request) { categoryForm := form.NewCategoryForm(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("form", categoryForm) view.Set("category", category) view.Set("menu", "categories") diff --git a/ui/controller.go b/ui/controller.go index 5b1bbaf..005b863 100644 --- a/ui/controller.go +++ b/ui/controller.go @@ -5,13 +5,14 @@ package ui // import "miniflux.app/ui" import ( - "github.com/gorilla/mux" "miniflux.app/config" "miniflux.app/locale" "miniflux.app/reader/feed" "miniflux.app/scheduler" "miniflux.app/storage" "miniflux.app/template" + + "github.com/gorilla/mux" ) // Controller contains all HTTP handlers for the user interface. diff --git a/ui/entry_bookmark.go b/ui/entry_bookmark.go index 9a469e1..e6d2f0e 100644 --- a/ui/entry_bookmark.go +++ b/ui/entry_bookmark.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -20,9 +19,7 @@ import ( // ShowStarredEntry shows a single feed entry in "starred" mode. func (c *Controller) ShowStarredEntry(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -78,8 +75,8 @@ func (c *Controller) ShowStarredEntry(w http.ResponseWriter, r *http.Request) { prevEntryRoute = route.Path(c.router, "starredEntry", "entryID", prevEntry.ID) } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("entry", entry) view.Set("prevEntry", prevEntry) view.Set("nextEntry", nextEntry) diff --git a/ui/entry_category.go b/ui/entry_category.go index 41b729f..795aaf1 100644 --- a/ui/entry_category.go +++ b/ui/entry_category.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -20,9 +19,7 @@ import ( // ShowCategoryEntry shows a single feed entry in "category" mode. func (c *Controller) ShowCategoryEntry(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -85,8 +82,8 @@ func (c *Controller) ShowCategoryEntry(w http.ResponseWriter, r *http.Request) { prevEntryRoute = route.Path(c.router, "categoryEntry", "categoryID", categoryID, "entryID", prevEntry.ID) } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("entry", entry) view.Set("prevEntry", prevEntry) view.Set("nextEntry", nextEntry) diff --git a/ui/entry_feed.go b/ui/entry_feed.go index be04e14..968c8f4 100644 --- a/ui/entry_feed.go +++ b/ui/entry_feed.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -20,9 +19,7 @@ import ( // ShowFeedEntry shows a single feed entry in "feed" mode. func (c *Controller) ShowFeedEntry(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -85,8 +82,8 @@ func (c *Controller) ShowFeedEntry(w http.ResponseWriter, r *http.Request) { prevEntryRoute = route.Path(c.router, "feedEntry", "feedID", feedID, "entryID", prevEntry.ID) } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("entry", entry) view.Set("prevEntry", prevEntry) view.Set("nextEntry", nextEntry) diff --git a/ui/entry_read.go b/ui/entry_read.go index 3309c81..61c7114 100644 --- a/ui/entry_read.go +++ b/ui/entry_read.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -19,9 +18,7 @@ import ( // ShowReadEntry shows a single feed entry in "history" mode. func (c *Controller) ShowReadEntry(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -66,8 +63,8 @@ func (c *Controller) ShowReadEntry(w http.ResponseWriter, r *http.Request) { prevEntryRoute = route.Path(c.router, "readEntry", "entryID", prevEntry.ID) } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("entry", entry) view.Set("prevEntry", prevEntry) view.Set("nextEntry", nextEntry) diff --git a/ui/entry_save.go b/ui/entry_save.go index 292b526..488022a 100644 --- a/ui/entry_save.go +++ b/ui/entry_save.go @@ -2,13 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "errors" "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/json" "miniflux.app/integration" @@ -23,9 +22,7 @@ func (c *Controller) SaveEntry(w http.ResponseWriter, r *http.Request) { return } - ctx := context.New(r) - - builder := c.store.NewEntryQueryBuilder(ctx.UserID()) + builder := c.store.NewEntryQueryBuilder(request.UserID(r)) builder.WithEntryID(entryID) builder.WithoutStatus(model.EntryStatusRemoved) @@ -40,7 +37,7 @@ func (c *Controller) SaveEntry(w http.ResponseWriter, r *http.Request) { return } - settings, err := c.store.Integration(ctx.UserID()) + settings, err := c.store.Integration(request.UserID(r)) if err != nil { json.ServerError(w, err) return diff --git a/ui/entry_scraper.go b/ui/entry_scraper.go index 52e0846..0082307 100644 --- a/ui/entry_scraper.go +++ b/ui/entry_scraper.go @@ -8,7 +8,6 @@ import ( "errors" "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/json" "miniflux.app/model" @@ -24,8 +23,7 @@ func (c *Controller) FetchContent(w http.ResponseWriter, r *http.Request) { return } - ctx := context.New(r) - builder := c.store.NewEntryQueryBuilder(ctx.UserID()) + builder := c.store.NewEntryQueryBuilder(request.UserID(r)) builder.WithEntryID(entryID) builder.WithoutStatus(model.EntryStatusRemoved) diff --git a/ui/entry_search.go b/ui/entry_search.go index 7e09bbf..15babc1 100644 --- a/ui/entry_search.go +++ b/ui/entry_search.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -20,9 +19,7 @@ import ( // ShowSearchEntry shows a single entry in "search" mode. func (c *Controller) ShowSearchEntry(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -80,8 +77,8 @@ func (c *Controller) ShowSearchEntry(w http.ResponseWriter, r *http.Request) { prevEntryRoute = route.Path(c.router, "searchEntry", "entryID", prevEntry.ID) } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("searchQuery", searchQuery) view.Set("entry", entry) view.Set("prevEntry", prevEntry) diff --git a/ui/entry_toggle_bookmark.go b/ui/entry_toggle_bookmark.go index 13de971..e8e87ca 100644 --- a/ui/entry_toggle_bookmark.go +++ b/ui/entry_toggle_bookmark.go @@ -2,12 +2,11 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/json" "miniflux.app/logger" @@ -21,8 +20,7 @@ func (c *Controller) ToggleBookmark(w http.ResponseWriter, r *http.Request) { return } - ctx := context.New(r) - if err := c.store.ToggleBookmark(ctx.UserID(), entryID); err != nil { + if err := c.store.ToggleBookmark(request.UserID(r), entryID); err != nil { logger.Error("[Controller:ToggleBookmark] %v", err) json.ServerError(w, nil) return diff --git a/ui/entry_unread.go b/ui/entry_unread.go index 0a8c076..30a6d34 100644 --- a/ui/entry_unread.go +++ b/ui/entry_unread.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -20,9 +19,7 @@ import ( // ShowUnreadEntry shows a single feed entry in "unread" mode. func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -86,8 +83,8 @@ func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) { } entry.Status = model.EntryStatusRead - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("entry", entry) view.Set("prevEntry", prevEntry) view.Set("nextEntry", nextEntry) diff --git a/ui/entry_update_status.go b/ui/entry_update_status.go index 4f5c114..8e9de4d 100644 --- a/ui/entry_update_status.go +++ b/ui/entry_update_status.go @@ -2,13 +2,13 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "errors" "net/http" - "miniflux.app/http/context" + "miniflux.app/http/request" "miniflux.app/http/response/json" "miniflux.app/logger" ) @@ -27,8 +27,7 @@ func (c *Controller) UpdateEntriesStatus(w http.ResponseWriter, r *http.Request) return } - ctx := context.New(r) - err = c.store.SetEntriesStatus(ctx.UserID(), entryIDs, status) + err = c.store.SetEntriesStatus(request.UserID(r), entryIDs, status) if err != nil { logger.Error("[Controller:UpdateEntryStatus] %v", err) json.ServerError(w, nil) diff --git a/ui/feed_edit.go b/ui/feed_edit.go index 213bfea..c78ca5e 100644 --- a/ui/feed_edit.go +++ b/ui/feed_edit.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/ui/form" @@ -17,9 +16,7 @@ import ( // EditFeed shows the form to modify a subscription. func (c *Controller) EditFeed(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -60,8 +57,8 @@ func (c *Controller) EditFeed(w http.ResponseWriter, r *http.Request) { Password: feed.Password, } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("form", feedForm) view.Set("categories", categories) view.Set("feed", feed) diff --git a/ui/feed_entries.go b/ui/feed_entries.go index fa18b26..dc0f05d 100644 --- a/ui/feed_entries.go +++ b/ui/feed_entries.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -18,9 +17,7 @@ import ( // ShowFeedEntries shows all entries for the given feed. func (c *Controller) ShowFeedEntries(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -64,8 +61,8 @@ func (c *Controller) ShowFeedEntries(w http.ResponseWriter, r *http.Request) { return } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("feed", feed) view.Set("entries", entries) view.Set("total", count) diff --git a/ui/feed_list.go b/ui/feed_list.go index 553ee55..9fe4aac 100644 --- a/ui/feed_list.go +++ b/ui/feed_list.go @@ -2,12 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" + "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/ui/session" "miniflux.app/ui/view" @@ -15,9 +15,7 @@ import ( // ShowFeedsPage shows the page with all subscriptions. func (c *Controller) ShowFeedsPage(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -29,8 +27,8 @@ func (c *Controller) ShowFeedsPage(w http.ResponseWriter, r *http.Request) { return } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("feeds", feeds) view.Set("total", len(feeds)) view.Set("menu", "feeds") diff --git a/ui/feed_refresh.go b/ui/feed_refresh.go index 634edfa..d9da238 100644 --- a/ui/feed_refresh.go +++ b/ui/feed_refresh.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" @@ -23,8 +22,7 @@ func (c *Controller) RefreshFeed(w http.ResponseWriter, r *http.Request) { return } - ctx := context.New(r) - if err := c.feedHandler.RefreshFeed(ctx.UserID(), feedID); err != nil { + if err := c.feedHandler.RefreshFeed(request.UserID(r), feedID); err != nil { logger.Error("[Controller:RefreshFeed] %v", err) } @@ -33,7 +31,7 @@ func (c *Controller) RefreshFeed(w http.ResponseWriter, r *http.Request) { // RefreshAllFeeds refresh all feeds in the background for the current user. func (c *Controller) RefreshAllFeeds(w http.ResponseWriter, r *http.Request) { - userID := context.New(r).UserID() + userID := request.UserID(r) jobs, err := c.store.NewUserBatch(userID, c.store.CountFeeds(userID)) if err != nil { html.ServerError(w, err) diff --git a/ui/feed_remove.go b/ui/feed_remove.go index 4a7294e..9071a33 100644 --- a/ui/feed_remove.go +++ b/ui/feed_remove.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" @@ -22,8 +21,7 @@ func (c *Controller) RemoveFeed(w http.ResponseWriter, r *http.Request) { return } - ctx := context.New(r) - if err := c.store.RemoveFeed(ctx.UserID(), feedID); err != nil { + if err := c.store.RemoveFeed(request.UserID(r), feedID); err != nil { html.ServerError(w, err) return } diff --git a/ui/feed_update.go b/ui/feed_update.go index 474f7e9..fc3a9a2 100644 --- a/ui/feed_update.go +++ b/ui/feed_update.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" @@ -20,9 +19,7 @@ import ( // UpdateFeed update a subscription and redirect to the feed entries page. func (c *Controller) UpdateFeed(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -53,8 +50,8 @@ func (c *Controller) UpdateFeed(w http.ResponseWriter, r *http.Request) { feedForm := form.NewFeedForm(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("form", feedForm) view.Set("categories", categories) view.Set("feed", feed) diff --git a/ui/history_entries.go b/ui/history_entries.go index de12539..25310a9 100644 --- a/ui/history_entries.go +++ b/ui/history_entries.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -18,9 +17,7 @@ import ( // ShowHistoryPage renders the page with all read entries. func (c *Controller) ShowHistoryPage(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -46,8 +43,8 @@ func (c *Controller) ShowHistoryPage(w http.ResponseWriter, r *http.Request) { return } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("entries", entries) view.Set("total", count) view.Set("pagination", c.getPagination(route.Path(c.router, "history"), count, offset)) diff --git a/ui/history_flush.go b/ui/history_flush.go index 0776f9c..5bb8910 100644 --- a/ui/history_flush.go +++ b/ui/history_flush.go @@ -2,12 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" + "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -15,7 +15,7 @@ import ( // FlushHistory changes all "read" items to "removed". func (c *Controller) FlushHistory(w http.ResponseWriter, r *http.Request) { - err := c.store.FlushHistory(context.New(r).UserID()) + err := c.store.FlushHistory(request.UserID(r)) if err != nil { html.ServerError(w, err) return diff --git a/ui/integration_pocket.go b/ui/integration_pocket.go index 62d3ddc..cce83b3 100644 --- a/ui/integration_pocket.go +++ b/ui/integration_pocket.go @@ -7,8 +7,8 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/response" + "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/integration/pocket" @@ -18,9 +18,7 @@ import ( // PocketAuthorize redirects the end-user to Pocket website to authorize the application. func (c *Controller) PocketAuthorize(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -32,13 +30,13 @@ func (c *Controller) PocketAuthorize(w http.ResponseWriter, r *http.Request) { return } - sess := session.New(c.store, ctx) + sess := session.New(c.store, request.SessionID(r)) connector := pocket.NewConnector(c.cfg.PocketConsumerKey(integration.PocketConsumerKey)) redirectURL := c.cfg.BaseURL() + route.Path(c.router, "pocketCallback") requestToken, err := connector.RequestToken(redirectURL) if err != nil { logger.Error("[Pocket:Authorize] %v", err) - sess.NewFlashErrorMessage(c.translator.GetLanguage(ctx.UserLanguage()).Get("Unable to fetch request token from Pocket!")) + sess.NewFlashErrorMessage(c.translator.GetLanguage(request.UserLanguage(r)).Get("Unable to fetch request token from Pocket!")) response.Redirect(w, r, route.Path(c.router, "integrations")) return } @@ -49,10 +47,9 @@ func (c *Controller) PocketAuthorize(w http.ResponseWriter, r *http.Request) { // PocketCallback saves the personal access token after the authorization step. func (c *Controller) PocketCallback(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) + sess := session.New(c.store, request.SessionID(r)) - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -65,10 +62,10 @@ func (c *Controller) PocketCallback(w http.ResponseWriter, r *http.Request) { } connector := pocket.NewConnector(c.cfg.PocketConsumerKey(integration.PocketConsumerKey)) - accessToken, err := connector.AccessToken(ctx.PocketRequestToken()) + accessToken, err := connector.AccessToken(request.PocketRequestToken(r)) if err != nil { logger.Error("[Pocket:Callback] %v", err) - sess.NewFlashErrorMessage(c.translator.GetLanguage(ctx.UserLanguage()).Get("Unable to fetch access token from Pocket!")) + sess.NewFlashErrorMessage(c.translator.GetLanguage(request.UserLanguage(r)).Get("Unable to fetch access token from Pocket!")) response.Redirect(w, r, route.Path(c.router, "integrations")) return } @@ -82,6 +79,6 @@ func (c *Controller) PocketCallback(w http.ResponseWriter, r *http.Request) { return } - sess.NewFlashMessage(c.translator.GetLanguage(ctx.UserLanguage()).Get("Your Pocket account is now linked!")) + sess.NewFlashMessage(c.translator.GetLanguage(request.UserLanguage(r)).Get("Your Pocket account is now linked!")) response.Redirect(w, r, route.Path(c.router, "integrations")) } diff --git a/ui/integration_show.go b/ui/integration_show.go index 0ae3eee..1c8adce 100644 --- a/ui/integration_show.go +++ b/ui/integration_show.go @@ -7,7 +7,7 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" + "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/ui/form" "miniflux.app/ui/session" @@ -16,9 +16,7 @@ import ( // ShowIntegrations renders the page with all external integrations. func (c *Controller) ShowIntegrations(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -55,8 +53,8 @@ func (c *Controller) ShowIntegrations(w http.ResponseWriter, r *http.Request) { PocketConsumerKey: integration.PocketConsumerKey, } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("form", integrationForm) view.Set("menu", "settings") view.Set("user", user) diff --git a/ui/integration_update.go b/ui/integration_update.go index 22c9000..e6d4a67 100644 --- a/ui/integration_update.go +++ b/ui/integration_update.go @@ -9,8 +9,8 @@ import ( "fmt" "net/http" - "miniflux.app/http/context" "miniflux.app/http/response" + "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/ui/form" @@ -19,10 +19,8 @@ import ( // UpdateIntegration updates integration settings. func (c *Controller) UpdateIntegration(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - - user, err := c.store.UserByID(ctx.UserID()) + sess := session.New(c.store, request.SessionID(r)) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -38,7 +36,7 @@ func (c *Controller) UpdateIntegration(w http.ResponseWriter, r *http.Request) { integrationForm.Merge(integration) if integration.FeverUsername != "" && c.store.HasDuplicateFeverUsername(user.ID, integration.FeverUsername) { - sess.NewFlashErrorMessage(c.translator.GetLanguage(ctx.UserLanguage()).Get("There is already someone else with the same Fever username!")) + sess.NewFlashErrorMessage(c.translator.GetLanguage(request.UserLanguage(r)).Get("There is already someone else with the same Fever username!")) response.Redirect(w, r, route.Path(c.router, "integrations")) return } @@ -55,6 +53,6 @@ func (c *Controller) UpdateIntegration(w http.ResponseWriter, r *http.Request) { return } - sess.NewFlashMessage(c.translator.GetLanguage(ctx.UserLanguage()).Get("Preferences saved!")) + sess.NewFlashMessage(c.translator.GetLanguage(request.UserLanguage(r)).Get("Preferences saved!")) response.Redirect(w, r, route.Path(c.router, "integrations")) } diff --git a/ui/login_check.go b/ui/login_check.go index a2f2826..95c5908 100644 --- a/ui/login_check.go +++ b/ui/login_check.go @@ -3,7 +3,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/cookie" "miniflux.app/http/request" "miniflux.app/http/response" @@ -18,13 +17,10 @@ import ( // CheckLogin validates the username/password and redirects the user to the unread page. func (c *Controller) CheckLogin(w http.ResponseWriter, r *http.Request) { remoteAddr := request.RealIP(r) - - ctx := context.New(r) - sess := session.New(c.store, ctx) - + sess := session.New(c.store, request.SessionID(r)) authForm := form.NewAuthForm(r) - view := view.New(c.tpl, ctx, sess) + view := view.New(c.tpl, r, sess) view.Set("errorMessage", "Invalid username or password.") view.Set("form", authForm) diff --git a/ui/login_show.go b/ui/login_show.go index d963df5..82c19ec 100644 --- a/ui/login_show.go +++ b/ui/login_show.go @@ -7,8 +7,8 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/response" + "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/ui/session" @@ -17,13 +17,12 @@ import ( // ShowLoginPage shows the login form. func (c *Controller) ShowLoginPage(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - if ctx.IsAuthenticated() { + if request.IsAuthenticated(r) { response.Redirect(w, r, route.Path(c.router, "unread")) return } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) html.OK(w, r, view.Render("login")) } diff --git a/ui/logout.go b/ui/logout.go index e610282..0c8e9e7 100644 --- a/ui/logout.go +++ b/ui/logout.go @@ -7,8 +7,8 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/cookie" + "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -18,10 +18,8 @@ import ( // Logout destroy the session and redirects the user to the login page. func (c *Controller) Logout(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - - user, err := c.store.UserByID(ctx.UserID()) + sess := session.New(c.store, request.SessionID(r)) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -30,7 +28,7 @@ func (c *Controller) Logout(w http.ResponseWriter, r *http.Request) { sess.SetLanguage(user.Language) sess.SetTheme(user.Theme) - if err := c.store.RemoveUserSessionByToken(user.ID, ctx.UserSessionToken()); err != nil { + if err := c.store.RemoveUserSessionByToken(user.ID, request.UserSessionToken(r)); err != nil { logger.Error("[Controller:Logout] %v", err) } diff --git a/ui/oauth2_callback.go b/ui/oauth2_callback.go index 4e0cd74..b1bb933 100644 --- a/ui/oauth2_callback.go +++ b/ui/oauth2_callback.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/cookie" "miniflux.app/http/request" "miniflux.app/http/response" @@ -20,8 +19,7 @@ import ( // OAuth2Callback receives the authorization code and create a new session. func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) + sess := session.New(c.store, request.SessionID(r)) provider := request.Param(r, "provider", "") if provider == "" { @@ -38,8 +36,8 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) { } state := request.QueryParam(r, "state", "") - if state == "" || state != ctx.OAuth2State() { - logger.Error(`[OAuth2] Invalid state value: got "%s" instead of "%s"`, state, ctx.OAuth2State()) + if state == "" || state != request.OAuth2State(r) { + logger.Error(`[OAuth2] Invalid state value: got "%s" instead of "%s"`, state, request.OAuth2State(r)) response.Redirect(w, r, route.Path(c.router, "login")) return } @@ -58,7 +56,7 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) { return } - if ctx.IsAuthenticated() { + if request.IsAuthenticated(r) { user, err := c.store.UserByExtraField(profile.Key, profile.ID) if err != nil { html.ServerError(w, err) @@ -66,18 +64,18 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) { } if user != nil { - logger.Error("[OAuth2] User #%d cannot be associated because %s is already associated", ctx.UserID(), user.Username) - sess.NewFlashErrorMessage(c.translator.GetLanguage(ctx.UserLanguage()).Get("There is already someone associated with this provider!")) + logger.Error("[OAuth2] User #%d cannot be associated because %s is already associated", request.UserID(r), user.Username) + sess.NewFlashErrorMessage(c.translator.GetLanguage(request.UserLanguage(r)).Get("There is already someone associated with this provider!")) response.Redirect(w, r, route.Path(c.router, "settings")) return } - if err := c.store.UpdateExtraField(ctx.UserID(), profile.Key, profile.ID); err != nil { + if err := c.store.UpdateExtraField(request.UserID(r), profile.Key, profile.ID); err != nil { html.ServerError(w, err) return } - sess.NewFlashMessage(c.translator.GetLanguage(ctx.UserLanguage()).Get("Your external account is now linked!")) + sess.NewFlashMessage(c.translator.GetLanguage(request.UserLanguage(r)).Get("Your external account is now linked!")) response.Redirect(w, r, route.Path(c.router, "settings")) return } diff --git a/ui/oauth2_redirect.go b/ui/oauth2_redirect.go index 08f065d..3b7c88a 100644 --- a/ui/oauth2_redirect.go +++ b/ui/oauth2_redirect.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/route" @@ -17,8 +16,7 @@ import ( // OAuth2Redirect redirects the user to the consent page to ask for permission. func (c *Controller) OAuth2Redirect(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) + sess := session.New(c.store, request.SessionID(r)) provider := request.Param(r, "provider", "") if provider == "" { diff --git a/ui/oauth2_unlink.go b/ui/oauth2_unlink.go index e0dbd16..bf76f05 100644 --- a/ui/oauth2_unlink.go +++ b/ui/oauth2_unlink.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" @@ -32,26 +31,25 @@ func (c *Controller) OAuth2Unlink(w http.ResponseWriter, r *http.Request) { return } - ctx := context.New(r) - sess := session.New(c.store, ctx) + sess := session.New(c.store, request.SessionID(r)) - hasPassword, err := c.store.HasPassword(ctx.UserID()) + hasPassword, err := c.store.HasPassword(request.UserID(r)) if err != nil { html.ServerError(w, err) return } if !hasPassword { - sess.NewFlashErrorMessage(c.translator.GetLanguage(ctx.UserLanguage()).Get("You must define a password otherwise you won't be able to login again.")) + sess.NewFlashErrorMessage(c.translator.GetLanguage(request.UserLanguage(r)).Get("You must define a password otherwise you won't be able to login again.")) response.Redirect(w, r, route.Path(c.router, "settings")) return } - if err := c.store.RemoveExtraField(ctx.UserID(), authProvider.GetUserExtraKey()); err != nil { + if err := c.store.RemoveExtraField(request.UserID(r), authProvider.GetUserExtraKey()); err != nil { html.ServerError(w, err) return } - sess.NewFlashMessage(c.translator.GetLanguage(ctx.UserLanguage()).Get("Your external account is now dissociated!")) + sess.NewFlashMessage(c.translator.GetLanguage(request.UserLanguage(r)).Get("Your external account is now dissociated!")) response.Redirect(w, r, route.Path(c.router, "settings")) } diff --git a/ui/opml_export.go b/ui/opml_export.go index 561c6c3..20194b0 100644 --- a/ui/opml_export.go +++ b/ui/opml_export.go @@ -2,12 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" + "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/response/xml" "miniflux.app/reader/opml" @@ -15,8 +15,7 @@ import ( // Export generates the OPML file. func (c *Controller) Export(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - opml, err := opml.NewHandler(c.store).Export(ctx.UserID()) + opml, err := opml.NewHandler(c.store).Export(request.UserID(r)) if err != nil { html.ServerError(w, err) return diff --git a/ui/opml_import.go b/ui/opml_import.go index 6e0f746..a8e732e 100644 --- a/ui/opml_import.go +++ b/ui/opml_import.go @@ -7,7 +7,7 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" + "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/ui/session" "miniflux.app/ui/view" @@ -15,16 +15,14 @@ import ( // Import shows the import form. func (c *Controller) Import(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("menu", "feeds") view.Set("user", user) view.Set("countUnread", c.store.CountUnreadEntries(user.ID)) diff --git a/ui/opml_upload.go b/ui/opml_upload.go index 414c7e3..86150fd 100644 --- a/ui/opml_upload.go +++ b/ui/opml_upload.go @@ -7,7 +7,7 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" + "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -19,9 +19,7 @@ import ( // UploadOPML handles OPML file importation. func (c *Controller) UploadOPML(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -42,8 +40,8 @@ func (c *Controller) UploadOPML(w http.ResponseWriter, r *http.Request) { fileHeader.Size, ) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("menu", "feeds") view.Set("user", user) view.Set("countUnread", c.store.CountUnreadEntries(user.ID)) diff --git a/ui/search_entries.go b/ui/search_entries.go index e6b533e..3f17ede 100644 --- a/ui/search_entries.go +++ b/ui/search_entries.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -18,9 +17,7 @@ import ( // ShowSearchEntries shows all entries for the given feed. func (c *Controller) ShowSearchEntries(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -48,8 +45,8 @@ func (c *Controller) ShowSearchEntries(w http.ResponseWriter, r *http.Request) { return } - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) pagination := c.getPagination(route.Path(c.router, "searchEntries"), count, offset) pagination.SearchQuery = searchQuery diff --git a/ui/session/session.go b/ui/session/session.go index f6a35c2..2351866 100644 --- a/ui/session/session.go +++ b/ui/session/session.go @@ -6,67 +6,64 @@ package session // import "miniflux.app/ui/session" import ( "miniflux.app/crypto" - "miniflux.app/http/context" "miniflux.app/storage" ) // Session handles session data. type Session struct { - store *storage.Storage - ctx *context.Context + store *storage.Storage + sessionID string } // NewOAuth2State generates a new OAuth2 state and stores the value into the database. func (s *Session) NewOAuth2State() string { state := crypto.GenerateRandomString(32) - s.store.UpdateSessionField(s.ctx.SessionID(), "oauth2_state", state) + s.store.UpdateSessionField(s.sessionID, "oauth2_state", state) return state } // NewFlashMessage creates a new flash message. func (s *Session) NewFlashMessage(message string) { - s.store.UpdateSessionField(s.ctx.SessionID(), "flash_message", message) + s.store.UpdateSessionField(s.sessionID, "flash_message", message) } // FlashMessage returns the current flash message if any. -func (s *Session) FlashMessage() string { - message := s.ctx.FlashMessage() +func (s *Session) FlashMessage(message string) string { if message != "" { - s.store.UpdateSessionField(s.ctx.SessionID(), "flash_message", "") + s.store.UpdateSessionField(s.sessionID, "flash_message", "") } return message } // NewFlashErrorMessage creates a new flash error message. func (s *Session) NewFlashErrorMessage(message string) { - s.store.UpdateSessionField(s.ctx.SessionID(), "flash_error_message", message) + s.store.UpdateSessionField(s.sessionID, "flash_error_message", message) } // FlashErrorMessage returns the last flash error message if any. -func (s *Session) FlashErrorMessage() string { - message := s.ctx.FlashErrorMessage() +func (s *Session) FlashErrorMessage(message string) string { if message != "" { - s.store.UpdateSessionField(s.ctx.SessionID(), "flash_error_message", "") + s.store.UpdateSessionField(s.sessionID, "flash_error_message", "") } return message } // SetLanguage updates the language field in session. func (s *Session) SetLanguage(language string) { - s.store.UpdateSessionField(s.ctx.SessionID(), "language", language) + s.store.UpdateSessionField(s.sessionID, "language", language) } // SetTheme updates the theme field in session. func (s *Session) SetTheme(theme string) { - s.store.UpdateSessionField(s.ctx.SessionID(), "theme", theme) + s.store.UpdateSessionField(s.sessionID, "theme", theme) } // SetPocketRequestToken updates Pocket Request Token. func (s *Session) SetPocketRequestToken(requestToken string) { - s.store.UpdateSessionField(s.ctx.SessionID(), "pocket_request_token", requestToken) + s.store.UpdateSessionField(s.sessionID, "pocket_request_token", requestToken) } // New returns a new session handler. -func New(store *storage.Storage, ctx *context.Context) *Session { - return &Session{store, ctx} +func New(store *storage.Storage, sessionID string) *Session { + return &Session{store, sessionID} } diff --git a/ui/session_list.go b/ui/session_list.go index 3cb8d94..3f5bf9e 100644 --- a/ui/session_list.go +++ b/ui/session_list.go @@ -7,20 +7,18 @@ package ui // import "miniflux.app/ui" import ( "net/http" + "miniflux.app/http/request" "miniflux.app/ui/session" "miniflux.app/ui/view" - - "miniflux.app/http/context" "miniflux.app/http/response/html" ) // ShowSessions shows the list of active user sessions. func (c *Controller) ShowSessions(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -34,7 +32,7 @@ func (c *Controller) ShowSessions(w http.ResponseWriter, r *http.Request) { sessions.UseTimezone(user.Timezone) - view.Set("currentSessionToken", ctx.UserSessionToken()) + view.Set("currentSessionToken", request.UserSessionToken(r)) view.Set("sessions", sessions) view.Set("menu", "settings") view.Set("user", user) diff --git a/ui/session_remove.go b/ui/session_remove.go index 6bec368..f08cd3d 100644 --- a/ui/session_remove.go +++ b/ui/session_remove.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" @@ -17,15 +16,13 @@ import ( // RemoveSession remove a user session. func (c *Controller) RemoveSession(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sessionID, err := request.IntParam(r, "sessionID") if err != nil { html.BadRequest(w, err) return } - err = c.store.RemoveUserSessionByID(ctx.UserID(), sessionID) + err = c.store.RemoveUserSessionByID(request.UserID(r), sessionID) if err != nil { logger.Error("[Controller:RemoveSession] %v", err) } diff --git a/ui/settings_show.go b/ui/settings_show.go index e079c65..07703eb 100644 --- a/ui/settings_show.go +++ b/ui/settings_show.go @@ -7,7 +7,7 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" + "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/locale" "miniflux.app/model" @@ -18,11 +18,10 @@ import ( // ShowSettings shows the settings page. func (c *Controller) ShowSettings(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return diff --git a/ui/settings_update.go b/ui/settings_update.go index 564afe2..e57f3b0 100644 --- a/ui/settings_update.go +++ b/ui/settings_update.go @@ -7,9 +7,9 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/response" "miniflux.app/http/response/html" + "miniflux.app/http/request" "miniflux.app/http/route" "miniflux.app/locale" "miniflux.app/logger" @@ -21,11 +21,10 @@ import ( // UpdateSettings update the settings. func (c *Controller) UpdateSettings(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -70,6 +69,6 @@ func (c *Controller) UpdateSettings(w http.ResponseWriter, r *http.Request) { sess.SetLanguage(user.Language) sess.SetTheme(user.Theme) - sess.NewFlashMessage(c.translator.GetLanguage(ctx.UserLanguage()).Get("Preferences saved!")) + sess.NewFlashMessage(c.translator.GetLanguage(request.UserLanguage(r)).Get("Preferences saved!")) response.Redirect(w, r, route.Path(c.router, "settings")) } diff --git a/ui/static_manifest.go b/ui/static_manifest.go index f8f6ac0..51369a2 100644 --- a/ui/static_manifest.go +++ b/ui/static_manifest.go @@ -2,12 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" + "miniflux.app/http/request" "miniflux.app/http/response/json" "miniflux.app/http/route" "miniflux.app/model" @@ -32,9 +32,7 @@ func (c *Controller) WebManifest(w http.ResponseWriter, r *http.Request) { BackgroundColor string `json:"background_color"` } - ctx := context.New(r) - themeColor := model.ThemeColor(ctx.UserTheme()) - + themeColor := model.ThemeColor(request.UserTheme(r)) manifest := &webManifest{ Name: "Miniflux", ShortName: "Miniflux", diff --git a/ui/subscription_add.go b/ui/subscription_add.go index f78c7c6..1639d0d 100644 --- a/ui/subscription_add.go +++ b/ui/subscription_add.go @@ -7,19 +7,18 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/response/html" + "miniflux.app/http/request" "miniflux.app/ui/session" "miniflux.app/ui/view" ) // AddSubscription shows the form to add a new feed. func (c *Controller) AddSubscription(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return diff --git a/ui/subscription_bookmarklet.go b/ui/subscription_bookmarklet.go index 889ae42..dd0d11f 100644 --- a/ui/subscription_bookmarklet.go +++ b/ui/subscription_bookmarklet.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/ui/form" @@ -17,11 +16,10 @@ import ( // Bookmarklet prefill the form to add a subscription from the URL provided by the bookmarklet. func (c *Controller) Bookmarklet(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return diff --git a/ui/subscription_choose.go b/ui/subscription_choose.go index 0deec54..f1cdfcb 100644 --- a/ui/subscription_choose.go +++ b/ui/subscription_choose.go @@ -7,9 +7,9 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/response" "miniflux.app/http/response/html" + "miniflux.app/http/request" "miniflux.app/http/route" "miniflux.app/ui/form" "miniflux.app/ui/session" @@ -18,11 +18,10 @@ import ( // ChooseSubscription shows a page to choose a subscription. func (c *Controller) ChooseSubscription(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return diff --git a/ui/subscription_submit.go b/ui/subscription_submit.go index fe61513..c6e8a95 100644 --- a/ui/subscription_submit.go +++ b/ui/subscription_submit.go @@ -7,9 +7,9 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/response" "miniflux.app/http/response/html" + "miniflux.app/http/request" "miniflux.app/http/route" "miniflux.app/logger" "miniflux.app/reader/subscription" @@ -20,11 +20,10 @@ import ( // SubmitSubscription try to find a feed from the URL provided by the user. func (c *Controller) SubmitSubscription(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - v := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + v := view.New(c.tpl, r, sess) - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -89,7 +88,7 @@ func (c *Controller) SubmitSubscription(w http.ResponseWriter, r *http.Request) response.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feed.ID)) case n > 1: - v := view.New(c.tpl, ctx, sess) + v := view.New(c.tpl, r, sess) v.Set("subscriptions", subscriptions) v.Set("form", subscriptionForm) v.Set("menu", "feeds") diff --git a/ui/unread_entries.go b/ui/unread_entries.go index 77f153d..5992162 100644 --- a/ui/unread_entries.go +++ b/ui/unread_entries.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -18,11 +17,10 @@ import ( // ShowUnreadPage render the page with all unread entries. func (c *Controller) ShowUnreadPage(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return diff --git a/ui/unread_mark_all_read.go b/ui/unread_mark_all_read.go index 7d47523..c467923 100644 --- a/ui/unread_mark_all_read.go +++ b/ui/unread_mark_all_read.go @@ -2,12 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" + "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/route" "miniflux.app/logger" @@ -15,7 +15,7 @@ import ( // MarkAllAsRead marks all unread entries as read. func (c *Controller) MarkAllAsRead(w http.ResponseWriter, r *http.Request) { - if err := c.store.MarkAllAsRead(context.New(r).UserID()); err != nil { + if err := c.store.MarkAllAsRead(request.UserID(r)); err != nil { logger.Error("[MarkAllAsRead] %v", err) } diff --git a/ui/user_create.go b/ui/user_create.go index 07cd819..b31b0de 100644 --- a/ui/user_create.go +++ b/ui/user_create.go @@ -2,12 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" + "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/ui/form" "miniflux.app/ui/session" @@ -16,11 +16,10 @@ import ( // CreateUser shows the user creation form. func (c *Controller) CreateUser(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return diff --git a/ui/user_edit.go b/ui/user_edit.go index 00f1acb..79e6d4a 100644 --- a/ui/user_edit.go +++ b/ui/user_edit.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/ui/form" @@ -17,11 +16,10 @@ import ( // EditUser shows the form to edit a user. func (c *Controller) EditUser(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return diff --git a/ui/user_list.go b/ui/user_list.go index 040ac7c..dce30e0 100644 --- a/ui/user_list.go +++ b/ui/user_list.go @@ -7,19 +7,18 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/response/html" + "miniflux.app/http/request" "miniflux.app/ui/session" "miniflux.app/ui/view" ) // ShowUsers renders the list of users. func (c *Controller) ShowUsers(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return diff --git a/ui/user_remove.go b/ui/user_remove.go index 63d2c46..4b5440d 100644 --- a/ui/user_remove.go +++ b/ui/user_remove.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" @@ -16,9 +15,7 @@ import ( // RemoveUser deletes a user from the database. func (c *Controller) RemoveUser(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return diff --git a/ui/user_save.go b/ui/user_save.go index a9167d2..a871dab 100644 --- a/ui/user_save.go +++ b/ui/user_save.go @@ -7,9 +7,9 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/response" "miniflux.app/http/response/html" + "miniflux.app/http/request" "miniflux.app/http/route" "miniflux.app/logger" "miniflux.app/ui/form" @@ -19,9 +19,7 @@ import ( // SaveUser validate and save the new user into the database. func (c *Controller) SaveUser(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -34,8 +32,8 @@ func (c *Controller) SaveUser(w http.ResponseWriter, r *http.Request) { userForm := form.NewUserForm(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("menu", "settings") view.Set("user", user) view.Set("countUnread", c.store.CountUnreadEntries(user.ID)) diff --git a/ui/user_update.go b/ui/user_update.go index 6881167..4882b47 100644 --- a/ui/user_update.go +++ b/ui/user_update.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" @@ -20,9 +19,7 @@ import ( // UpdateUser validate and update a user. func (c *Controller) UpdateUser(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - - user, err := c.store.UserByID(ctx.UserID()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { html.ServerError(w, err) return @@ -52,8 +49,8 @@ func (c *Controller) UpdateUser(w http.ResponseWriter, r *http.Request) { userForm := form.NewUserForm(r) - sess := session.New(c.store, ctx) - view := view.New(c.tpl, ctx, sess) + sess := session.New(c.store, request.SessionID(r)) + view := view.New(c.tpl, r, sess) view.Set("menu", "settings") view.Set("user", user) view.Set("countUnread", c.store.CountUnreadEntries(user.ID)) diff --git a/ui/view/view.go b/ui/view/view.go index 0351756..a54961a 100644 --- a/ui/view/view.go +++ b/ui/view/view.go @@ -5,7 +5,9 @@ package view // import "miniflux.app/ui/view" import ( - "miniflux.app/http/context" + "net/http" + + "miniflux.app/http/request" "miniflux.app/template" "miniflux.app/ui/session" "miniflux.app/ui/static" @@ -14,7 +16,7 @@ import ( // View wraps template argument building. type View struct { tpl *template.Engine - ctx *context.Context + r *http.Request params map[string]interface{} } @@ -26,17 +28,17 @@ func (v *View) Set(param string, value interface{}) *View { // Render executes the template with arguments. func (v *View) Render(template string) []byte { - return v.tpl.Render(template, v.ctx.UserLanguage(), v.params) + return v.tpl.Render(template, request.UserLanguage(v.r), v.params) } // New returns a new view with default parameters. -func New(tpl *template.Engine, ctx *context.Context, sess *session.Session) *View { - b := &View{tpl, ctx, make(map[string]interface{})} - theme := ctx.UserTheme() +func New(tpl *template.Engine, r *http.Request, sess *session.Session) *View { + b := &View{tpl, r, make(map[string]interface{})} + theme := request.UserTheme(r) b.params["menu"] = "" - b.params["csrf"] = ctx.CSRF() - b.params["flashMessage"] = sess.FlashMessage() - b.params["flashErrorMessage"] = sess.FlashErrorMessage() + b.params["csrf"] = request.CSRF(r) + b.params["flashMessage"] = sess.FlashMessage(request.FlashMessage(r)) + b.params["flashErrorMessage"] = sess.FlashErrorMessage(request.FlashErrorMessage(r)) b.params["theme"] = theme b.params["theme_checksum"] = static.StylesheetsChecksums[theme] b.params["app_js_checksum"] = static.JavascriptsChecksums["app"] |