mirror of
https://github.com/writeas/writefreely
synced 2025-02-03 14:47:32 +01:00
Support editing some config values in admin UI
This is almost all of T541
This commit is contained in:
parent
09a3fe09fe
commit
9fe4b09de5
34
admin.go
34
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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
<li><a href="#page-privacy">Edit Privacy page</a></li>
|
||||
{{end}}
|
||||
<li><a href="#reset-pass">Reset user password</a></li>
|
||||
<li><a href="#config">Configuration</a></li>
|
||||
<li><a href="#monitor">Application monitor</a></li>
|
||||
</ul>
|
||||
|
||||
@ -79,6 +83,38 @@ function savePage(el) {
|
||||
|
||||
<hr />
|
||||
|
||||
<h2><a name="config"></a>App Configuration</h2>
|
||||
|
||||
{{if .ConfigMessage}}<p class="success" style="text-align: center">{{.ConfigMessage}}</p>{{end}}
|
||||
|
||||
<form action="/admin/update/config" method="post">
|
||||
<div class="ui attached table segment">
|
||||
<dl class="dl-horizontal admin-dl-horizontal">
|
||||
<dt>Site Name</dt>
|
||||
<dd><input type="text" name="site_name" id="site_name" class="inline" value="{{.Config.SiteName}}" style="width: 14em;" /></dd>
|
||||
<dt>Host</dt>
|
||||
<dd>{{.Config.Host}}</dd>
|
||||
<dt>User Mode</dt>
|
||||
<dd>{{if .Config.SingleUser}}Single user{{else}}Multiple users{{end}}</dd>
|
||||
<dt><label for="open_registration">Open Registrations</label></dt>
|
||||
<dd><input type="checkbox" name="open_registration" id="open_registration" {{if .Config.OpenRegistration}}checked="checked"{{end}} /></dd>
|
||||
<dt><label for="min_username_len">Minimum Username Length</label></dt>
|
||||
<dd><input type="number" name="min_username_len" id="min_username_len" class="inline" min="1" max="100" value="{{.Config.MinUsernameLen}}" /></dd>
|
||||
<dt><label for="max_blogs">Maximum Blogs per User</label></dt>
|
||||
<dd><input type="number" name="max_blogs" id="max_blogs" class="inline" min="1" value="{{.Config.MaxBlogs}}" /></dd>
|
||||
<dt><label for="federation">Federation</label></dt>
|
||||
<dd><input type="checkbox" name="federation" id="federation" {{if .Config.Federation}}checked="checked"{{end}} /></dd>
|
||||
<dt><label for="public_stats">Public Stats</label></dt>
|
||||
<dd><input type="checkbox" name="public_stats" id="public_stats" {{if .Config.PublicStats}}checked="checked"{{end}} /></dd>
|
||||
<dt><label for="private">Private Instance</label></dt>
|
||||
<dd><input type="checkbox" name="private" id="private" {{if .Config.Private}}checked="checked"{{end}} /></dd>
|
||||
</dl>
|
||||
<input type="submit" value="Save Configuration" />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<hr />
|
||||
|
||||
<h2><a name="monitor"></a>Application</h2>
|
||||
|
||||
<div class="ui attached table segment">
|
||||
|
Loading…
x
Reference in New Issue
Block a user