adding smarter error recovery and reformatted the unjoin page

This commit is contained in:
2026-02-10 22:32:18 -07:00
parent 611881b7dc
commit 0e5a4bc5a3
5 changed files with 79 additions and 33 deletions
+18 -1
View File
@@ -15,6 +15,7 @@ import (
"fmt" "fmt"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"net/url"
"strconv" "strconv"
"time" "time"
@@ -59,6 +60,7 @@ type AmContext interface {
IsMember() bool IsMember() bool
IsMemberLocked() bool IsMemberLocked() bool
LeftMenu() string LeftMenu() string
Locator() string
OutputType() string OutputType() string
Parameter(string) string Parameter(string) string
QueryParamInt(string, int) int QueryParamInt(string, int) int
@@ -239,11 +241,14 @@ func (c *amContext) FormFile(name string) (*multipart.FileHeader, error) {
return c.echoContext.FormFile(name) return c.echoContext.FormFile(name)
} }
// emptyMap is the return from FrameMetadata if the specified selector is not present.
var emptyMap map[string]string = make(map[string]string)
// FrameMetadata returns the frame metadata for a specified type. // FrameMetadata returns the frame metadata for a specified type.
func (c *amContext) FrameMetadata(selector int) map[string]string { func (c *amContext) FrameMetadata(selector int) map[string]string {
rmap, ok := c.frameMeta[selector] rmap, ok := c.frameMeta[selector]
if !ok { if !ok {
rmap = make(map[string]string) rmap = emptyMap
} }
return rmap return rmap
} }
@@ -296,6 +301,18 @@ func (c *amContext) LeftMenu() string {
} }
} }
// Locator returns the current URL path minus the scheme and host, so it's a site-relative locator.
func (c *amContext) Locator() string {
tmp := url.URL{
Path: c.echoContext.Request().URL.Path,
RawPath: c.echoContext.Request().URL.RawPath,
RawQuery: c.echoContext.Request().URL.RawQuery,
Fragment: c.echoContext.Request().URL.Fragment,
RawFragment: c.echoContext.Request().URL.RawFragment,
}
return tmp.String()
}
// OutputType returns the MIME output type set for the current operation. // OutputType returns the MIME output type set for the current operation.
func (c *amContext) OutputType() string { func (c *amContext) OutputType() string {
return c.outputType return c.outputType
+6
View File
@@ -70,6 +70,9 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
} }
amctxt.SetFrameTitle("Internal Server Error") amctxt.SetFrameTitle("Internal Server Error")
amctxt.VarMap().Set("error", message) amctxt.VarMap().Set("error", message)
if tmp := amctxt.GetSession("lastKnownGood"); tmp != nil {
amctxt.VarMap().Set("recovery", tmp)
}
command = "framed" command = "framed"
data = "error.jet" data = "error.jet"
case "ipban": case "ipban":
@@ -148,6 +151,9 @@ func AmWrap(myfunc PageFunc) echo.HandlerFunc {
// Exec the wrapped function. // Exec the wrapped function.
command, arg := myfunc(ctxt) command, arg := myfunc(ctxt)
if command != "error" && command != "ipban" {
ctxt.SetSession("lastKnownGood", ctxt.Locator())
}
if err := ctxt.SaveSession(); err != nil { if err := ctxt.SaveSession(); err != nil {
c.Logger().Errorf("Session save error: %v", err) c.Logger().Errorf("Session save error: %v", err)
return err return err
+1 -1
View File
@@ -9,7 +9,7 @@
<!-- BEGIN DIALOG {{ __dialog.Name }} --> <!-- BEGIN DIALOG {{ __dialog.Name }} -->
<div class="p-4"> <div class="p-4">
<div class="mb-6"> <div class="mb-6">
<div class=" flex items-baseline gap-2"> <div class="flex items-baseline gap-2">
<h1 class="text-blue-800 text-4xl font-bold mb-2">{{ __dialog.Title }}</h1> <h1 class="text-blue-800 text-4xl font-bold mb-2">{{ __dialog.Title }}</h1>
{{ if __dialog.Subtitle != "" }} {{ if __dialog.Subtitle != "" }}
<span class="text-blue-800 text-2xl font-bold ml-2">{{ __dialog.Subtitle }}</span> <span class="text-blue-800 text-2xl font-bold ml-2">{{ __dialog.Subtitle }}</span>
+8
View File
@@ -25,11 +25,19 @@
<!-- Action Buttons --> <!-- Action Buttons -->
<div class="flex gap-4 justify-center"> <div class="flex gap-4 justify-center">
{{ if isset(recovery) }}
<a href="{{ recovery }}"
class="bg-blue-600 hover:bg-blue-700 text-white font-bold px-8 py-3 rounded-lg text-lg transition-colors shadow-lg hover:shadow-xl flex items-center gap-2">
<span class="text-xl">↩️</span>
Go Back
</a>
{{ else }}
<a href="/" <a href="/"
class="bg-gray-600 hover:bg-gray-700 text-white font-bold px-8 py-3 rounded-lg text-lg transition-colors shadow-lg hover:shadow-xl flex items-center gap-2"> class="bg-gray-600 hover:bg-gray-700 text-white font-bold px-8 py-3 rounded-lg text-lg transition-colors shadow-lg hover:shadow-xl flex items-center gap-2">
<span class="text-xl">↩️</span> <span class="text-xl">↩️</span>
Return to Home Page Return to Home Page
</a> </a>
{{ end }}
</div> </div>
</div> </div>
</div> </div>
+26 -11
View File
@@ -1,6 +1,6 @@
{* {*
* Amsterdam Web Communities System * 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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -8,16 +8,27 @@
*} *}
<div class="p-4"> <div class="p-4">
<div class="mb-6"> <div class="mb-6">
<h1 class="text-blue-800 text-4xl font-bold mb-2">Unjoin Community</h1> <div class="flex items-baseline gap-2">
<h1 class="text-blue-800 text-4xl font-bold mb-2">Unjoin Community:</h1>
<span class="text-blue-800 text-2xl font-bold ml-2">{{ comm.Name }}</span> <span class="text-blue-800 text-2xl font-bold ml-2">{{ comm.Name }}</span>
</div>
<hr class="border-2 border-gray-400 w-4/5 mb-4"> <hr class="border-2 border-gray-400 w-4/5 mb-4">
</div> </div>
<div class="bg-yellow-50 p-6 rounded-lg"> <div class="max-w-2xl w-full">
<div class="space-y-4"> <div class="bg-white border-2 border-red-600 rounded-lg shadow-2xl overflow-hidden">
<h2 class="text-lg font-bold text-black mb-4">⚠️ Warning</h2> <!-- Dialog Header -->
<p class="text-black"> <div class="bg-red-600 px-6 py-4">
You are about to unjoin the {{ comm.Name }} community. <h1 class="text-white text-2xl font-bold text-center flex items-center justify-center gap-3">
<span class="text-3xl">⚠️</span> Warning <span class="text-3xl">⚠️</span>
</h1>
</div>
<!-- Dialog Body -->
<div class="px-8 py-8">
<div class="text-center mb-8">
<p class="text-gray-800 text-lg leading-relaxed">
You are about to unjoin the <span class="text-red-800 font-bold">{{ comm.Name }}</span> community.
{{ if comm.MembersOnly }} {{ if comm.MembersOnly }}
You will lose access to all content of the community, as well as the ability to interact with You will lose access to all content of the community, as well as the ability to interact with
the community as a whole. the community as a whole.
@@ -25,17 +36,21 @@
You will lose the ability to interact with the community's members and content. You will lose the ability to interact with the community's members and content.
{{ end }} {{ end }}
</p> </p>
<p class="text-black">Please confirm if you wish to proceed.</p> <p class="text-gray-800 text-lg font-bold mt-4">Are you sure you want to do this?</p>
</div> </div>
<div class="flex justify-center gap-4 mt-6">
<!-- Action Buttons -->
<div class="flex gap-4 justify-center">
<form method="POST" action="/comm/{{ comm.Alias }}/unjoin"> <form method="POST" action="/comm/{{ comm.Alias }}/unjoin">
<button type="submit" name="cancel" <button type="submit" name="cancel"
class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-2 rounded font-medium transition-colors">Cancel</button> class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-2 rounded font-medium transition-colors">Cancel</button>
<button type="submit" name="unjoin" <button type="submit" name="unjoin"
class="bg-red-600 hover:bg-red-700 text-white px-6 py-2 rounded font-medium transition-colors"> class="bg-red-600 hover:bg-red-700 text-white px-6 py-2 rounded font-medium transition-colors">
Unjoin {{ comm.Name }} ↗️ Unjoin {{ comm.Name }}
</button> </button>
</form> </form>
</div> </div>
</div> </div>
</div>
</div>
</div> </div>