add param abstraction to request context

This commit is contained in:
sentriz
2020-01-17 20:09:08 +00:00
parent 4af1e43389
commit 8e5d397082
13 changed files with 207 additions and 184 deletions

View File

@@ -9,7 +9,6 @@ import (
"senan.xyz/g/gonic/model"
"senan.xyz/g/gonic/scanner"
"senan.xyz/g/gonic/server/key"
"senan.xyz/g/gonic/server/lastfm"
)
@@ -60,7 +59,7 @@ func (c *Controller) ServeHome(r *http.Request) *Response {
}
//
// playlists box
user := r.Context().Value(key.User).(*model.User)
user := r.Context().Value(CtxUser).(*model.User)
c.DB.
Select("*, count(items.id) as track_count").
Joins(`
@@ -92,7 +91,7 @@ func (c *Controller) ServeChangeOwnPasswordDo(r *http.Request) *Response {
flashW: []string{err.Error()},
}
}
user := r.Context().Value(key.User).(*model.User)
user := r.Context().Value(CtxUser).(*model.User)
user.Password = passwordOne
c.DB.Save(user)
return &Response{redirect: "/admin/home"}
@@ -117,14 +116,14 @@ func (c *Controller) ServeLinkLastFMDo(r *http.Request) *Response {
flashW: []string{err.Error()},
}
}
user := r.Context().Value(key.User).(*model.User)
user := r.Context().Value(CtxUser).(*model.User)
user.LastFMSession = sessionKey
c.DB.Save(&user)
return &Response{redirect: "/admin/home"}
}
func (c *Controller) ServeUnlinkLastFMDo(r *http.Request) *Response {
user := r.Context().Value(key.User).(*model.User)
user := r.Context().Value(CtxUser).(*model.User)
user.LastFMSession = ""
c.DB.Save(&user)
return &Response{redirect: "/admin/home"}
@@ -241,7 +240,7 @@ func (c *Controller) ServeUpdateLastFMAPIKey(r *http.Request) *Response {
data.CurrentLastFMAPIKey = c.DB.GetSetting("lastfm_api_key")
data.CurrentLastFMAPISecret = c.DB.GetSetting("lastfm_secret")
return &Response{
template: "update_lastfm_api_key.tmpl",
template: "update_lastfm_api_key",
data: data,
}
}
@@ -285,7 +284,7 @@ func (c *Controller) ServeUploadPlaylistDo(r *http.Request) *Response {
code: 500,
}
}
user := r.Context().Value(key.User).(*model.User)
user := r.Context().Value(CtxUser).(*model.User)
var playlistCount int
var errors []string
for _, headers := range r.MultipartForm.File {