diff --git a/db/model.go b/db/model.go index 9c7b4e4..84e39f5 100644 --- a/db/model.go +++ b/db/model.go @@ -51,9 +51,10 @@ type Cover struct { // User represents the users table type User struct { Base - Name string `gorm:"not null;unique_index"` - Password string - IsAdmin bool + Name string `gorm:"not null;unique_index"` + Password string + LastFMSession string + IsAdmin bool } // Setting represents the settings table diff --git a/handler/admin.go b/handler/admin.go index b9388ed..3ada6dd 100644 --- a/handler/admin.go +++ b/handler/admin.go @@ -93,14 +93,16 @@ func (c *Controller) ServeLinkLastFMCallback(w http.ResponseWriter, r *http.Requ secret.Value, token, ) + session := r.Context().Value("session").(*sessions.Session) if err != nil { - session := r.Context().Value("session").(*sessions.Session) session.AddFlash(err.Error()) session.Save(r, w) http.Redirect(w, r, "/admin/home", 302) return } - fmt.Println("THE SESSION KEY", sessionKey) + user, _ := session.Values["user"].(*db.User) + user.LastFMSession = sessionKey + c.DB.Save(&user) http.Redirect(w, r, "/admin/home", 302) } diff --git a/templates/pages/home.tmpl b/templates/pages/home.tmpl index 036043b..67f27c3 100644 --- a/templates/pages/home.tmpl +++ b/templates/pages/home.tmpl @@ -16,30 +16,40 @@ last.fm