add user manage routes

This commit is contained in:
sentriz
2019-04-16 17:46:15 +01:00
parent 64fb0fdf82
commit 0d1c25a550
13 changed files with 234 additions and 106 deletions

View File

@@ -30,14 +30,14 @@ func checkCredentialsBasic(password, givenPassword string) bool {
return password == givenPassword
}
func (c *Controller) LogConnection(next http.HandlerFunc) http.HandlerFunc {
func (c *Controller) WithLogging(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
log.Printf("connection from `%s` for `%s`", r.RemoteAddr, r.URL)
next.ServeHTTP(w, r)
}
}
func (c *Controller) CheckParameters(next http.HandlerFunc) http.HandlerFunc {
func (c *Controller) WithValidSubsonicArgs(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
for _, req := range requiredParameters {
param := r.URL.Query().Get(req)
@@ -83,7 +83,7 @@ func (c *Controller) CheckParameters(next http.HandlerFunc) http.HandlerFunc {
}
}
func (c *Controller) EnableCORS(next http.HandlerFunc) http.HandlerFunc {
func (c *Controller) WithCORS(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods",
@@ -98,3 +98,17 @@ func (c *Controller) EnableCORS(next http.HandlerFunc) http.HandlerFunc {
next.ServeHTTP(w, r)
}
}
func (c *Controller) WithValidSession(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session, _ := c.SStore.Get(r, "gonic")
user, _ := session.Values["user"]
if user == nil {
session.AddFlash("you are not authenticated")
session.Save(r, w)
http.Redirect(w, r, "/admin/login", 303)
return
}
next.ServeHTTP(w, r)
}
}