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
- update last.fm api key
- link account
+ {{ if .User.IsAdmin }} + update api key
+ {{ end }} + {{ if .CurrentLastFMAPIKey }} + {{ if .User.LastFMSession }} + current status linked + {{ else }} + current status unlinked link
+ {{ end }} + {{ else if not .User.IsAdmin }} + api key not set. please ask your admin to set it + {{ end }}
{{ if .User.IsAdmin }} - {{/* admin panel to manage all users */}} -
- users -
-
- {{ range $user := .AllUsers }} - {{ $user.Name }} created {{ $user.CreatedAt.Format "Jan 02, 2006" }} change password
- {{ end }} - create new -
+ {{/* admin panel to manage all users */}} +
+ users +
+
+ {{ range $user := .AllUsers }} + {{ $user.Name }} created {{ $user.CreatedAt.Format "Jan 02, 2006" }} change password
+ {{ end }} + create new +
{{ else }} - {{/* user panel to manage themselves */}} -
- your account -
-
- change password -
+ {{/* user panel to manage themselves */}} +
+ your account +
+
+ change password +
{{ end }}
{{ end }}