diff options
author | Frédéric Guillot <fred@miniflux.net> | 2017-11-21 18:37:08 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2017-11-21 18:37:08 -0800 |
commit | 1bc43ec2bc2282d9e18ca622444d45f09c1b6378 (patch) | |
tree | acadc7a1bbbc508c0beee3bdb48879820eb1c2f0 | |
parent | 02ff7b4bcf2b2c691e55ae61fe97bfd9ae37658e (diff) |
Improve Context to be more idiomatic
-rw-r--r-- | server/api/controller/category.go | 8 | ||||
-rw-r--r-- | server/api/controller/entry.go | 12 | ||||
-rw-r--r-- | server/api/controller/feed.go | 12 | ||||
-rw-r--r-- | server/core/context.go | 33 | ||||
-rw-r--r-- | server/core/handler.go | 2 | ||||
-rw-r--r-- | server/ui/controller/category.go | 22 | ||||
-rw-r--r-- | server/ui/controller/controller.go | 4 | ||||
-rw-r--r-- | server/ui/controller/entry.go | 26 | ||||
-rw-r--r-- | server/ui/controller/feed.go | 20 | ||||
-rw-r--r-- | server/ui/controller/history.go | 8 | ||||
-rw-r--r-- | server/ui/controller/login.go | 12 | ||||
-rw-r--r-- | server/ui/controller/opml.go | 8 | ||||
-rw-r--r-- | server/ui/controller/session.go | 6 | ||||
-rw-r--r-- | server/ui/controller/settings.go | 6 | ||||
-rw-r--r-- | server/ui/controller/subscription.go | 10 | ||||
-rw-r--r-- | server/ui/controller/unread.go | 6 | ||||
-rw-r--r-- | server/ui/controller/user.go | 18 |
17 files changed, 107 insertions, 106 deletions
diff --git a/server/api/controller/category.go b/server/api/controller/category.go index deaa273..bf89411 100644 --- a/server/api/controller/category.go +++ b/server/api/controller/category.go @@ -18,7 +18,7 @@ func (c *Controller) CreateCategory(ctx *core.Context, request *core.Request, re return } - category.UserID = ctx.GetUserID() + category.UserID = ctx.UserID() if err := category.ValidateCategoryCreation(); err != nil { response.JSON().ServerError(err) return @@ -47,7 +47,7 @@ func (c *Controller) UpdateCategory(ctx *core.Context, request *core.Request, re return } - category.UserID = ctx.GetUserID() + category.UserID = ctx.UserID() category.ID = categoryID if err := category.ValidateCategoryModification(); err != nil { response.JSON().BadRequest(err) @@ -65,7 +65,7 @@ func (c *Controller) UpdateCategory(ctx *core.Context, request *core.Request, re // GetCategories is the API handler to get a list of categories for a given user. func (c *Controller) GetCategories(ctx *core.Context, request *core.Request, response *core.Response) { - categories, err := c.store.GetCategories(ctx.GetUserID()) + categories, err := c.store.GetCategories(ctx.UserID()) if err != nil { response.JSON().ServerError(errors.New("Unable to fetch categories")) return @@ -76,7 +76,7 @@ func (c *Controller) GetCategories(ctx *core.Context, request *core.Request, res // RemoveCategory is the API handler to remove a category. func (c *Controller) RemoveCategory(ctx *core.Context, request *core.Request, response *core.Response) { - userID := ctx.GetUserID() + userID := ctx.UserID() categoryID, err := request.IntegerParam("categoryID") if err != nil { response.JSON().BadRequest(err) diff --git a/server/api/controller/entry.go b/server/api/controller/entry.go index d5f5b18..54d52ba 100644 --- a/server/api/controller/entry.go +++ b/server/api/controller/entry.go @@ -13,7 +13,7 @@ import ( // GetEntry is the API handler to get a single feed entry. func (c *Controller) GetEntry(ctx *core.Context, request *core.Request, response *core.Response) { - userID := ctx.GetUserID() + userID := ctx.UserID() feedID, err := request.IntegerParam("feedID") if err != nil { response.JSON().BadRequest(err) @@ -26,7 +26,7 @@ func (c *Controller) GetEntry(ctx *core.Context, request *core.Request, response return } - builder := c.store.GetEntryQueryBuilder(userID, ctx.GetUserTimezone()) + builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone()) builder.WithFeedID(feedID) builder.WithEntryID(entryID) @@ -46,7 +46,7 @@ func (c *Controller) GetEntry(ctx *core.Context, request *core.Request, response // GetFeedEntries is the API handler to get all feed entries. func (c *Controller) GetFeedEntries(ctx *core.Context, request *core.Request, response *core.Response) { - userID := ctx.GetUserID() + userID := ctx.UserID() feedID, err := request.IntegerParam("feedID") if err != nil { response.JSON().BadRequest(err) @@ -76,7 +76,7 @@ func (c *Controller) GetFeedEntries(ctx *core.Context, request *core.Request, re limit := request.QueryIntegerParam("limit", 100) offset := request.QueryIntegerParam("offset", 0) - builder := c.store.GetEntryQueryBuilder(userID, ctx.GetUserTimezone()) + builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone()) builder.WithFeedID(feedID) builder.WithStatus(status) builder.WithOrder(model.DefaultSortingOrder) @@ -101,7 +101,7 @@ func (c *Controller) GetFeedEntries(ctx *core.Context, request *core.Request, re // SetEntryStatus is the API handler to change the status of an entry. func (c *Controller) SetEntryStatus(ctx *core.Context, request *core.Request, response *core.Response) { - userID := ctx.GetUserID() + userID := ctx.UserID() feedID, err := request.IntegerParam("feedID") if err != nil { @@ -126,7 +126,7 @@ func (c *Controller) SetEntryStatus(ctx *core.Context, request *core.Request, re return } - builder := c.store.GetEntryQueryBuilder(userID, ctx.GetUserTimezone()) + builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone()) builder.WithFeedID(feedID) builder.WithEntryID(entryID) diff --git a/server/api/controller/feed.go b/server/api/controller/feed.go index 8ec0e04..6a779c3 100644 --- a/server/api/controller/feed.go +++ b/server/api/controller/feed.go @@ -12,7 +12,7 @@ import ( // CreateFeed is the API handler to create a new feed. func (c *Controller) CreateFeed(ctx *core.Context, request *core.Request, response *core.Response) { - userID := ctx.GetUserID() + userID := ctx.UserID() feedURL, categoryID, err := payload.DecodeFeedCreationPayload(request.Body()) if err != nil { response.JSON().BadRequest(err) @@ -30,7 +30,7 @@ func (c *Controller) CreateFeed(ctx *core.Context, request *core.Request, respon // RefreshFeed is the API handler to refresh a feed. func (c *Controller) RefreshFeed(ctx *core.Context, request *core.Request, response *core.Response) { - userID := ctx.GetUserID() + userID := ctx.UserID() feedID, err := request.IntegerParam("feedID") if err != nil { response.JSON().BadRequest(err) @@ -48,7 +48,7 @@ func (c *Controller) RefreshFeed(ctx *core.Context, request *core.Request, respo // UpdateFeed is the API handler that is used to update a feed. func (c *Controller) UpdateFeed(ctx *core.Context, request *core.Request, response *core.Response) { - userID := ctx.GetUserID() + userID := ctx.UserID() feedID, err := request.IntegerParam("feedID") if err != nil { response.JSON().BadRequest(err) @@ -83,7 +83,7 @@ func (c *Controller) UpdateFeed(ctx *core.Context, request *core.Request, respon // GetFeeds is the API handler that get all feeds that belongs to the given user. func (c *Controller) GetFeeds(ctx *core.Context, request *core.Request, response *core.Response) { - feeds, err := c.store.GetFeeds(ctx.GetUserID()) + feeds, err := c.store.GetFeeds(ctx.UserID()) if err != nil { response.JSON().ServerError(errors.New("Unable to fetch feeds from the database")) return @@ -94,7 +94,7 @@ func (c *Controller) GetFeeds(ctx *core.Context, request *core.Request, response // GetFeed is the API handler to get a feed. func (c *Controller) GetFeed(ctx *core.Context, request *core.Request, response *core.Response) { - userID := ctx.GetUserID() + userID := ctx.UserID() feedID, err := request.IntegerParam("feedID") if err != nil { response.JSON().BadRequest(err) @@ -117,7 +117,7 @@ func (c *Controller) GetFeed(ctx *core.Context, request *core.Request, response // RemoveFeed is the API handler to remove a feed. func (c *Controller) RemoveFeed(ctx *core.Context, request *core.Request, response *core.Response) { - userID := ctx.GetUserID() + userID := ctx.UserID() feedID, err := request.IntegerParam("feedID") if err != nil { response.JSON().BadRequest(err) diff --git a/server/core/context.go b/server/core/context.go index c9d2dc2..90c4659 100644 --- a/server/core/context.go +++ b/server/core/context.go @@ -5,11 +5,12 @@ package core import ( + "log" + "net/http" + "github.com/miniflux/miniflux2/model" "github.com/miniflux/miniflux2/server/route" "github.com/miniflux/miniflux2/storage" - "log" - "net/http" "github.com/gorilla/mux" ) @@ -31,8 +32,8 @@ func (c *Context) IsAdminUser() bool { return false } -// GetUserTimezone returns the timezone used by the logged user. -func (c *Context) GetUserTimezone() string { +// UserTimezone returns the timezone used by the logged user. +func (c *Context) UserTimezone() string { if v := c.request.Context().Value("UserTimezone"); v != nil { return v.(string) } @@ -47,19 +48,19 @@ func (c *Context) IsAuthenticated() bool { return false } -// GetUserID returns the UserID of the logged user. -func (c *Context) GetUserID() int64 { +// UserID returns the UserID of the logged user. +func (c *Context) UserID() int64 { if v := c.request.Context().Value("UserId"); v != nil { return v.(int64) } return 0 } -// GetLoggedUser returns all properties related to the logged user. -func (c *Context) GetLoggedUser() *model.User { +// LoggedUser returns all properties related to the logged user. +func (c *Context) LoggedUser() *model.User { if c.user == nil { var err error - c.user, err = c.store.GetUserById(c.GetUserID()) + c.user, err = c.store.GetUserById(c.UserID()) if err != nil { log.Fatalln(err) } @@ -72,14 +73,14 @@ func (c *Context) GetLoggedUser() *model.User { return c.user } -// GetUserLanguage get the locale used by the current logged user. -func (c *Context) GetUserLanguage() string { - user := c.GetLoggedUser() +// UserLanguage get the locale used by the current logged user. +func (c *Context) UserLanguage() string { + user := c.LoggedUser() return user.Language } -// GetCsrfToken returns the current CSRF token. -func (c *Context) GetCsrfToken() string { +// CsrfToken returns the current CSRF token. +func (c *Context) CsrfToken() string { if v := c.request.Context().Value("CsrfToken"); v != nil { return v.(string) } @@ -88,8 +89,8 @@ func (c *Context) GetCsrfToken() string { return "" } -// GetRoute returns the path for the given arguments. -func (c *Context) GetRoute(name string, args ...interface{}) string { +// Route returns the path for the given arguments. +func (c *Context) Route(name string, args ...interface{}) string { return route.GetRoute(c.router, name, args...) } diff --git a/server/core/handler.go b/server/core/handler.go index 2802f31..8541301 100644 --- a/server/core/handler.go +++ b/server/core/handler.go @@ -38,7 +38,7 @@ func (h *Handler) Use(f HandlerFunc) http.Handler { response := NewResponse(w, r, h.template) if ctx.IsAuthenticated() { - h.template.SetLanguage(ctx.GetUserLanguage()) + h.template.SetLanguage(ctx.UserLanguage()) } else { h.template.SetLanguage("en_US") } diff --git a/server/ui/controller/category.go b/server/ui/controller/category.go index 21e70fe..e8ebb03 100644 --- a/server/ui/controller/category.go +++ b/server/ui/controller/category.go @@ -21,7 +21,7 @@ func (c *Controller) ShowCategories(ctx *core.Context, request *core.Request, re return } - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() categories, err := c.store.GetCategoriesWithFeedCount(user.ID) if err != nil { response.HTML().ServerError(err) @@ -37,7 +37,7 @@ func (c *Controller) ShowCategories(ctx *core.Context, request *core.Request, re // ShowCategoryEntries shows all entries for the given category. func (c *Controller) ShowCategoryEntries(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() offset := request.QueryIntegerParam("offset", 0) args, err := c.getCommonTemplateArgs(ctx) @@ -75,7 +75,7 @@ func (c *Controller) ShowCategoryEntries(ctx *core.Context, request *core.Reques "category": category, "entries": entries, "total": count, - "pagination": c.getPagination(ctx.GetRoute("categoryEntries", "categoryID", category.ID), count, offset), + "pagination": c.getPagination(ctx.Route("categoryEntries", "categoryID", category.ID), count, offset), "menu": "categories", })) } @@ -95,7 +95,7 @@ func (c *Controller) CreateCategory(ctx *core.Context, request *core.Request, re // SaveCategory validate and save the new category into the database. func (c *Controller) SaveCategory(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() args, err := c.getCommonTemplateArgs(ctx) if err != nil { response.HTML().ServerError(err) @@ -133,12 +133,12 @@ func (c *Controller) SaveCategory(ctx *core.Context, request *core.Request, resp return } - response.Redirect(ctx.GetRoute("categories")) + response.Redirect(ctx.Route("categories")) } // EditCategory shows the form to modify a category. func (c *Controller) EditCategory(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() category, err := c.getCategoryFromURL(ctx, request, response) if err != nil { @@ -157,7 +157,7 @@ func (c *Controller) EditCategory(ctx *core.Context, request *core.Request, resp // UpdateCategory validate and update a category. func (c *Controller) UpdateCategory(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() category, err := c.getCategoryFromURL(ctx, request, response) if err != nil { @@ -195,12 +195,12 @@ func (c *Controller) UpdateCategory(ctx *core.Context, request *core.Request, re return } - response.Redirect(ctx.GetRoute("categories")) + response.Redirect(ctx.Route("categories")) } // RemoveCategory delete a category from the database. func (c *Controller) RemoveCategory(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() category, err := c.getCategoryFromURL(ctx, request, response) if err != nil { @@ -212,7 +212,7 @@ func (c *Controller) RemoveCategory(ctx *core.Context, request *core.Request, re return } - response.Redirect(ctx.GetRoute("categories")) + response.Redirect(ctx.Route("categories")) } func (c *Controller) getCategoryFromURL(ctx *core.Context, request *core.Request, response *core.Response) (*model.Category, error) { @@ -222,7 +222,7 @@ func (c *Controller) getCategoryFromURL(ctx *core.Context, request *core.Request return nil, err } - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() category, err := c.store.GetCategory(user.ID, categoryID) if err != nil { response.HTML().ServerError(err) diff --git a/server/ui/controller/controller.go b/server/ui/controller/controller.go index 535fbba..22c9dce 100644 --- a/server/ui/controller/controller.go +++ b/server/ui/controller/controller.go @@ -29,7 +29,7 @@ type Controller struct { } func (c *Controller) getCommonTemplateArgs(ctx *core.Context) (tplParams, error) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone) builder.WithStatus(model.EntryStatusUnread) @@ -42,7 +42,7 @@ func (c *Controller) getCommonTemplateArgs(ctx *core.Context) (tplParams, error) "menu": "", "user": user, "countUnread": countUnread, - "csrf": ctx.GetCsrfToken(), + "csrf": ctx.CsrfToken(), } return params, nil } diff --git a/server/ui/controller/entry.go b/server/ui/controller/entry.go index 1a55a1d..7915af5 100644 --- a/server/ui/controller/entry.go +++ b/server/ui/controller/entry.go @@ -15,7 +15,7 @@ import ( // ShowFeedEntry shows a single feed entry in "feed" mode. func (c *Controller) ShowFeedEntry(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() sortingDirection := model.DefaultSortingDirection entryID, err := request.IntegerParam("entryID") @@ -80,12 +80,12 @@ func (c *Controller) ShowFeedEntry(ctx *core.Context, request *core.Request, res nextEntryRoute := "" if nextEntry != nil { - nextEntryRoute = ctx.GetRoute("feedEntry", "feedID", feedID, "entryID", nextEntry.ID) + nextEntryRoute = ctx.Route("feedEntry", "feedID", feedID, "entryID", nextEntry.ID) } prevEntryRoute := "" if prevEntry != nil { - prevEntryRoute = ctx.GetRoute("feedEntry", "feedID", feedID, "entryID", prevEntry.ID) + prevEntryRoute = ctx.Route("feedEntry", "feedID", feedID, "entryID", prevEntry.ID) } if entry.Status == model.EntryStatusUnread { @@ -108,7 +108,7 @@ func (c *Controller) ShowFeedEntry(ctx *core.Context, request *core.Request, res // ShowCategoryEntry shows a single feed entry in "category" mode. func (c *Controller) ShowCategoryEntry(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() sortingDirection := model.DefaultSortingDirection categoryID, err := request.IntegerParam("categoryID") @@ -173,12 +173,12 @@ func (c *Controller) ShowCategoryEntry(ctx *core.Context, request *core.Request, nextEntryRoute := "" if nextEntry != nil { - nextEntryRoute = ctx.GetRoute("categoryEntry", "categoryID", categoryID, "entryID", nextEntry.ID) + nextEntryRoute = ctx.Route("categoryEntry", "categoryID", categoryID, "entryID", nextEntry.ID) } prevEntryRoute := "" if prevEntry != nil { - prevEntryRoute = ctx.GetRoute("categoryEntry", "categoryID", categoryID, "entryID", prevEntry.ID) + prevEntryRoute = ctx.Route("categoryEntry", "categoryID", categoryID, "entryID", prevEntry.ID) } if entry.Status == model.EntryStatusUnread { @@ -202,7 +202,7 @@ func (c *Controller) ShowCategoryEntry(ctx *core.Context, request *core.Request, // ShowUnreadEntry shows a single feed entry in "unread" mode. func (c *Controller) ShowUnreadEntry(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() sortingDirection := model.DefaultSortingDirection entryID, err := request.IntegerParam("entryID") @@ -260,12 +260,12 @@ func (c *Controller) ShowUnreadEntry(ctx *core.Context, request *core.Request, r nextEntryRoute := "" if nextEntry != nil { - nextEntryRoute = ctx.GetRoute("unreadEntry", "entryID", nextEntry.ID) + nextEntryRoute = ctx.Route("unreadEntry", "entryID", nextEntry.ID) } prevEntryRoute := "" if prevEntry != nil { - prevEntryRoute = ctx.GetRoute("unreadEntry", "entryID", prevEntry.ID) + prevEntryRoute = ctx.Route("unreadEntry", "entryID", prevEntry.ID) } if entry.Status == model.EntryStatusUnread { @@ -289,7 +289,7 @@ func (c *Controller) ShowUnreadEntry(ctx *core.Context, request *core.Request, r // ShowReadEntry shows a single feed entry in "history" mode. func (c *Controller) ShowReadEntry(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() sortingDirection := model.DefaultSortingDirection entryID, err := request.IntegerParam("entryID") @@ -347,12 +347,12 @@ func (c *Controller) ShowReadEntry(ctx *core.Context, request *core.Request, res nextEntryRoute := "" if nextEntry != nil { - nextEntryRoute = ctx.GetRoute("readEntry", "entryID", nextEntry.ID) + nextEntryRoute = ctx.Route("readEntry", "entryID", nextEntry.ID) } prevEntryRoute := "" if prevEntry != nil { - prevEntryRoute = ctx.GetRoute("readEntry", "entryID", prevEntry.ID) + prevEntryRoute = ctx.Route("readEntry", "entryID", prevEntry.ID) } response.HTML().Render("entry", args.Merge(tplParams{ @@ -367,7 +367,7 @@ func (c *Controller) ShowReadEntry(ctx *core.Context, request *core.Request, res // UpdateEntriesStatus handles Ajax request to update the status for a list of entries. func (c *Controller) UpdateEntriesStatus(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() entryIDs, status, err := payload.DecodeEntryStatusPayload(request.Body()) if err != nil { diff --git a/server/ui/controller/feed.go b/server/ui/controller/feed.go index 044c716..dc55a11 100644 --- a/server/ui/controller/feed.go +++ b/server/ui/controller/feed.go @@ -15,7 +15,7 @@ import ( // ShowFeedsPage shows the page with all subscriptions. func (c *Controller) ShowFeedsPage(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() args, err := c.getCommonTemplateArgs(ctx) if err != nil { @@ -38,7 +38,7 @@ func (c *Controller) ShowFeedsPage(ctx *core.Context, request *core.Request, res // ShowFeedEntries shows all entries for the given feed. func (c *Controller) ShowFeedEntries(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() offset := request.QueryIntegerParam("offset", 0) args, err := c.getCommonTemplateArgs(ctx) @@ -76,14 +76,14 @@ func (c *Controller) ShowFeedEntries(ctx *core.Context, request *core.Request, r "feed": feed, "entries": entries, "total": count, - "pagination": c.getPagination(ctx.GetRoute("feedEntries", "feedID", feed.ID), count, offset), + "pagination": c.getPagination(ctx.Route("feedEntries", "feedID", feed.ID), count, offset), "menu": "feeds", })) } // EditFeed shows the form to modify a subscription. func (c *Controller) EditFeed(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() feed, err := c.getFeedFromURL(request, response, user) if err != nil { @@ -101,7 +101,7 @@ func (c *Controller) EditFeed(ctx *core.Context, request *core.Request, response // UpdateFeed update a subscription and redirect to the feed entries page. func (c *Controller) UpdateFeed(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() feed, err := c.getFeedFromURL(request, response, user) if err != nil { @@ -131,7 +131,7 @@ func (c *Controller) UpdateFeed(ctx *core.Context, request *core.Request, respon return } - response.Redirect(ctx.GetRoute("feedEntries", "feedID", feed.ID)) + response.Redirect(ctx.Route("feedEntries", "feedID", feed.ID)) } // RemoveFeed delete a subscription from the database and redirect to the list of feeds page. @@ -142,13 +142,13 @@ func (c *Controller) RemoveFeed(ctx *core.Context, request *core.Request, respon return } - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() if err := c.store.RemoveFeed(user.ID, feedID); err != nil { response.HTML().ServerError(err) return } - response.Redirect(ctx.GetRoute("feeds")) + response.Redirect(ctx.Route("feeds")) } // RefreshFeed refresh a subscription and redirect to the feed entries page. @@ -159,12 +159,12 @@ func (c *Controller) RefreshFeed(ctx *core.Context, request *core.Request, respo return } - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() if err := c.feedHandler.RefreshFeed(user.ID, feedID); err != nil { log.Println("[UI:RefreshFeed]", err) } - response.Redirect(ctx.GetRoute("feedEntries", "feedID", feedID)) + response.Redirect(ctx.Route("feedEntries", "feedID", feedID)) } func (c *Controller) getFeedFromURL(request *core.Request, response *core.Response, user *model.User) (*model.Feed, error) { diff --git a/server/ui/controller/history.go b/server/ui/controller/history.go index dff78be..100b12f 100644 --- a/server/ui/controller/history.go +++ b/server/ui/controller/history.go @@ -11,7 +11,7 @@ import ( // ShowHistoryPage renders the page with all read entries. func (c *Controller) ShowHistoryPage(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() offset := request.QueryIntegerParam("offset", 0) args, err := c.getCommonTemplateArgs(ctx) @@ -42,14 +42,14 @@ func (c *Controller) ShowHistoryPage(ctx *core.Context, request *core.Request, r response.HTML().Render("history", args.Merge(tplParams{ "entries": entries, "total": count, - "pagination": c.getPagination(ctx.GetRoute("history"), count, offset), + "pagination": c.getPagination(ctx.Route("history"), count, offset), "menu": "history", })) } // FlushHistory changes all "read" items to "removed". func (c *Controller) FlushHistory(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() err := c.store.FlushHistory(user.ID) if err != nil { @@ -57,5 +57,5 @@ func (c *Controller) FlushHistory(ctx *core.Context, request *core.Request, resp return } - response.Redirect(ctx.GetRoute("history")) + response.Redirect(ctx.Route("history")) } diff --git a/server/ui/controller/login.go b/server/ui/controller/login.go index 3bdb320..aaaf0b6 100644 --- a/server/ui/controller/login.go +++ b/server/ui/controller/login.go @@ -16,12 +16,12 @@ import ( func (c *Controller) ShowLoginPage(ctx *core.Context, request *core.Request, response *core.Response) { if ctx.IsAuthenticated() { - response.Redirect(ctx.GetRoute("unread")) + response.Redirect(ctx.Route("unread")) return } response.HTML().Render("login", tplParams{ - "csrf": ctx.GetCsrfToken(), + "csrf": ctx.CsrfToken(), }) } @@ -29,7 +29,7 @@ func (c *Controller) CheckLogin(ctx *core.Context, request *core.Request, respon authForm := form.NewAuthForm(request.Request()) tplParams := tplParams{ "errorMessage": "Invalid username or password.", - "csrf": ctx.GetCsrfToken(), + "csrf": ctx.CsrfToken(), } if err := authForm.Validate(); err != nil { @@ -65,11 +65,11 @@ func (c *Controller) CheckLogin(ctx *core.Context, request *core.Request, respon } response.SetCookie(cookie) - response.Redirect(ctx.GetRoute("unread")) + response.Redirect(ctx.Route("unread")) } func (c *Controller) Logout(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() sessionCookie := request.Cookie("sessionID") if err := c.store.RemoveSessionByToken(user.ID, sessionCookie); err != nil { @@ -87,5 +87,5 @@ func (c *Controller) Logout(ctx *core.Context, request *core.Request, response * } response.SetCookie(cookie) - response.Redirect(ctx.GetRoute("login")) + response.Redirect(ctx.Route("login")) } diff --git a/server/ui/controller/opml.go b/server/ui/controller/opml.go index 60e2767..d489032 100644 --- a/server/ui/controller/opml.go +++ b/server/ui/controller/opml.go @@ -11,7 +11,7 @@ import ( ) func (c *Controller) Export(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() opml, err := c.opmlHandler.Export(user.ID) if err != nil { response.HTML().ServerError(err) @@ -37,12 +37,12 @@ func (c *Controller) UploadOPML(ctx *core.Context, request *core.Request, respon file, fileHeader, err := request.File("file") if err != nil { log.Println(err) - response.Redirect(ctx.GetRoute("import")) + response.Redirect(ctx.Route("import")) return } defer file.Close() - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() log.Printf("[UI:UploadOPML] User #%d uploaded this file: %s (%d bytes)\n", user.ID, fileHeader.Filename, fileHeader.Size) if impErr := c.opmlHandler.Import(user.ID, file); impErr != nil { @@ -60,5 +60,5 @@ func (c *Controller) UploadOPML(ctx *core.Context, request *core.Request, respon return } - response.Redirect(ctx.GetRoute("feeds")) + response.Redirect(ctx.Route("feeds")) } diff --git a/server/ui/controller/session.go b/server/ui/controller/session.go index 9ec3506..fec754b 100644 --- a/server/ui/controller/session.go +++ b/server/ui/controller/session.go @@ -10,7 +10,7 @@ import ( ) func (c *Controller) ShowSessions(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() args, err := c.getCommonTemplateArgs(ctx) if err != nil { response.HTML().ServerError(err) @@ -32,7 +32,7 @@ func (c *Controller) ShowSessions(ctx *core.Context, request *core.Request, resp } func (c *Controller) RemoveSession(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() sessionID, err := request.IntegerParam("sessionID") if err != nil { @@ -45,5 +45,5 @@ func (c *Controller) RemoveSession(ctx *core.Context, request *core.Request, res log.Println("[UI:RemoveSession]", err) } - response.Redirect(ctx.GetRoute("sessions")) + response.Redirect(ctx.Route("sessions")) } diff --git a/server/ui/controller/settings.go b/server/ui/controller/settings.go index 3e3b6b3..1bd599b 100644 --- a/server/ui/controller/settings.go +++ b/server/ui/controller/settings.go @@ -13,7 +13,7 @@ import ( ) func (c *Controller) ShowSettings(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() args, err := c.getSettingsFormTemplateArgs(ctx, user, nil) if err != nil { @@ -25,7 +25,7 @@ func (c *Controller) ShowSettings(ctx *core.Context, request *core.Request, resp } func (c *Controller) UpdateSettings(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() settingsForm := form.NewSettingsForm(request.Request()) args, err := c.getSettingsFormTemplateArgs(ctx, user, settingsForm) @@ -60,7 +60,7 @@ func (c *Controller) UpdateSettings(ctx *core.Context, request *core.Request, re return } - response.Redirect(ctx.GetRoute("settings")) + response.Redirect(ctx.Route("settings")) } func (c *Controller) getSettingsFormTemplateArgs(ctx *core.Context, user *model.User, settingsForm *form.SettingsForm) (tplParams, error) { diff --git a/server/ui/controller/subscription.go b/server/ui/controller/subscription.go index a9473bd..22ec685 100644 --- a/server/ui/controller/subscription.go +++ b/server/ui/controller/subscription.go @@ -13,7 +13,7 @@ import ( ) func (c *Controller) AddSubscription(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() args, err := c.getSubscriptionFormTemplateArgs(ctx, user) if err != nil { @@ -25,7 +25,7 @@ func (c *Controller) AddSubscription(ctx *core.Context, request *core.Request, r } func (c *Controller) SubmitSubscription(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() args, err := c.getSubscriptionFormTemplateArgs(ctx, user) if err != nil { @@ -71,7 +71,7 @@ func (c *Controller) SubmitSubscription(ctx *core.Context, request *core.Request return } - response.Redirect(ctx.GetRoute("feedEntries", "feedID", feed.ID)) + response.Redirect(ctx.Route("feedEntries", "feedID", feed.ID)) case n > 1: response.HTML().Render("choose_subscription", args.Merge(tplParams{ "categoryID": subscriptionForm.CategoryID, @@ -81,7 +81,7 @@ func (c *Controller) SubmitSubscription(ctx *core.Context, request *core.Request } func (c *Controller) ChooseSubscription(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() args, err := c.getSubscriptionFormTemplateArgs(ctx, user) if err != nil { @@ -107,7 +107,7 @@ func (c *Controller) ChooseSubscription(ctx *core.Context, request *core.Request return } - response.Redirect(ctx.GetRoute("feedEntries", "feedID", feed.ID)) + response.Redirect(ctx.Route("feedEntries", "feedID", feed.ID)) } func (c *Controller) getSubscriptionFormTemplateArgs(ctx *core.Context, user *model.User) (tplParams, error) { diff --git a/server/ui/controller/unread.go b/server/ui/controller/unread.go index 8457cf4..593ee38 100644 --- a/server/ui/controller/unread.go +++ b/server/ui/controller/unread.go @@ -11,7 +11,7 @@ import ( // ShowUnreadPage render the page with all unread entries. func (c *Controller) ShowUnreadPage(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() offset := request.QueryIntegerParam("offset", 0) builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone) @@ -37,8 +37,8 @@ func (c *Controller) ShowUnreadPage(ctx *core.Context, request *core.Request, re "user": user, "countUnread": countUnread, "entries": entries, - "pagination": c.getPagination(ctx.GetRoute("unread"), countUnread, offset), + "pagination": c.getPagination(ctx.Route("unread"), countUnread, offset), "menu": "unread", - "csrf": ctx.GetCsrfToken(), + "csrf": ctx.CsrfToken(), }) } diff --git a/server/ui/controller/user.go b/server/ui/controller/user.go index 01c786f..1590d96 100644 --- a/server/ui/controller/user.go +++ b/server/ui/controller/user.go @@ -13,7 +13,7 @@ import ( ) func (c *Controller) ShowUsers(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() if !user.IsAdmin { response.HTML().Forbidden() @@ -39,7 +39,7 @@ func (c *Controller) ShowUsers(ctx *core.Context, request *core.Request, respons } func (c *Controller) CreateUser(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() if !user.IsAdmin { response.HTML().Forbidden() @@ -59,7 +59,7 @@ func (c *Controller) CreateUser(ctx *core.Context, request *core.Request, respon } func (c *Controller) SaveUser(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() if !user.IsAdmin { response.HTML().Forbidden() @@ -102,11 +102,11 @@ func (c *Controller) SaveUser(ctx *core.Context, request *core.Request, response return } - response.Redirect(ctx.GetRoute("users")) + response.Redirect(ctx.Route("users")) } func (c *Controller) EditUser(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() if !user.IsAdmin { response.HTML().Forbidden() @@ -135,7 +135,7 @@ func (c *Controller) EditUser(ctx *core.Context, request *core.Request, response } func (c *Controller) UpdateUser(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() if !user.IsAdmin { response.HTML().Forbidden() @@ -186,11 +186,11 @@ func (c *Controller) UpdateUser(ctx *core.Context, request *core.Request, respon return } - response.Redirect(ctx.GetRoute("users")) + response.Redirect(ctx.Route("users")) } func (c *Controller) RemoveUser(ctx *core.Context, request *core.Request, response *core.Response) { - user := ctx.GetLoggedUser() + user := ctx.LoggedUser() if !user.IsAdmin { response.HTML().Forbidden() return @@ -206,7 +206,7 @@ func (c *Controller) RemoveUser(ctx *core.Context, request *core.Request, respon return } - response.Redirect(ctx.GetRoute("users")) + response.Redirect(ctx.Route("users")) } func (c *Controller) getUserFromURL(ctx *core.Context, request *core.Request, response *core.Response) (*model.User, error) { |