Major refactor
- use embedded static assets - added pw management subcommands
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package allowances
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const sessionName = "allowances"
|
||||
|
||||
type authed func(w http.ResponseWriter, r *http.Request, uid string) error
|
||||
|
||||
func (a *Allowances) protected(handler authed) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := a.store.Get(r, sessionName)
|
||||
if err != nil {
|
||||
log.Printf("%+v", err)
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
u, ok := session.Values["uuid"]
|
||||
if !ok {
|
||||
http.Redirect(
|
||||
w, r,
|
||||
prefix["login"],
|
||||
http.StatusTemporaryRedirect,
|
||||
)
|
||||
return
|
||||
}
|
||||
err = handler(w, r, u.(string))
|
||||
if err != nil {
|
||||
json.NewEncoder(w).Encode(NewFailure(err.Error()))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user