update recieve link cb
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/sentriz/gonic/db"
|
||||
"github.com/sentriz/gonic/handler/utilities"
|
||||
"github.com/sentriz/gonic/lastfm"
|
||||
)
|
||||
|
||||
func (c *Controller) ServeLogin(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -83,7 +84,23 @@ func (c *Controller) ServeLinkLastFMCallback(w http.ResponseWriter, r *http.Requ
|
||||
http.Error(w, "please provide a token", 400)
|
||||
return
|
||||
}
|
||||
_ = token
|
||||
var apiKey db.Setting
|
||||
c.DB.Where("key = ?", "lastfm_api_key").First(&apiKey)
|
||||
var secret db.Setting
|
||||
c.DB.Where("key = ?", "lastfm_secret").First(&secret)
|
||||
sessionKey, err := lastfm.GetSession(
|
||||
apiKey.Value,
|
||||
secret.Value,
|
||||
token,
|
||||
)
|
||||
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)
|
||||
}
|
||||
|
||||
func (c *Controller) ServeChangePassword(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -164,10 +181,10 @@ func (c *Controller) ServeCreateUserDo(w http.ResponseWriter, r *http.Request) {
|
||||
func (c *Controller) ServeUpdateLastFMAPIKey(w http.ResponseWriter, r *http.Request) {
|
||||
var data templateData
|
||||
var apiKey db.Setting
|
||||
var secret db.Setting
|
||||
c.DB.Where("key = ?", "lastfm_api_key").First(&apiKey)
|
||||
c.DB.Where("key = ?", "lastfm_secret").First(&secret)
|
||||
data.CurrentLastFMAPIKey = apiKey.Value
|
||||
var secret db.Setting
|
||||
c.DB.Where("key = ?", "lastfm_secret").First(&secret)
|
||||
data.CurrentLastFMAPISecret = secret.Value
|
||||
renderTemplate(w, r, "update_lastfm_api_key", &data)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/sentriz/gonic/db"
|
||||
"github.com/sentriz/gonic/handler/utilities"
|
||||
"github.com/sentriz/gonic/subsonic"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
@@ -142,21 +143,6 @@ func respondError(w http.ResponseWriter, r *http.Request,
|
||||
))
|
||||
}
|
||||
|
||||
func firstExisting(or string, strings ...string) string {
|
||||
current := ""
|
||||
for _, s := range strings {
|
||||
if s == "" {
|
||||
continue
|
||||
}
|
||||
current = s
|
||||
break
|
||||
}
|
||||
if current == "" {
|
||||
return or
|
||||
}
|
||||
return current
|
||||
}
|
||||
|
||||
func renderTemplate(w http.ResponseWriter, r *http.Request,
|
||||
name string, data *templateData) {
|
||||
session := r.Context().Value("session").(*sessions.Session)
|
||||
@@ -169,13 +155,13 @@ func renderTemplate(w http.ResponseWriter, r *http.Request,
|
||||
if ok {
|
||||
data.User = user
|
||||
}
|
||||
scheme := firstExisting(
|
||||
scheme := utilities.FirstExisting(
|
||||
"http", // fallback
|
||||
r.Header.Get("X-Forwarded-Proto"),
|
||||
r.Header.Get("X-Forwarded-Scheme"),
|
||||
r.URL.Scheme,
|
||||
)
|
||||
host := firstExisting(
|
||||
host := utilities.FirstExisting(
|
||||
"localhost:7373", // fallback
|
||||
r.Header.Get("X-Forwarded-Host"),
|
||||
r.Host,
|
||||
|
||||
@@ -25,3 +25,18 @@ func ValidateAPIKey(apiKey, secret string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func FirstExisting(or string, strings ...string) string {
|
||||
current := ""
|
||||
for _, s := range strings {
|
||||
if s == "" {
|
||||
continue
|
||||
}
|
||||
current = s
|
||||
break
|
||||
}
|
||||
if current == "" {
|
||||
return or
|
||||
}
|
||||
return current
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user