mirror of
https://github.com/gmemstr/pogo.git
synced 2024-09-19 09:11:10 +01:00
New config route for editing & getting config
Now that config no longer handles sensitive account info it's fine to pass this to client. Debating whether to allow anyone to fetch config, but for now restricted to level 2 user accounts.
This commit is contained in:
parent
b0e7a69771
commit
db24981641
|
@ -47,6 +47,65 @@ type Config struct {
|
|||
* able to have access to, mostly user management.
|
||||
*/
|
||||
|
||||
func ConfigurationManager() common.Handler {
|
||||
|
||||
return func(rc *common.RouterContext, w http.ResponseWriter, r *http.Request) *common.HTTPError {
|
||||
|
||||
if r.Method == "GET" {
|
||||
return common.ReadAndServeFile("assets/config/config.json", w)
|
||||
}
|
||||
fmt.Println(r.Host)
|
||||
err := r.ParseMultipartForm(32 << 20)
|
||||
if err != nil {
|
||||
return &common.HTTPError{
|
||||
Message: err.Error(),
|
||||
StatusCode: http.StatusBadRequest,
|
||||
}
|
||||
}
|
||||
file, handler, err := r.FormFile("image")
|
||||
if err == nil {
|
||||
defer file.Close()
|
||||
fmt.Println(handler.Header)
|
||||
f, err := os.OpenFile("./assets/web/static/podcastimage.png", os.O_WRONLY|os.O_CREATE, 0666)
|
||||
if err != nil {
|
||||
w.Write([]byte("<script>window.location = '/admin#failed';</script>"))
|
||||
|
||||
fmt.Println(err)
|
||||
return nil
|
||||
}
|
||||
defer f.Close()
|
||||
io.Copy(f, file)
|
||||
} else {
|
||||
// Do nothing, assume no image was uploaded :(
|
||||
}
|
||||
newconfig := Config{
|
||||
strings.Join(r.Form["feedname"], ""),
|
||||
strings.Join(r.Form["host"], ""),
|
||||
strings.Join(r.Form["email"], ""),
|
||||
strings.Join(r.Form["description"], ""),
|
||||
r.Host + "/assets/podcastimage.png",
|
||||
"http://" + r.Host,
|
||||
}
|
||||
newconfigjson, err := json.Marshal(newconfig)
|
||||
if err != nil {
|
||||
return &common.HTTPError{
|
||||
Message: err.Error(),
|
||||
StatusCode: http.StatusBadRequest,
|
||||
}
|
||||
}
|
||||
err = ioutil.WriteFile("./assets/config/config.json", newconfigjson, 0644)
|
||||
if err != nil {
|
||||
return &common.HTTPError{
|
||||
Message: err.Error(),
|
||||
StatusCode: http.StatusBadRequest,
|
||||
}
|
||||
}
|
||||
w.Write([]byte("<script>window.location = '/admin#/Settings#saved';</script>"))
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func AddUser() common.Handler {
|
||||
|
||||
return func(rc *common.RouterContext, w http.ResponseWriter, r *http.Request) *common.HTTPError {
|
||||
|
|
|
@ -120,6 +120,11 @@ func Init() *mux.Router {
|
|||
admin.ListUsers(),
|
||||
)).Methods("GET")
|
||||
|
||||
r.Handle("/admin/settings", Handle(
|
||||
auth.RequireAuthorization(2),
|
||||
admin.ConfigurationManager(),
|
||||
)).Methods("GET", "POST")
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue