diff --git a/admin.go b/admin.go index c5e762b..7785a5f 100644 --- a/admin.go +++ b/admin.go @@ -6,8 +6,10 @@ import ( "github.com/gorilla/mux" "github.com/writeas/impart" "github.com/writeas/web-core/auth" + "github.com/writeas/writefreely/config" "net/http" "runtime" + "strconv" "time" ) @@ -61,14 +63,19 @@ func handleViewAdminDash(app *app, u *User, w http.ResponseWriter, r *http.Reque updateAppStats() p := struct { *UserPage - Message string SysStatus systemStatus + Config config.AppCfg + + Message, ConfigMessage string AboutPage, PrivacyPage string }{ UserPage: NewUserPage(app, r, u, "Admin", nil), - Message: r.FormValue("m"), SysStatus: sysStatus, + Config: app.cfg.App, + + Message: r.FormValue("m"), + ConfigMessage: r.FormValue("cm"), } var err error @@ -104,6 +111,29 @@ func handleAdminUpdateSite(app *app, u *User, w http.ResponseWriter, r *http.Req return impart.HTTPError{http.StatusFound, "/admin" + m + "#page-" + id} } +func handleAdminUpdateConfig(app *app, u *User, w http.ResponseWriter, r *http.Request) error { + app.cfg.App.SiteName = r.FormValue("site_name") + app.cfg.App.OpenRegistration = r.FormValue("open_registration") == "on" + mul, err := strconv.Atoi(r.FormValue("min_username_len")) + if err == nil { + app.cfg.App.MinUsernameLen = mul + } + mb, err := strconv.Atoi(r.FormValue("max_blogs")) + if err == nil { + app.cfg.App.MaxBlogs = mb + } + app.cfg.App.Federation = r.FormValue("federation") == "on" + app.cfg.App.PublicStats = r.FormValue("public_stats") == "on" + app.cfg.App.Private = r.FormValue("private") == "on" + + m := "?cm=Configuration+saved." + err = config.Save(app.cfg) + if err != nil { + m = "?cm=" + err.Error() + } + return impart.HTTPError{http.StatusFound, "/admin" + m + "#config"} +} + func updateAppStats() { sysStatus.Uptime = tool.TimeSincePro(appStartTime) diff --git a/routes.go b/routes.go index 9b376bf..df57373 100644 --- a/routes.go +++ b/routes.go @@ -116,6 +116,7 @@ func initRoutes(handler *Handler, r *mux.Router, cfg *config.Config, db *datasto write.HandleFunc("/auth/login", handler.Web(webLogin, UserLevelNoneRequired)).Methods("POST") write.HandleFunc("/admin", handler.Admin(handleViewAdminDash)).Methods("GET") + write.HandleFunc("/admin/update/config", handler.Admin(handleAdminUpdateConfig)).Methods("POST") write.HandleFunc("/admin/update/{page}", handler.Admin(handleAdminUpdateSite)).Methods("POST") // Handle special pages first diff --git a/templates/user/admin.tmpl b/templates/user/admin.tmpl index bdfbd71..c855fa4 100644 --- a/templates/user/admin.tmpl +++ b/templates/user/admin.tmpl @@ -7,6 +7,9 @@ ul.pagenav {list-style: none;} form { margin: 0 0 2em; } +form dt { + line-height: inherit; +} .ui.divider:not(.vertical):not(.horizontal) { border-top: 1px solid rgba(34,36,38,.15); border-bottom: 1px solid rgba(255,255,255,.1); @@ -47,6 +50,7 @@ function savePage(el) {
  • Edit Privacy page
  • {{end}}
  • Reset user password
  • +
  • Configuration
  • Application monitor
  • @@ -79,6 +83,38 @@ function savePage(el) {
    +

    App Configuration

    + + {{if .ConfigMessage}}

    {{.ConfigMessage}}

    {{end}} + +
    +
    +
    +
    Site Name
    +
    +
    Host
    +
    {{.Config.Host}}
    +
    User Mode
    +
    {{if .Config.SingleUser}}Single user{{else}}Multiple users{{end}}
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    + +
    +

    Application