reformatted IP Ban page and shifted specific rendering to AmSendPageData
This commit is contained in:
@@ -57,20 +57,9 @@ func AmErrorHandler(err error, c echo.Context) {
|
||||
if c.Response().Committed {
|
||||
return
|
||||
}
|
||||
|
||||
errCode := http.StatusInternalServerError
|
||||
if he, ok := err.(*echo.HTTPError); ok {
|
||||
errCode = he.Code
|
||||
}
|
||||
|
||||
amctxt := ui.AmContextFromEchoContext(c)
|
||||
amctxt.SetLeftMenu("top")
|
||||
amctxt.SetRC(errCode)
|
||||
amctxt.VarMap().Set("error", err.Error())
|
||||
// TODO: come up with a way to shift templates and titles for different error codes
|
||||
amctxt.VarMap().Set("amsterdam_pageTitle", "Amsterdam Internal Server Error")
|
||||
cerr := ui.AmSendPageData(c, amctxt, "framed", "error.jet")
|
||||
cerr := ui.AmSendPageData(c, amctxt, "error", err)
|
||||
if cerr != nil {
|
||||
log.Errorf("Error rendering error %d (%v): %v", errCode, err, cerr)
|
||||
log.Errorf("Error rendering error (%v): %v", err, cerr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +299,6 @@ func JumpToShortcut(ctxt ui.AmContext) (string, any) {
|
||||
}
|
||||
scope, target := link.Classify()
|
||||
if scope != "global" {
|
||||
ctxt.SetRC(http.StatusNotFound)
|
||||
return "error", echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("not found: %s", ctxt.URLParam("postlink")))
|
||||
}
|
||||
if err = link.VerifyNames(ctxt.Ctx()); err != nil {
|
||||
|
||||
+1
-4
@@ -32,10 +32,7 @@ func IPBanTest(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
// but let the request pass anyway
|
||||
} else if banmsg != "" {
|
||||
amctxt := AmContextFromEchoContext(c)
|
||||
amctxt.VarMap().Set("amsterdam_pageTitle", "IP Address Banned")
|
||||
amctxt.VarMap().Set("message", banmsg)
|
||||
amctxt.SetRC(http.StatusForbidden)
|
||||
return AmSendPageData(c, amctxt, "framed", "ipban.jet")
|
||||
return AmSendPageData(c, amctxt, "ipban", banmsg)
|
||||
}
|
||||
return next(c)
|
||||
}
|
||||
|
||||
+11
-3
@@ -36,9 +36,9 @@ import (
|
||||
* Standard Go error status.
|
||||
*/
|
||||
func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data any) error {
|
||||
var err error
|
||||
|
||||
if command == "error" {
|
||||
// Preprocess certain commands into different ones.
|
||||
switch command {
|
||||
case "error":
|
||||
httprc := amctxt.RC()
|
||||
message := ""
|
||||
if data == nil {
|
||||
@@ -73,8 +73,16 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
|
||||
amctxt.SetRC(httprc)
|
||||
command = "framed"
|
||||
data = "error.jet"
|
||||
case "ipban":
|
||||
amctxt.VarMap().Set("amsterdam_pageTitle", "IP Address Banned")
|
||||
amctxt.VarMap().Set("message", data)
|
||||
amctxt.SetRC(http.StatusForbidden)
|
||||
command = "framed"
|
||||
data = "ipban.jet"
|
||||
}
|
||||
|
||||
// Process commands.
|
||||
var err error
|
||||
switch command {
|
||||
case "bytes":
|
||||
err = ctxt.Blob(amctxt.RC(), amctxt.OutputType(), data.([]byte))
|
||||
|
||||
+18
-7
@@ -1,17 +1,28 @@
|
||||
{*
|
||||
* Amsterdam Web Communities System
|
||||
* Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved
|
||||
* Copyright (c) 2025-2026 Erbosoft Metaverse Design Solutions, All Rights Reserved
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*}
|
||||
<div class="flex">
|
||||
<div class="flex-1 p-4">
|
||||
<div class="mb-8">
|
||||
<h1 class="text-blue-800 text-4xl font-bold mb-2">This IP Address Has Been Banned</h1>
|
||||
<hr class="border-2 border-gray-400 w-4/5 mb-4">
|
||||
<p class="text-black text-sm mb-4"><strong>{{ message }}</strong></p>
|
||||
<div class="p-4">
|
||||
<!-- IP Ban Dialog -->
|
||||
<div class="max-w-2xl w-full">
|
||||
<div class="bg-white border-2 border-gray-600 rounded-lg shadow-2xl overflow-hidden">
|
||||
<!-- Dialog Header -->
|
||||
<div class="bg-gray-600 px-6 py-4">
|
||||
<h1 class="text-white text-2xl font-bold text-center flex items-center justify-center gap-3">
|
||||
<span class="text-3xl">⛔</span>This IP Address Has Been Banned<span class="text-3xl">⛔</span>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<!-- Dialog Body -->
|
||||
<div class="px-8 py-8">
|
||||
<div class="text-center mb-8">
|
||||
<p class="text-black-800 text-lg leading-relaxed"><b>{{ message }}</b></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user