diff --git a/arn/UserHelper.go b/arn/UserHelper.go index 689cf2ed..e30f417f 100644 --- a/arn/UserHelper.go +++ b/arn/UserHelper.go @@ -166,3 +166,20 @@ func SortUsersFollowers(users []*User) map[string]int { return followCount } + +// SameUser returns true or false depending on if the users are the same. +func SameUser(a *User, b *User) bool { + if a == nil { + return false + } + + if b == nil { + return false + } + + if a.ID == b.ID { + return true + } + + return false +} diff --git a/auth/Facebook.go b/auth/Facebook.go index 35ee33ee..0ece524e 100644 --- a/auth/Facebook.go +++ b/auth/Facebook.go @@ -11,7 +11,6 @@ import ( "github.com/aerogo/log" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/assets" - "github.com/animenotifier/notify.moe/utils" jsoniter "github.com/json-iterator/go" "golang.org/x/oauth2" "golang.org/x/oauth2/facebook" @@ -100,7 +99,7 @@ func Facebook(app *aero.Application, authLog *log.Log) { fbUser.Email = strings.Replace(fbUser.Email, "googlemail.com", "gmail.com", 1) // Is this an existing user connecting another social account? - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user != nil { // Add FacebookToUser reference diff --git a/auth/Google.go b/auth/Google.go index e693187b..c61a4d43 100644 --- a/auth/Google.go +++ b/auth/Google.go @@ -11,7 +11,6 @@ import ( "github.com/aerogo/log" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/assets" - "github.com/animenotifier/notify.moe/utils" jsoniter "github.com/json-iterator/go" "golang.org/x/oauth2" "golang.org/x/oauth2/google" @@ -111,7 +110,7 @@ func Google(app *aero.Application, authLog *log.Log) { googleUser.Email = strings.Replace(googleUser.Email, "googlemail.com", "gmail.com", 1) // Is this an existing user connecting another social account? - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user != nil { // Add GoogleToUser reference diff --git a/auth/Logout.go b/auth/Logout.go index d9f5a632..9c9ae535 100644 --- a/auth/Logout.go +++ b/auth/Logout.go @@ -5,7 +5,7 @@ import ( "github.com/aerogo/aero" "github.com/aerogo/log" - "github.com/animenotifier/notify.moe/utils" + "github.com/animenotifier/notify.moe/arn" ) // Logout is called when the user clicks the logout button. @@ -13,7 +13,7 @@ import ( func Logout(app *aero.Application, authLog *log.Log) { app.Get("/logout", func(ctx aero.Context) error { if ctx.HasSession() { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user != nil { authLog.Info("%s logged out | %s | %s | %s | %s", user.Nick, user.ID, ctx.IP(), user.Email, user.RealName()) diff --git a/auth/Twitter.go b/auth/Twitter.go index 5f727788..4d7409e2 100644 --- a/auth/Twitter.go +++ b/auth/Twitter.go @@ -12,7 +12,6 @@ import ( "github.com/aerogo/log" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/assets" - "github.com/animenotifier/notify.moe/utils" "github.com/gomodule/oauth1/oauth" jsoniter "github.com/json-iterator/go" ) @@ -112,7 +111,7 @@ func Twitter(app *aero.Application, authLog *log.Log) { twUser.Email = strings.Replace(twUser.Email, "googlemail.com", "gmail.com", 1) // Is this an existing user connecting another social account? - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user != nil { // Add TwitterToUser reference diff --git a/middleware/Log.go b/middleware/Log.go index f1438930..ea9f897f 100644 --- a/middleware/Log.go +++ b/middleware/Log.go @@ -9,7 +9,7 @@ import ( "github.com/aerogo/aero" "github.com/aerogo/log" - "github.com/animenotifier/notify.moe/utils" + "github.com/animenotifier/notify.moe/arn" ) var ( @@ -54,7 +54,7 @@ func logRequest(ctx aero.Context, responseTime time.Duration) { responseTimeString = strings.Repeat(" ", repeatSpaceCount) + responseTimeString - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) ip := ctx.IP() hostNames, cached := GetHostsForIP(ip) diff --git a/middleware/UserInfo.go b/middleware/UserInfo.go index 335d1f8e..3cfbe545 100644 --- a/middleware/UserInfo.go +++ b/middleware/UserInfo.go @@ -9,7 +9,6 @@ import ( "github.com/aerogo/http/client" "github.com/akyoto/color" "github.com/animenotifier/notify.moe/arn" - "github.com/animenotifier/notify.moe/utils" "github.com/mssola/user_agent" ) @@ -25,7 +24,7 @@ func UserInfo(next aero.Handler) aero.Handler { return nil } - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) // When there's no user logged in, nothing to update if user == nil { diff --git a/mixins/AnimeList.pixy b/mixins/AnimeList.pixy index 70d39c70..17735fd6 100644 --- a/mixins/AnimeList.pixy +++ b/mixins/AnimeList.pixy @@ -30,7 +30,7 @@ component AnimeListScrollable(animeListItems []*arn.AnimeListItem, viewUser *arn if item.Status != arn.AnimeListStatusCompleted .anime-list-item-episodes .anime-list-item-episodes-watched - .action(contenteditable=utils.SameUser(user, viewUser), data-field="Episodes", data-type="number", data-trigger="focusout", data-action="save")= item.Episodes + .action(contenteditable=arn.SameUser(user, viewUser), data-field="Episodes", data-type="number", data-trigger="focusout", data-action="save")= item.Episodes if item.Status == arn.AnimeListStatusWatching && user != nil && user.ID == viewUser.ID .plus-episode.action(data-action="increaseEpisode", data-trigger="click") + @@ -41,4 +41,4 @@ component AnimeListScrollable(animeListItems []*arn.AnimeListItem, viewUser *arn .anime-list-item-episodes-max= item.Anime().EpisodeCountString() .anime-list-item-rating-container - .anime-list-item-rating.action.tip(contenteditable=utils.SameUser(user, viewUser), data-field="Rating.Overall", data-type="number", data-trigger="focusout", data-action="save", aria-label="O: " + utils.FormatRating(item.Rating.Overall) + " | S: " + utils.FormatRating(item.Rating.Story) + " | V: " + utils.FormatRating(item.Rating.Visuals) + " | M: " + utils.FormatRating(item.Rating.Soundtrack))= utils.FormatRating(item.Rating.Overall) + .anime-list-item-rating.action.tip(contenteditable=arn.SameUser(user, viewUser), data-field="Rating.Overall", data-type="number", data-trigger="focusout", data-action="save", aria-label="O: " + utils.FormatRating(item.Rating.Overall) + " | S: " + utils.FormatRating(item.Rating.Story) + " | V: " + utils.FormatRating(item.Rating.Visuals) + " | M: " + utils.FormatRating(item.Rating.Soundtrack))= utils.FormatRating(item.Rating.Overall) diff --git a/pages/activity/activity.go b/pages/activity/activity.go index ec63de89..c87e4911 100644 --- a/pages/activity/activity.go +++ b/pages/activity/activity.go @@ -3,19 +3,18 @@ package activity import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" - "github.com/animenotifier/notify.moe/utils" ) // Global activity page. func Global(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) activities := fetchActivities(user, false) return render(ctx, activities) } // Followed activity page. func Followed(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) activities := fetchActivities(user, true) return render(ctx, activities) } diff --git a/pages/activity/render.go b/pages/activity/render.go index b560a236..bef4ed73 100644 --- a/pages/activity/render.go +++ b/pages/activity/render.go @@ -4,7 +4,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/infinitescroll" ) @@ -15,7 +14,7 @@ const ( // render renders the activities page with the given activities. func render(ctx aero.Context, allActivities []arn.Activity) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) index, _ := ctx.GetInt("index") // Slice the part that we need diff --git a/pages/admin/admin.go b/pages/admin/admin.go index c88fc36b..c780b287 100644 --- a/pages/admin/admin.go +++ b/pages/admin/admin.go @@ -6,8 +6,8 @@ import ( "strings" "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/disk" "github.com/shirou/gopsutil/host" @@ -16,7 +16,7 @@ import ( // Get admin page. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "admin" && user.Role != "editor") { return ctx.Redirect(http.StatusTemporaryRedirect, "/") diff --git a/pages/admin/payments.go b/pages/admin/payments.go index d4e415af..11ba56c0 100644 --- a/pages/admin/payments.go +++ b/pages/admin/payments.go @@ -7,12 +7,11 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // PaymentHistory ... func PaymentHistory(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/admin/purchases.go b/pages/admin/purchases.go index 90183092..73478ede 100644 --- a/pages/admin/purchases.go +++ b/pages/admin/purchases.go @@ -7,12 +7,11 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // PurchaseHistory ... func PurchaseHistory(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/admin/registrations.go b/pages/admin/registrations.go index faa4ec50..f362f537 100644 --- a/pages/admin/registrations.go +++ b/pages/admin/registrations.go @@ -13,7 +13,7 @@ import ( // UserRegistrations ... func UserRegistrations(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/amv/amv.go b/pages/amv/amv.go index 31e42e95..ef6f74f5 100644 --- a/pages/amv/amv.go +++ b/pages/amv/amv.go @@ -7,14 +7,13 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/middleware" - "github.com/animenotifier/notify.moe/utils" ) // Get a single AMV. func Get(ctx aero.Context) error { id := ctx.Get("id") amv, err := arn.GetAMV(id) - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if err != nil { return ctx.Error(http.StatusNotFound, "AMV not found", err) diff --git a/pages/amv/edit.go b/pages/amv/edit.go index 7784c561..53f47f5e 100644 --- a/pages/amv/edit.go +++ b/pages/amv/edit.go @@ -6,7 +6,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/editform" ) @@ -14,7 +13,7 @@ import ( func Edit(ctx aero.Context) error { id := ctx.Get("id") amv, err := arn.GetAMV(id) - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if err != nil { return ctx.Error(http.StatusNotFound, "AMV not found", err) diff --git a/pages/amvs/render.go b/pages/amvs/render.go index 1cb5bb26..6daf81ea 100644 --- a/pages/amvs/render.go +++ b/pages/amvs/render.go @@ -4,7 +4,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/infinitescroll" ) @@ -15,7 +14,7 @@ const ( // render renders the AMVs page with the given AMVs. func render(ctx aero.Context, allAMVs []*arn.AMV) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) index, _ := ctx.GetInt("index") tag := ctx.Get("tag") diff --git a/pages/anime/anime.go b/pages/anime/anime.go index a0202f57..d5bd9140 100644 --- a/pages/anime/anime.go +++ b/pages/anime/anime.go @@ -9,7 +9,6 @@ import ( "github.com/animenotifier/notify.moe/assets" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/middleware" - "github.com/animenotifier/notify.moe/utils" ) const ( @@ -22,7 +21,7 @@ const ( // Get anime page. func Get(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) anime, err := arn.GetAnime(id) if err != nil { diff --git a/pages/anime/characters.go b/pages/anime/characters.go index d4ab6b82..3f0ee762 100644 --- a/pages/anime/characters.go +++ b/pages/anime/characters.go @@ -3,8 +3,6 @@ package anime import ( "net/http" - "github.com/animenotifier/notify.moe/utils" - "github.com/animenotifier/notify.moe/components" "github.com/aerogo/aero" @@ -14,7 +12,7 @@ import ( // Characters ... func Characters(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) anime, err := arn.GetAnime(id) if err != nil { diff --git a/pages/anime/comments.go b/pages/anime/comments.go index 22a52a63..4d87704b 100644 --- a/pages/anime/comments.go +++ b/pages/anime/comments.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" @@ -12,7 +11,7 @@ import ( // Comments ... func Comments(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) id := ctx.Get("id") anime, err := arn.GetAnime(id) diff --git a/pages/anime/editanime/editanime.go b/pages/anime/editanime/editanime.go index 3cbc1f11..829bb02a 100644 --- a/pages/anime/editanime/editanime.go +++ b/pages/anime/editanime/editanime.go @@ -6,14 +6,13 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/editform" ) // Main anime edit page. func Main(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "editor" && user.Role != "admin") { return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this anime") @@ -31,7 +30,7 @@ func Main(ctx aero.Context) error { // Images anime images edit page. func Images(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "editor" && user.Role != "admin") { return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this anime") @@ -49,7 +48,7 @@ func Images(ctx aero.Context) error { // Characters anime characters edit page. func Characters(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "editor" && user.Role != "admin") { return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit") @@ -73,7 +72,7 @@ func Characters(ctx aero.Context) error { // Relations anime relations edit page. func Relations(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "editor" && user.Role != "admin") { return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit") @@ -97,7 +96,7 @@ func Relations(ctx aero.Context) error { // Episodes anime episodes edit page. func Episodes(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "editor" && user.Role != "admin") { return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit") diff --git a/pages/anime/episodes.go b/pages/anime/episodes.go index edfca4f3..656d84ab 100644 --- a/pages/anime/episodes.go +++ b/pages/anime/episodes.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" @@ -12,7 +11,7 @@ import ( // Episodes ... func Episodes(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) id := ctx.Get("id") anime, err := arn.GetAnime(id) episodeToFriends := map[int][]*arn.User{} diff --git a/pages/anime/relations.go b/pages/anime/relations.go index f27325f5..cd0e57d3 100644 --- a/pages/anime/relations.go +++ b/pages/anime/relations.go @@ -6,12 +6,11 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Relations ... func Relations(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) id := ctx.Get("id") anime, err := arn.GetAnime(id) diff --git a/pages/anime/tracks.go b/pages/anime/tracks.go index aa5a4a28..eec89d7a 100644 --- a/pages/anime/tracks.go +++ b/pages/anime/tracks.go @@ -3,8 +3,6 @@ package anime import ( "net/http" - "github.com/animenotifier/notify.moe/utils" - "github.com/animenotifier/notify.moe/components" "github.com/aerogo/aero" @@ -14,7 +12,7 @@ import ( // Tracks ... func Tracks(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) anime, err := arn.GetAnime(id) diff --git a/pages/animeimport/deletekitsu.go b/pages/animeimport/deletekitsu.go index 000e7eb2..ee629b2a 100644 --- a/pages/animeimport/deletekitsu.go +++ b/pages/animeimport/deletekitsu.go @@ -6,7 +6,6 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" ) // DeleteKitsu marks an anime for deletion. @@ -14,7 +13,7 @@ func DeleteKitsu(ctx aero.Context) error { id := ctx.Get("id") // Is the user allowed to delete? - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "editor" && user.Role != "admin") { return ctx.Error(http.StatusUnauthorized, "Not authorized") diff --git a/pages/animeimport/kitsu.go b/pages/animeimport/kitsu.go index c2814c90..0d0ebada 100644 --- a/pages/animeimport/kitsu.go +++ b/pages/animeimport/kitsu.go @@ -10,13 +10,12 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" ) // Kitsu anime import. func Kitsu(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "editor" && user.Role != "admin") { return ctx.Error(http.StatusUnauthorized, "Not authorized") diff --git a/pages/animelist/animelist.go b/pages/animelist/animelist.go index 01600ab3..fc32682d 100644 --- a/pages/animelist/animelist.go +++ b/pages/animelist/animelist.go @@ -9,7 +9,6 @@ import ( "github.com/animenotifier/notify.moe/assets" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/middleware" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/infinitescroll" ) @@ -20,7 +19,7 @@ const ( // Filter filters a user's anime list item by the status. func Filter(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) status := ctx.Get("status") sortBy := arn.SortByRating diff --git a/pages/animelist/delete.go b/pages/animelist/delete.go index 602c95bc..ed2908de 100644 --- a/pages/animelist/delete.go +++ b/pages/animelist/delete.go @@ -4,13 +4,13 @@ import ( "net/http" "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // DeleteConfirmation shows the confirmation page before deleting an anime list. func DeleteConfirmation(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") @@ -21,7 +21,7 @@ func DeleteConfirmation(ctx aero.Context) error { // Delete deletes your entire anime list. func Delete(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/animelist/redirect.go b/pages/animelist/redirect.go index f4765d0e..f9aebe77 100644 --- a/pages/animelist/redirect.go +++ b/pages/animelist/redirect.go @@ -4,12 +4,12 @@ import ( "net/http" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" + "github.com/animenotifier/notify.moe/arn" ) // Redirect to the full URL including the user nick. func Redirect(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/animelistitem/animelistitem.go b/pages/animelistitem/animelistitem.go index dd0526dc..85a8b7af 100644 --- a/pages/animelistitem/animelistitem.go +++ b/pages/animelistitem/animelistitem.go @@ -7,12 +7,11 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Get anime page. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) nick := ctx.Get("nick") viewUser, err := arn.GetUserByNick(nick) diff --git a/pages/calendar/calendar.go b/pages/calendar/calendar.go index 7ca5b164..f775c227 100644 --- a/pages/calendar/calendar.go +++ b/pages/calendar/calendar.go @@ -23,7 +23,7 @@ var weekdayNames = []string{ // Get renders the calendar page. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) oneWeek := 7 * 24 * time.Hour now := time.Now() diff --git a/pages/character/character.go b/pages/character/character.go index 10679474..465357d8 100644 --- a/pages/character/character.go +++ b/pages/character/character.go @@ -19,7 +19,7 @@ const ( // Get character. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) id := ctx.Get("id") character, err := arn.GetCharacter(id) diff --git a/pages/character/edit.go b/pages/character/edit.go index dfe4e008..2f22266b 100644 --- a/pages/character/edit.go +++ b/pages/character/edit.go @@ -6,7 +6,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/editform" ) @@ -14,7 +13,7 @@ import ( func Edit(ctx aero.Context) error { id := ctx.Get("id") character, err := arn.GetCharacter(id) - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if err != nil { return ctx.Error(http.StatusNotFound, "Character not found", err) @@ -27,7 +26,7 @@ func Edit(ctx aero.Context) error { func EditImages(ctx aero.Context) error { id := ctx.Get("id") character, err := arn.GetCharacter(id) - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if err != nil { return ctx.Error(http.StatusNotFound, "Character not found", err) diff --git a/pages/characters/render.go b/pages/characters/render.go index 342ecddd..1745a065 100644 --- a/pages/characters/render.go +++ b/pages/characters/render.go @@ -4,7 +4,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/infinitescroll" ) @@ -15,7 +14,7 @@ const ( // render renders the characters page with the given characters. func render(ctx aero.Context, allCharacters []*arn.Character) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) index, _ := ctx.GetInt("index") tag := ctx.Get("tag") diff --git a/pages/charge/charge.go b/pages/charge/charge.go index 0789c61f..4ef209ab 100644 --- a/pages/charge/charge.go +++ b/pages/charge/charge.go @@ -3,15 +3,14 @@ package charge import ( "net/http" - "github.com/animenotifier/notify.moe/components" - "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" + "github.com/animenotifier/notify.moe/arn" + "github.com/animenotifier/notify.moe/components" ) // Get charge page. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/companies/all.go b/pages/companies/all.go index 475ed8da..53495030 100644 --- a/pages/companies/all.go +++ b/pages/companies/all.go @@ -8,12 +8,11 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // All renders an index of all companies. func All(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) companies := arn.FilterCompanies(func(company *arn.Company) bool { return !company.IsDraft diff --git a/pages/companies/popular.go b/pages/companies/popular.go index 889f82b8..9868e2d0 100644 --- a/pages/companies/popular.go +++ b/pages/companies/popular.go @@ -4,7 +4,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/infinitescroll" ) @@ -12,7 +11,7 @@ const maxPopularCompanies = 10 // Popular renders the best companies. func Popular(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) index, _ := ctx.GetInt("index") // Fetch all eligible companies diff --git a/pages/company/company.go b/pages/company/company.go index f10ed8ef..e9271cae 100644 --- a/pages/company/company.go +++ b/pages/company/company.go @@ -14,7 +14,7 @@ import ( // Get renders a company page. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) id := ctx.Get("id") company, err := arn.GetCompany(id) diff --git a/pages/company/edit.go b/pages/company/edit.go index 4f3a3198..09c9cf1a 100644 --- a/pages/company/edit.go +++ b/pages/company/edit.go @@ -8,7 +8,6 @@ import ( "github.com/animenotifier/notify.moe/assets" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/middleware" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/editform" ) @@ -16,7 +15,7 @@ import ( func Edit(ctx aero.Context) error { id := ctx.Get("id") company, err := arn.GetCompany(id) - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if err != nil { return ctx.Error(http.StatusNotFound, "Company not found", err) diff --git a/pages/compare/animelist.go b/pages/compare/animelist.go index 53e5e3f2..7a89db6d 100644 --- a/pages/compare/animelist.go +++ b/pages/compare/animelist.go @@ -13,7 +13,7 @@ import ( // AnimeList ... func AnimeList(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) nickA := ctx.Get("nick-1") nickB := ctx.Get("nick-2") diff --git a/pages/editlog/editlog.go b/pages/editlog/editlog.go index 9494ad39..df5c538e 100644 --- a/pages/editlog/editlog.go +++ b/pages/editlog/editlog.go @@ -9,7 +9,6 @@ import ( "github.com/animenotifier/notify.moe/utils/infinitescroll" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" ) const ( @@ -19,7 +18,7 @@ const ( // Get edit log. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) index, _ := ctx.GetInt("index") nick := ctx.Get("nick") diff --git a/pages/editor/editor.go b/pages/editor/editor.go index 21beb95a..a3bb8b24 100644 --- a/pages/editor/editor.go +++ b/pages/editor/editor.go @@ -7,12 +7,11 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Get ... func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "admin" && user.Role != "editor") { return ctx.Redirect(http.StatusTemporaryRedirect, "/") diff --git a/pages/editor/filteranime/utils.go b/pages/editor/filteranime/utils.go index 3c74d785..f0965787 100644 --- a/pages/editor/filteranime/utils.go +++ b/pages/editor/filteranime/utils.go @@ -7,14 +7,13 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) const maxAnimeEntries = 70 // editorList renders the anime list with the given title and filter. func editorList(ctx aero.Context, title string, filter func(*arn.Anime) bool, searchLink func(*arn.Anime) string) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "admin" && user.Role != "editor") { return ctx.Error(http.StatusUnauthorized, "Not authorized") diff --git a/pages/editor/filtercompanies/filtercompanies.go b/pages/editor/filtercompanies/filtercompanies.go index ca02527c..6b0f4da1 100644 --- a/pages/editor/filtercompanies/filtercompanies.go +++ b/pages/editor/filtercompanies/filtercompanies.go @@ -6,14 +6,13 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) const maxEntries = 70 // NoDescription ... func NoDescription(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "admin" && user.Role != "editor") { return ctx.Redirect(http.StatusTemporaryRedirect, "/") diff --git a/pages/editor/filtersoundtracks/utils.go b/pages/editor/filtersoundtracks/utils.go index 3b351eb5..56b9d019 100644 --- a/pages/editor/filtersoundtracks/utils.go +++ b/pages/editor/filtersoundtracks/utils.go @@ -7,14 +7,13 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) const maxSoundTrackEntries = 70 // editorList renders the soundtrack list with the given title and filter. func editorList(ctx aero.Context, title string, filter func(*arn.SoundTrack) bool, searchLink func(*arn.SoundTrack) string) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "admin" && user.Role != "editor") { return ctx.Error(http.StatusUnauthorized, "Not authorized") diff --git a/pages/editor/jobs/jobs.go b/pages/editor/jobs/jobs.go index 5f4b4bb2..b7ca3eab 100644 --- a/pages/editor/jobs/jobs.go +++ b/pages/editor/jobs/jobs.go @@ -4,6 +4,7 @@ import ( "sort" "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/utils" ) @@ -30,7 +31,7 @@ var jobLogs = []string{} // Overview shows all background jobs. func Overview(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) jobs := []*utils.JobInfo{} for _, job := range jobInfo { diff --git a/pages/editor/jobs/start.go b/pages/editor/jobs/start.go index 64e9c6eb..287e420a 100644 --- a/pages/editor/jobs/start.go +++ b/pages/editor/jobs/start.go @@ -7,7 +7,6 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" ) // Only allow one job to be started at a time @@ -18,7 +17,7 @@ func Start(ctx aero.Context) error { jobStartMutex.Lock() defer jobStartMutex.Unlock() - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "editor" && user.Role != "admin") { return ctx.Error(http.StatusUnauthorized, "Not authorized") diff --git a/pages/editor/kitsu.go b/pages/editor/kitsu.go index d9b2b341..1e1c33a4 100644 --- a/pages/editor/kitsu.go +++ b/pages/editor/kitsu.go @@ -7,12 +7,11 @@ import ( "github.com/animenotifier/kitsu" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // NewKitsuAnime ... func NewKitsuAnime(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) finder := arn.NewAnimeFinder("kitsu/anime") deletedIDs, err := arn.GetIDList("deleted kitsu anime") diff --git a/pages/editor/mal.go b/pages/editor/mal.go index 09387297..6e7f168d 100644 --- a/pages/editor/mal.go +++ b/pages/editor/mal.go @@ -19,7 +19,7 @@ type diffFunction func(*arn.Anime, *mal.Anime) []animediff.Difference // CompareMAL ... func CompareMAL(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) year := ctx.Get("year") status := ctx.Get("status") season := ctx.Get("season") diff --git a/pages/embed/embed.go b/pages/embed/embed.go index 223c8e27..3a4c1b92 100644 --- a/pages/embed/embed.go +++ b/pages/embed/embed.go @@ -4,13 +4,13 @@ import ( "net/http" "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Get anime list in the browser extension. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.HTML(components.Login("_blank")) diff --git a/pages/episode/episode.go b/pages/episode/episode.go index 03e98053..98e6b262 100644 --- a/pages/episode/episode.go +++ b/pages/episode/episode.go @@ -7,13 +7,12 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" minio "github.com/minio/minio-go/v6" ) // Get renders the anime episode. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) id := ctx.Get("id") // Get episode diff --git a/pages/explore/explore.go b/pages/explore/explore.go index 3194536b..05d1a6ce 100644 --- a/pages/explore/explore.go +++ b/pages/explore/explore.go @@ -7,7 +7,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Filter filters the anime for the explore page. @@ -16,7 +15,7 @@ func Filter(ctx aero.Context) error { season := ctx.Get("season") status := ctx.Get("status") typ := ctx.Get("type") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) now := time.Now() if year == "" { diff --git a/pages/explore/explorecolor/explorecolor.go b/pages/explore/explorecolor/explorecolor.go index ebc39d57..17e8fa9d 100644 --- a/pages/explore/explorecolor/explorecolor.go +++ b/pages/explore/explorecolor/explorecolor.go @@ -8,7 +8,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/infinitescroll" ) @@ -19,7 +18,7 @@ const ( // AnimeByAverageColor returns all anime with an image in the given color. func AnimeByAverageColor(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) color := ctx.Get("color") index, _ := ctx.GetInt("index") diff --git a/pages/explore/explorerelations/sequels.go b/pages/explore/explorerelations/sequels.go index 3dae2883..44313865 100644 --- a/pages/explore/explorerelations/sequels.go +++ b/pages/explore/explorerelations/sequels.go @@ -14,7 +14,7 @@ import ( // Sequels ... func Sequels(ctx aero.Context) error { nick := ctx.Get("nick") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) viewUser, err := arn.GetUserByNick(nick) if err != nil { diff --git a/pages/explore/halloffame/halloffame.go b/pages/explore/halloffame/halloffame.go index 4f3ec743..a2a59e8d 100644 --- a/pages/explore/halloffame/halloffame.go +++ b/pages/explore/halloffame/halloffame.go @@ -14,7 +14,7 @@ const minYear = 1963 // Get ... func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) maxYear := time.Now().Year() - 1 hallOfFameEntries := []*utils.HallOfFameEntry{} diff --git a/pages/genre/genre.go b/pages/genre/genre.go index 215c3426..1a4029d0 100644 --- a/pages/genre/genre.go +++ b/pages/genre/genre.go @@ -6,7 +6,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) const animePerPage = 100 @@ -14,7 +13,7 @@ const animeRatingCountThreshold = 5 // Get renders the genre page. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) genreName := ctx.Get("name") animes := []*arn.Anime{} diff --git a/pages/genres/genres.go b/pages/genres/genres.go index a95bec78..07dc90d0 100644 --- a/pages/genres/genres.go +++ b/pages/genres/genres.go @@ -4,12 +4,11 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Get ... func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) genres := []string{} genreToAnime := map[string]*arn.Anime{} diff --git a/pages/group/edit.go b/pages/group/edit.go index 5ea95147..47977c03 100644 --- a/pages/group/edit.go +++ b/pages/group/edit.go @@ -6,7 +6,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/editform" ) @@ -14,7 +13,7 @@ import ( func Edit(ctx aero.Context) error { id := ctx.Get("id") group, err := arn.GetGroup(id) - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if err != nil { return ctx.Error(http.StatusNotFound, "Group not found", err) @@ -33,7 +32,7 @@ func Edit(ctx aero.Context) error { func EditImage(ctx aero.Context) error { id := ctx.Get("id") group, err := arn.GetGroup(id) - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if err != nil { return ctx.Error(http.StatusNotFound, "Group not found", err) diff --git a/pages/group/feed.go b/pages/group/feed.go index 52a5bc36..a2ff6421 100644 --- a/pages/group/feed.go +++ b/pages/group/feed.go @@ -7,12 +7,11 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/middleware" - "github.com/animenotifier/notify.moe/utils" ) // Feed shows the group front page. func Feed(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) id := ctx.Get("id") group, err := arn.GetGroup(id) diff --git a/pages/group/info.go b/pages/group/info.go index 40fcfffd..169244cc 100644 --- a/pages/group/info.go +++ b/pages/group/info.go @@ -7,12 +7,11 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/middleware" - "github.com/animenotifier/notify.moe/utils" ) // Info shows the group information page. func Info(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) id := ctx.Get("id") group, err := arn.GetGroup(id) diff --git a/pages/group/members.go b/pages/group/members.go index cd4ed8c1..db91e593 100644 --- a/pages/group/members.go +++ b/pages/group/members.go @@ -7,12 +7,11 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/middleware" - "github.com/animenotifier/notify.moe/utils" ) // Members shows the group members. func Members(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) id := ctx.Get("id") group, err := arn.GetGroup(id) diff --git a/pages/groups/joined.go b/pages/groups/joined.go index 4c047a62..99d7deec 100644 --- a/pages/groups/joined.go +++ b/pages/groups/joined.go @@ -4,14 +4,13 @@ import ( "net/http" "sort" - "github.com/animenotifier/notify.moe/utils" - "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" ) // Joined shows the most popular joined groups. func Joined(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/groups/render.go b/pages/groups/render.go index 83814550..34bc337c 100644 --- a/pages/groups/render.go +++ b/pages/groups/render.go @@ -4,7 +4,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/infinitescroll" ) @@ -15,7 +14,7 @@ const ( // render renders the groups page with the given groups. func render(ctx aero.Context, allGroups []*arn.Group) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) index, _ := ctx.GetInt("index") // Slice the part that we need diff --git a/pages/home/home.go b/pages/home/home.go index 158e4edb..e01d7c31 100644 --- a/pages/home/home.go +++ b/pages/home/home.go @@ -2,13 +2,14 @@ package home import ( "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/pages/frontpage" "github.com/animenotifier/notify.moe/utils" ) // Get the anime list or the frontpage when logged out. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return frontpage.Get(ctx) diff --git a/pages/inventory/inventory.go b/pages/inventory/inventory.go index c82dd474..ccab1a83 100644 --- a/pages/inventory/inventory.go +++ b/pages/inventory/inventory.go @@ -8,12 +8,11 @@ import ( "github.com/animenotifier/notify.moe/components" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" ) // Get inventory page. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) viewUser := user if user == nil { diff --git a/pages/listimport/listimport.go b/pages/listimport/listimport.go index 57a0322d..0645d833 100644 --- a/pages/listimport/listimport.go +++ b/pages/listimport/listimport.go @@ -4,13 +4,13 @@ import ( "net/http" "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Get ... func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusBadRequest, "Not logged in") diff --git a/pages/listimport/listimportanilist/anilist.go b/pages/listimport/listimportanilist/anilist.go index e5e419b4..bb6fcbf0 100644 --- a/pages/listimport/listimportanilist/anilist.go +++ b/pages/listimport/listimportanilist/anilist.go @@ -10,12 +10,11 @@ import ( "github.com/animenotifier/anilist" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Preview shows an import preview. func Preview(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusBadRequest, "Not logged in") @@ -32,7 +31,7 @@ func Preview(ctx aero.Context) error { // Finish ... func Finish(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusBadRequest, "Not logged in") @@ -74,7 +73,7 @@ func Finish(ctx aero.Context) error { // getMatches finds and returns all matches for the logged in user. func getMatches(ctx aero.Context) ([]*arn.AniListMatch, error) { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return nil, errors.New("Not logged in") diff --git a/pages/listimport/listimportkitsu/kitsu.go b/pages/listimport/listimportkitsu/kitsu.go index e594039e..14b3e546 100644 --- a/pages/listimport/listimportkitsu/kitsu.go +++ b/pages/listimport/listimportkitsu/kitsu.go @@ -9,12 +9,11 @@ import ( "github.com/animenotifier/kitsu" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Preview shows an import preview. func Preview(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusBadRequest, "Not logged in") @@ -31,7 +30,7 @@ func Preview(ctx aero.Context) error { // Finish ... func Finish(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusBadRequest, "Not logged in") @@ -85,7 +84,7 @@ func Finish(ctx aero.Context) error { // getMatches finds and returns all matches for the logged in user. func getMatches(ctx aero.Context) ([]*arn.KitsuMatch, error) { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return nil, errors.New("Not logged in") diff --git a/pages/listimport/listimportmyanimelist/myanimelist.go b/pages/listimport/listimportmyanimelist/myanimelist.go index 3c0f0448..e1c16ad6 100644 --- a/pages/listimport/listimportmyanimelist/myanimelist.go +++ b/pages/listimport/listimportmyanimelist/myanimelist.go @@ -10,12 +10,11 @@ import ( "github.com/animenotifier/mal" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Preview shows an import preview. func Preview(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusBadRequest, "Not logged in") @@ -32,7 +31,7 @@ func Preview(ctx aero.Context) error { // Finish ... func Finish(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusBadRequest, "Not logged in") @@ -79,7 +78,7 @@ func Finish(ctx aero.Context) error { // getMatches finds and returns all matches for the logged in user. func getMatches(ctx aero.Context) ([]*arn.MyAnimeListMatch, error) { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return nil, errors.New("Not logged in") diff --git a/pages/me/me.go b/pages/me/me.go index b68600da..a36c4f79 100644 --- a/pages/me/me.go +++ b/pages/me/me.go @@ -2,12 +2,12 @@ package me import ( "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" + "github.com/animenotifier/notify.moe/arn" ) // Get ... func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.JSON(nil) diff --git a/pages/newthread/newthread.go b/pages/newthread/newthread.go index 6a98065b..17704323 100644 --- a/pages/newthread/newthread.go +++ b/pages/newthread/newthread.go @@ -4,13 +4,13 @@ import ( "net/http" "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Get forums page. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusBadRequest, "Not logged in") diff --git a/pages/notifications/api.go b/pages/notifications/api.go index d4f65be7..29364dcc 100644 --- a/pages/notifications/api.go +++ b/pages/notifications/api.go @@ -8,12 +8,11 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/assets" - "github.com/animenotifier/notify.moe/utils" ) // CountUnseen sends the number of unseen notifications. func CountUnseen(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusBadRequest, "Not logged in") @@ -26,7 +25,7 @@ func CountUnseen(ctx aero.Context) error { // MarkNotificationsAsSeen marks all notifications as seen. func MarkNotificationsAsSeen(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusBadRequest, "Not logged in") @@ -73,7 +72,7 @@ func Latest(ctx aero.Context) error { // Test sends a test notification to the logged in user. func Test(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusBadRequest, "Not logged in") diff --git a/pages/notifications/notifications.go b/pages/notifications/notifications.go index 722510a1..ee544fd9 100644 --- a/pages/notifications/notifications.go +++ b/pages/notifications/notifications.go @@ -8,14 +8,13 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) const maxNotifications = 30 // ByUser shows all notifications sent to the given user. func ByUser(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusBadRequest, "Not logged in") diff --git a/pages/paypal/paypal.go b/pages/paypal/paypal.go index 26b84955..7e30dc71 100644 --- a/pages/paypal/paypal.go +++ b/pages/paypal/paypal.go @@ -6,14 +6,13 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/assets" - "github.com/animenotifier/notify.moe/utils" paypalsdk "github.com/logpacker/PayPal-Go-SDK" ) // CreatePayment creates the PayPal payment, typically via a JSON API route. func CreatePayment(ctx aero.Context) error { // Make sure the user is logged in - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/paypal/success.go b/pages/paypal/success.go index f2b60fa6..0cfaa2d7 100644 --- a/pages/paypal/success.go +++ b/pages/paypal/success.go @@ -10,7 +10,6 @@ import ( "github.com/animenotifier/notify.moe/arn/stringutils" "github.com/animenotifier/notify.moe/assets" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) const adminID = "4J6qpK1ve" @@ -18,7 +17,7 @@ const adminID = "4J6qpK1ve" // Success is called once the payment has been confirmed by the user on the PayPal website. // However, the actual payment still needs to be executed and can fail. func Success(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/post/editpost/editpost.go b/pages/post/editpost/editpost.go index 8d0c9ad8..1783e675 100644 --- a/pages/post/editpost/editpost.go +++ b/pages/post/editpost/editpost.go @@ -6,14 +6,13 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/editform" ) // Get post edit page. func Get(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "editor" && user.Role != "admin") { return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this post") diff --git a/pages/post/post.go b/pages/post/post.go index 839a0e03..821688d7 100644 --- a/pages/post/post.go +++ b/pages/post/post.go @@ -7,13 +7,12 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/middleware" - "github.com/animenotifier/notify.moe/utils" ) // Get post. func Get(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) post, err := arn.GetPost(id) if err != nil { diff --git a/pages/post/reply-ui.go b/pages/post/reply-ui.go index c782058c..c57d2138 100644 --- a/pages/post/reply-ui.go +++ b/pages/post/reply-ui.go @@ -6,13 +6,12 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // ReplyUI renders a new post area. func ReplyUI(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) post, err := arn.GetPost(id) if err != nil { diff --git a/pages/profile/followers.go b/pages/profile/followers.go index 84b4bb11..9037b980 100644 --- a/pages/profile/followers.go +++ b/pages/profile/followers.go @@ -21,6 +21,6 @@ package profile // followers := viewUser.Followers() // arn.SortUsersLastSeenFirst(followers) -// return ctx.HTML(components.ProfileFollowers(followers, viewUser, utils.GetUser(ctx), ctx.Path())) +// return ctx.HTML(components.ProfileFollowers(followers, viewUser, arn.GetUserFromContext(ctx), ctx.Path())) // } diff --git a/pages/profile/posts.go b/pages/profile/posts.go index 9b801a02..c222f530 100644 --- a/pages/profile/posts.go +++ b/pages/profile/posts.go @@ -27,6 +27,6 @@ package profile // posts = posts[:postLimit] // } -// return ctx.HTML(components.LatestPosts(arn.ToPostables(posts), viewUser, utils.GetUser(ctx), ctx.Path())) +// return ctx.HTML(components.LatestPosts(arn.ToPostables(posts), viewUser, arn.GetUserFromContext(ctx), ctx.Path())) // } diff --git a/pages/profile/profile.go b/pages/profile/profile.go index 230979a9..3efaffca 100644 --- a/pages/profile/profile.go +++ b/pages/profile/profile.go @@ -33,7 +33,7 @@ func Get(ctx aero.Context) error { // Profile renders the user profile page of the given viewUser. func Profile(ctx aero.Context, viewUser *arn.User) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) sortBy := arn.SortByRating if user != nil { diff --git a/pages/profile/profilecharacters/liked.go b/pages/profile/profilecharacters/liked.go index 45213413..ab654477 100644 --- a/pages/profile/profilecharacters/liked.go +++ b/pages/profile/profilecharacters/liked.go @@ -7,7 +7,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Liked shows all liked characters of a particular user. @@ -40,5 +39,5 @@ func Liked(ctx aero.Context) error { // return aLikes > bLikes }) - return ctx.HTML(components.ProfileCharacters(characters, viewUser, utils.GetUser(ctx), ctx.Path())) + return ctx.HTML(components.ProfileCharacters(characters, viewUser, arn.GetUserFromContext(ctx), ctx.Path())) } diff --git a/pages/profile/profilequotes/render.go b/pages/profile/profilequotes/render.go index dc2297d3..79d561bf 100644 --- a/pages/profile/profilequotes/render.go +++ b/pages/profile/profilequotes/render.go @@ -19,7 +19,7 @@ package profilequotes // func render(ctx aero.Context, fetch func(userID string) []*arn.Quote) string { // nick := ctx.Get("nick") // index, _ := ctx.GetInt("index") -// user := utils.GetUser(ctx) +// user := arn.GetUserFromContext(ctx) // viewUser, err := arn.GetUserByNick(nick) // if err != nil { diff --git a/pages/profile/profiletracks/render.go b/pages/profile/profiletracks/render.go index 7e4d39d7..2496e49a 100644 --- a/pages/profile/profiletracks/render.go +++ b/pages/profile/profiletracks/render.go @@ -19,7 +19,7 @@ package profiletracks // func render(ctx aero.Context, fetch func(userID string) []*arn.SoundTrack) string { // nick := ctx.Get("nick") // index, _ := ctx.GetInt("index") -// user := utils.GetUser(ctx) +// user := arn.GetUserFromContext(ctx) // viewUser, err := arn.GetUserByNick(nick) // if err != nil { diff --git a/pages/profile/stats.go b/pages/profile/stats.go index 339cc689..2efc320f 100644 --- a/pages/profile/stats.go +++ b/pages/profile/stats.go @@ -98,5 +98,5 @@ package profile // arn.NewPieChart("Soundtracks", trackTags), // } -// return ctx.HTML(components.ProfileStats(&userStats, viewUser, utils.GetUser(ctx), ctx.Path())) +// return ctx.HTML(components.ProfileStats(&userStats, viewUser, arn.GetUserFromContext(ctx), ctx.Path())) // } diff --git a/pages/profile/threads.go b/pages/profile/threads.go index 36b7d455..371a0817 100644 --- a/pages/profile/threads.go +++ b/pages/profile/threads.go @@ -27,5 +27,5 @@ package profile // threads = threads[:maxThreads] // } -// return ctx.HTML(components.ProfileThreads(threads, viewUser, utils.GetUser(ctx), ctx.Path())) +// return ctx.HTML(components.ProfileThreads(threads, viewUser, arn.GetUserFromContext(ctx), ctx.Path())) // } diff --git a/pages/quote/edit.go b/pages/quote/edit.go index 6f7cca67..5b57e465 100644 --- a/pages/quote/edit.go +++ b/pages/quote/edit.go @@ -9,13 +9,12 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/assets" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/editform" ) // Edit quote. func Edit(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) id := ctx.Get("id") quote, err := arn.GetQuote(id) diff --git a/pages/quote/quote.go b/pages/quote/quote.go index a950718d..a0f7d702 100644 --- a/pages/quote/quote.go +++ b/pages/quote/quote.go @@ -8,12 +8,11 @@ import ( "github.com/animenotifier/notify.moe/assets" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/middleware" - "github.com/animenotifier/notify.moe/utils" ) // Get quote. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) id := ctx.Get("id") quote, err := arn.GetQuote(id) diff --git a/pages/quotes/best.go b/pages/quotes/best.go index 0c1c3e06..5bb5931a 100644 --- a/pages/quotes/best.go +++ b/pages/quotes/best.go @@ -4,13 +4,12 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/infinitescroll" ) // Best renders the best quotes. func Best(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) index, _ := ctx.GetInt("index") // Fetch all eligible quotes diff --git a/pages/quotes/quotes.go b/pages/quotes/quotes.go index 4cb70a7d..fc1eb0d5 100644 --- a/pages/quotes/quotes.go +++ b/pages/quotes/quotes.go @@ -4,7 +4,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/infinitescroll" ) @@ -12,7 +11,7 @@ const maxQuotes = 15 // Latest renders the latest quotes. func Latest(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) index, _ := ctx.GetInt("index") // Fetch all eligible quotes diff --git a/pages/recommended/anime.go b/pages/recommended/anime.go index b753adee..ee401b03 100644 --- a/pages/recommended/anime.go +++ b/pages/recommended/anime.go @@ -7,7 +7,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) const ( @@ -18,7 +17,7 @@ const ( // Anime shows a list of recommended anime. func Anime(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) nick := ctx.Get("nick") viewUser, err := arn.GetUserByNick(nick) diff --git a/pages/search/search.go b/pages/search/search.go index b318dbbd..784df882 100644 --- a/pages/search/search.go +++ b/pages/search/search.go @@ -3,9 +3,8 @@ package search import ( "net/http" - "github.com/animenotifier/notify.moe/utils" - "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/arn/search" "github.com/animenotifier/notify.moe/components" ) @@ -24,7 +23,7 @@ const ( // Get search page. func Get(ctx aero.Context) error { term := ctx.Get("term") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if len(term) > search.MaxSearchTermLength { ctx.SetStatus(http.StatusRequestEntityTooLarge) @@ -47,13 +46,13 @@ func Get(ctx aero.Context) error { // GetEmptySearch renders the search page with no contents. func GetEmptySearch(ctx aero.Context) error { - return ctx.HTML(components.SearchResults("", nil, nil, nil, nil, nil, nil, nil, nil, nil, utils.GetUser(ctx))) + return ctx.HTML(components.SearchResults("", nil, nil, nil, nil, nil, nil, nil, nil, nil, arn.GetUserFromContext(ctx))) } // Anime search. func Anime(ctx aero.Context) error { term := ctx.Get("term") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if len(term) > search.MaxSearchTermLength { ctx.SetStatus(http.StatusRequestEntityTooLarge) @@ -66,7 +65,7 @@ func Anime(ctx aero.Context) error { // Characters search. func Characters(ctx aero.Context) error { term := ctx.Get("term") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if len(term) > search.MaxSearchTermLength { ctx.SetStatus(http.StatusRequestEntityTooLarge) @@ -79,7 +78,7 @@ func Characters(ctx aero.Context) error { // Posts search. func Posts(ctx aero.Context) error { term := ctx.Get("term") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if len(term) > search.MaxSearchTermLength { ctx.SetStatus(http.StatusRequestEntityTooLarge) @@ -92,7 +91,7 @@ func Posts(ctx aero.Context) error { // Threads search. func Threads(ctx aero.Context) error { term := ctx.Get("term") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if len(term) > search.MaxSearchTermLength { ctx.SetStatus(http.StatusRequestEntityTooLarge) @@ -105,7 +104,7 @@ func Threads(ctx aero.Context) error { // SoundTracks search. func SoundTracks(ctx aero.Context) error { term := ctx.Get("term") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if len(term) > search.MaxSearchTermLength { ctx.SetStatus(http.StatusRequestEntityTooLarge) @@ -118,7 +117,7 @@ func SoundTracks(ctx aero.Context) error { // AMVs search. func AMVs(ctx aero.Context) error { term := ctx.Get("term") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if len(term) > search.MaxSearchTermLength { ctx.SetStatus(http.StatusRequestEntityTooLarge) diff --git a/pages/settings/settings.go b/pages/settings/settings.go index 3861af8d..bd823db5 100644 --- a/pages/settings/settings.go +++ b/pages/settings/settings.go @@ -5,13 +5,12 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" - "github.com/animenotifier/notify.moe/utils" ) // Get settings. func Get(component func(*arn.User) string) func(aero.Context) error { return func(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/shop/buyitem.go b/pages/shop/buyitem.go index f484baa6..fbb93c92 100644 --- a/pages/shop/buyitem.go +++ b/pages/shop/buyitem.go @@ -6,7 +6,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" - "github.com/animenotifier/notify.moe/utils" ) var itemBuyMutex sync.Mutex @@ -18,7 +17,7 @@ func BuyItem(ctx aero.Context) error { defer itemBuyMutex.Unlock() // Logged in user - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/shop/history.go b/pages/shop/history.go index d00d2429..b14275cc 100644 --- a/pages/shop/history.go +++ b/pages/shop/history.go @@ -7,12 +7,11 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // PurchaseHistory ... func PurchaseHistory(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/shop/shop.go b/pages/shop/shop.go index f2f7de65..c7151a71 100644 --- a/pages/shop/shop.go +++ b/pages/shop/shop.go @@ -8,12 +8,11 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Get shop page. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/soundtrack/download.go b/pages/soundtrack/download.go index 2858764d..c211e65b 100644 --- a/pages/soundtrack/download.go +++ b/pages/soundtrack/download.go @@ -5,13 +5,12 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" - "github.com/animenotifier/notify.moe/utils" ) // Download tries to refresh the soundtrack file. func Download(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "editor" && user.Role != "admin") { return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this soundtrack") diff --git a/pages/soundtrack/edit.go b/pages/soundtrack/edit.go index 5e8cecab..20f91e97 100644 --- a/pages/soundtrack/edit.go +++ b/pages/soundtrack/edit.go @@ -5,7 +5,6 @@ import ( "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/middleware" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/editform" "github.com/aerogo/aero" @@ -16,7 +15,7 @@ import ( func Edit(ctx aero.Context) error { id := ctx.Get("id") track, err := arn.GetSoundTrack(id) - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if err != nil { return ctx.Error(http.StatusNotFound, "Track not found", err) diff --git a/pages/soundtrack/lyrics.go b/pages/soundtrack/lyrics.go index 41a93a51..000815ce 100644 --- a/pages/soundtrack/lyrics.go +++ b/pages/soundtrack/lyrics.go @@ -14,7 +14,7 @@ import ( func Lyrics(ctx aero.Context) error { id := ctx.Get("id") track, err := arn.GetSoundTrack(id) - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if err != nil { return ctx.Error(http.StatusNotFound, "Track not found", err) diff --git a/pages/soundtrack/soundtrack.go b/pages/soundtrack/soundtrack.go index 37eb2975..216dcbdf 100644 --- a/pages/soundtrack/soundtrack.go +++ b/pages/soundtrack/soundtrack.go @@ -7,14 +7,13 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/middleware" - "github.com/animenotifier/notify.moe/utils" ) // Get track. func Get(ctx aero.Context) error { id := ctx.Get("id") track, err := arn.GetSoundTrack(id) - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if err != nil { return ctx.Error(http.StatusNotFound, "Track not found", err) diff --git a/pages/soundtracks/render.go b/pages/soundtracks/render.go index c0a08b27..e82f0510 100644 --- a/pages/soundtracks/render.go +++ b/pages/soundtracks/render.go @@ -4,7 +4,6 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/infinitescroll" ) @@ -15,7 +14,7 @@ const ( // render renders the soundracks page with the given tracks. func render(ctx aero.Context, allTracks []*arn.SoundTrack) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) index, _ := ctx.GetInt("index") tag := ctx.Get("tag") diff --git a/pages/sse/sse.go b/pages/sse/sse.go index 9776ebae..ae5f3044 100644 --- a/pages/sse/sse.go +++ b/pages/sse/sse.go @@ -3,11 +3,10 @@ package sse import ( "net/http" + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components/css" "github.com/animenotifier/notify.moe/components/js" - - "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" ) var ( @@ -17,7 +16,7 @@ var ( // Events streams server events to the client. func Events(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/support/support.go b/pages/support/support.go index ec822887..8b1c9d2d 100644 --- a/pages/support/support.go +++ b/pages/support/support.go @@ -2,13 +2,13 @@ package support import ( "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Get support page. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) profileLink := "/" if user != nil { diff --git a/pages/thread/editthread/editthread.go b/pages/thread/editthread/editthread.go index 81ac098c..f23a876b 100644 --- a/pages/thread/editthread/editthread.go +++ b/pages/thread/editthread/editthread.go @@ -6,14 +6,13 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/editform" ) // Get thread edit page. func Get(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || (user.Role != "editor" && user.Role != "admin") { return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this thread") diff --git a/pages/thread/reply-ui.go b/pages/thread/reply-ui.go index 24c569d8..4417a2b6 100644 --- a/pages/thread/reply-ui.go +++ b/pages/thread/reply-ui.go @@ -6,13 +6,12 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // ReplyUI renders a new post area. func ReplyUI(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) thread, err := arn.GetThread(id) if err != nil { diff --git a/pages/thread/thread.go b/pages/thread/thread.go index 22bfc178..04f11766 100644 --- a/pages/thread/thread.go +++ b/pages/thread/thread.go @@ -7,13 +7,12 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/middleware" - "github.com/animenotifier/notify.moe/utils" ) // Get thread. func Get(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) // Fetch thread thread, err := arn.GetThread(id) diff --git a/pages/upload/amv-file.go b/pages/upload/amv-file.go index 8b305c74..7508d286 100644 --- a/pages/upload/amv-file.go +++ b/pages/upload/amv-file.go @@ -6,12 +6,11 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" ) // AMVFile handles the video upload for AMV files. func AMVFile(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) amvID := ctx.Get("id") if user == nil { diff --git a/pages/upload/anime-image.go b/pages/upload/anime-image.go index fe85d237..40cb890f 100644 --- a/pages/upload/anime-image.go +++ b/pages/upload/anime-image.go @@ -6,12 +6,11 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" ) // AnimeImage handles the anime image upload. func AnimeImage(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) animeID := ctx.Get("id") if user == nil || (user.Role != "editor" && user.Role != "admin") { diff --git a/pages/upload/character-image.go b/pages/upload/character-image.go index d4cc2af4..9841152d 100644 --- a/pages/upload/character-image.go +++ b/pages/upload/character-image.go @@ -6,12 +6,11 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" ) // CharacterImage handles the character image upload. func CharacterImage(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) characterID := ctx.Get("id") if user == nil || (user.Role != "editor" && user.Role != "admin") { diff --git a/pages/upload/group-image.go b/pages/upload/group-image.go index 03f26bdb..d1dd0a14 100644 --- a/pages/upload/group-image.go +++ b/pages/upload/group-image.go @@ -5,12 +5,11 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" - "github.com/animenotifier/notify.moe/utils" ) // GroupImage handles the group image upload. func GroupImage(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) groupID := ctx.Get("id") if user == nil || (user.Role != "editor" && user.Role != "admin") { diff --git a/pages/upload/user-cover.go b/pages/upload/user-cover.go index 92cff86d..2854b6f5 100644 --- a/pages/upload/user-cover.go +++ b/pages/upload/user-cover.go @@ -4,12 +4,12 @@ import ( "net/http" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" + "github.com/animenotifier/notify.moe/arn" ) // UserCover handles the cover image upload. func UserCover(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/upload/user-image.go b/pages/upload/user-image.go index 0763b324..4f37e281 100644 --- a/pages/upload/user-image.go +++ b/pages/upload/user-image.go @@ -4,12 +4,12 @@ import ( "net/http" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/utils" + "github.com/animenotifier/notify.moe/arn" ) // UserImage handles the avatar upload. func UserImage(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/pages/user/edit.go b/pages/user/edit.go index 441be7da..7f847273 100644 --- a/pages/user/edit.go +++ b/pages/user/edit.go @@ -5,14 +5,13 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" - "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/editform" ) // Edit user. func Edit(ctx aero.Context) error { nick := ctx.Get("nick") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil || user.Role != "admin" { return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this user") diff --git a/pages/user/user.go b/pages/user/user.go index bcec6c6d..6b7b97dd 100644 --- a/pages/user/user.go +++ b/pages/user/user.go @@ -4,13 +4,13 @@ import ( "net/http" "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/pages/profile" - "github.com/animenotifier/notify.moe/utils" ) // Get redirects /+ to /+UserName func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusBadRequest, "Not logged in") diff --git a/pages/welcome/welcome.go b/pages/welcome/welcome.go index 12fbeef9..4fc8fe21 100644 --- a/pages/welcome/welcome.go +++ b/pages/welcome/welcome.go @@ -4,13 +4,13 @@ import ( "net/http" "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" - "github.com/animenotifier/notify.moe/utils" ) // Get returns the welcome page. func Get(ctx aero.Context) error { - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in") diff --git a/utils/GetUser.go b/utils/GetUser.go deleted file mode 100644 index 066690c5..00000000 --- a/utils/GetUser.go +++ /dev/null @@ -1,28 +0,0 @@ -package utils - -import ( - "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/arn" -) - -// GetUser returns the logged in user for the given context. -func GetUser(ctx aero.Context) *arn.User { - return arn.GetUserFromContext(ctx) -} - -// SameUser returns "true" or "false" depending on if the users are the same. -func SameUser(a *arn.User, b *arn.User) string { - if a == nil { - return "false" - } - - if b == nil { - return "false" - } - - if a.ID == b.ID { - return "true" - } - - return "false" -} diff --git a/utils/history/history.go b/utils/history/history.go index b1bb2555..d69272b9 100644 --- a/utils/history/history.go +++ b/utils/history/history.go @@ -5,14 +5,13 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" - "github.com/animenotifier/notify.moe/utils" ) // Handler returns a function that renders the history of any object. func Handler(render func(interface{}, []*arn.EditLogEntry, *arn.User) string, typeNames ...string) func(ctx aero.Context) error { return func(ctx aero.Context) error { id := ctx.Get("id") - user := utils.GetUser(ctx) + user := arn.GetUserFromContext(ctx) obj, err := arn.DB.Get(typeNames[0], id) if err != nil {