1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-09-18 22:06:23 -07:00

Use generic page header for manage pages, add login template

This commit is contained in:
Eggbertx 2022-01-04 17:48:46 -08:00
parent c8d8af077b
commit b2318af7a3
12 changed files with 132 additions and 44 deletions

View file

@ -344,17 +344,26 @@ var actions = []Action{
username := request.FormValue("username")
password := request.FormValue("password")
redirectAction := request.FormValue("action")
if redirectAction == "" {
if redirectAction == "" || redirectAction == "logout" {
redirectAction = "announcements"
}
if username == "" || password == "" {
//assume that they haven't logged in
output = `<form method="POST" action="` + systemCritical.WebRoot + `manage?action=login" id="login-box" class="staff-form">` +
`<input type="hidden" name="redirect" value="` + redirectAction + `" />` +
`<input type="text" name="username" class="logindata" /><br />` +
`<input type="password" name="password" class="logindata" /><br />` +
`<input type="submit" value="Login" />` +
`</form>`
manageLoginBuffer := bytes.NewBufferString("")
if err = serverutil.MinifyTemplate(gctemplates.ManageLogin,
map[string]interface{}{
"webroot": config.GetSystemCriticalConfig().WebRoot,
"site_config": config.GetSiteConfig(),
"sections": gcsql.AllSections,
"boards": gcsql.AllBoards,
"board_config": config.GetBoardConfig(""),
"redirect": redirectAction,
}, manageLoginBuffer, "text/html"); err != nil {
return "", errors.New(gclog.Print(gclog.LErrorLog,
"Error executing staff login page template: "+err.Error()))
}
output = manageLoginBuffer.String()
} else {
key := gcutil.Md5Sum(request.RemoteAddr + username + password + systemCritical.RandomSeed + gcutil.RandomString(3))[0:10]
createSession(key, username, password, request, writer)
@ -371,7 +380,7 @@ var actions = []Action{
cookie.MaxAge = 0
cookie.Expires = time.Now().Add(-7 * 24 * time.Hour)
http.SetCookie(writer, cookie)
return "Logged out successfully", nil
return "<br />Logged out successfully", nil
}},
{
ID: "announcements",

View file

@ -5,9 +5,8 @@ import (
"fmt"
"net/http"
"github.com/gochan-org/gochan/pkg/config"
"github.com/gochan-org/gochan/pkg/building"
"github.com/gochan-org/gochan/pkg/gclog"
"github.com/gochan-org/gochan/pkg/gctemplates"
"github.com/gochan-org/gochan/pkg/gcutil"
"github.com/gochan-org/gochan/pkg/serverutil"
)
@ -116,18 +115,16 @@ func CallManageFunction(writer http.ResponseWriter, request *http.Request) {
serverutil.MinifyWriter(writer, []byte(outputJSON), "application/json")
return
}
managePageBuffer.WriteString("<!DOCTYPE html><html><head>")
criticalCfg := config.GetSystemCriticalConfig()
if err = serverutil.MinifyTemplate(gctemplates.ManageHeader,
map[string]interface{}{
"webroot": criticalCfg.WebRoot,
},
&managePageBuffer, "text/html"); err != nil {
serverutil.ServeErrorPage(writer, gclog.Print(gclog.LErrorLog|gclog.LStaffLog,
"Error executing manage page header template: ", err.Error()))
if err = building.BuildPageHeader(&managePageBuffer); err != nil {
serveError(writer, "error", actionID,
gclog.Print(gclog.LErrorLog, "Failed writing page header: ", err.Error()), false)
return
}
managePageBuffer.WriteString("<br />" + fmt.Sprint(output) + "<br /><br />")
if err = building.BuildPageFooter(&managePageBuffer); err != nil {
serveError(writer, "error", actionID,
gclog.Print(gclog.LErrorLog, "Failed writing page footer: ", err.Error()), false)
return
}
managePageBuffer.WriteString(fmt.Sprint(output, "</body></html>"))
writer.Write(managePageBuffer.Bytes())
}