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