save session key
This commit is contained in:
@@ -53,6 +53,7 @@ type User struct {
|
|||||||
Base
|
Base
|
||||||
Name string `gorm:"not null;unique_index"`
|
Name string `gorm:"not null;unique_index"`
|
||||||
Password string
|
Password string
|
||||||
|
LastFMSession string
|
||||||
IsAdmin bool
|
IsAdmin bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,14 +93,16 @@ func (c *Controller) ServeLinkLastFMCallback(w http.ResponseWriter, r *http.Requ
|
|||||||
secret.Value,
|
secret.Value,
|
||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
if err != nil {
|
|
||||||
session := r.Context().Value("session").(*sessions.Session)
|
session := r.Context().Value("session").(*sessions.Session)
|
||||||
|
if err != nil {
|
||||||
session.AddFlash(err.Error())
|
session.AddFlash(err.Error())
|
||||||
session.Save(r, w)
|
session.Save(r, w)
|
||||||
http.Redirect(w, r, "/admin/home", 302)
|
http.Redirect(w, r, "/admin/home", 302)
|
||||||
return
|
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)
|
http.Redirect(w, r, "/admin/home", 302)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,18 @@
|
|||||||
<u>last.fm</u>
|
<u>last.fm</u>
|
||||||
</div>
|
</div>
|
||||||
<div class="right">
|
<div class="right">
|
||||||
<a href="/admin/update_lastfm_api_key">update last.fm api key</a><br/>
|
{{ if .User.IsAdmin }}
|
||||||
<a href="https://www.last.fm/api/auth/?api_key={{ .CurrentLastFMAPIKey }}&cb={{ .RequestRoot }}/admin/link_lastfm_callback">link account</a><br/>
|
<a href="/admin/update_lastfm_api_key">update api key</a><br/>
|
||||||
|
{{ end }}
|
||||||
|
{{ if .CurrentLastFMAPIKey }}
|
||||||
|
{{ if .User.LastFMSession }}
|
||||||
|
<span class="light">current status</span> linked
|
||||||
|
{{ else }}
|
||||||
|
<span class="light">current status</span> unlinked <a href="https://www.last.fm/api/auth/?api_key={{ .CurrentLastFMAPIKey }}&cb={{ .RequestRoot }}/admin/link_lastfm_callback">link</a><br/>
|
||||||
|
{{ end }}
|
||||||
|
{{ else if not .User.IsAdmin }}
|
||||||
|
<span class="light">api key not set. please ask your admin to set it</span>
|
||||||
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="padded box mono">
|
<div class="padded box mono">
|
||||||
|
|||||||
Reference in New Issue
Block a user