mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 01:57:02 +00:00
Fix for flashes not clearing bug
This commit is contained in:
@@ -69,9 +69,9 @@
|
|||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{{with .ctx.Session.Flashes "errors"}}
|
{{with .errorFlash}}
|
||||||
<div class="alert alert-danger">
|
<div class="alert alert-danger">
|
||||||
<p>Please fix the following errors and resubmit:<p>
|
<p>Please fix the following errors and try again:<p>
|
||||||
<ul>
|
<ul>
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<li>{{.}}</li>
|
<li>{{.}}</li>
|
||||||
|
|||||||
@@ -64,16 +64,6 @@ $(document).ready(function() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="message-container" class="col-md-9">
|
<div id="message-container" class="col-md-9">
|
||||||
{{with .ctx.Session.Flashes "errors"}}
|
|
||||||
<div class="errors">
|
|
||||||
<p>Please fix the following errors and resubmit:<p>
|
|
||||||
<ul>
|
|
||||||
{{range .}}
|
|
||||||
<li>{{.}}</li>
|
|
||||||
{{end}}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
<div id="message-content">
|
<div id="message-content">
|
||||||
<p>Select a message at left, or enter a different username into the box on upper right.</p>
|
<p>Select a message at left, or enter a different username into the box on upper right.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -17,14 +17,12 @@ func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *httpd.Context)
|
|||||||
// Form values must be validated manually
|
// Form values must be validated manually
|
||||||
name := req.FormValue("name")
|
name := req.FormValue("name")
|
||||||
selected := req.FormValue("id")
|
selected := req.FormValue("id")
|
||||||
|
|
||||||
if len(name) == 0 {
|
if len(name) == 0 {
|
||||||
ctx.Session.AddFlash("Account name is required", "errors")
|
ctx.Session.AddFlash("Account name is required", "errors")
|
||||||
_ = ctx.Session.Save(req, w)
|
_ = ctx.Session.Save(req, w)
|
||||||
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
|
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
name, err = smtpd.ParseMailboxName(name)
|
name, err = smtpd.ParseMailboxName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Session.AddFlash(err.Error(), "errors")
|
ctx.Session.AddFlash(err.Error(), "errors")
|
||||||
@@ -32,17 +30,19 @@ func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *httpd.Context)
|
|||||||
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
|
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remember this mailbox was visited
|
// Remember this mailbox was visited
|
||||||
RememberMailbox(ctx, name)
|
RememberMailbox(ctx, name)
|
||||||
|
// Get flash messages, save session
|
||||||
|
errorFlash := ctx.Session.Flashes("errors")
|
||||||
if err = ctx.Session.Save(req, w); err != nil {
|
if err = ctx.Session.Save(req, w); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Render template
|
||||||
return httpd.RenderTemplate("mailbox/index.html", w, map[string]interface{}{
|
return httpd.RenderTemplate("mailbox/index.html", w, map[string]interface{}{
|
||||||
"ctx": ctx,
|
"ctx": ctx,
|
||||||
"name": name,
|
"errorFlash": errorFlash,
|
||||||
"selected": selected,
|
"name": name,
|
||||||
|
"selected": selected,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ func MailboxLink(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (
|
|||||||
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
|
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
// Build redirect
|
||||||
uri := fmt.Sprintf("%s?name=%s&id=%s", httpd.Reverse("MailboxIndex"), name, id)
|
uri := fmt.Sprintf("%s?name=%s&id=%s", httpd.Reverse("MailboxIndex"), name, id)
|
||||||
http.Redirect(w, req, uri, http.StatusSeeOther)
|
http.Redirect(w, req, uri, http.StatusSeeOther)
|
||||||
return nil
|
return nil
|
||||||
@@ -81,7 +81,7 @@ func MailboxList(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (
|
|||||||
return fmt.Errorf("Failed to get messages for %v: %v", name, err)
|
return fmt.Errorf("Failed to get messages for %v: %v", name, err)
|
||||||
}
|
}
|
||||||
log.Tracef("Got %v messsages", len(messages))
|
log.Tracef("Got %v messsages", len(messages))
|
||||||
|
// Render partial template
|
||||||
return httpd.RenderPartial("mailbox/_list.html", w, map[string]interface{}{
|
return httpd.RenderPartial("mailbox/_list.html", w, map[string]interface{}{
|
||||||
"ctx": ctx,
|
"ctx": ctx,
|
||||||
"name": name,
|
"name": name,
|
||||||
@@ -115,10 +115,9 @@ func MailboxShow(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("ReadBody(%q) failed: %v", id, err)
|
return fmt.Errorf("ReadBody(%q) failed: %v", id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
body := template.HTML(httpd.TextToHTML(mime.Text))
|
body := template.HTML(httpd.TextToHTML(mime.Text))
|
||||||
htmlAvailable := mime.HTML != ""
|
htmlAvailable := mime.HTML != ""
|
||||||
|
// Render partial template
|
||||||
return httpd.RenderPartial("mailbox/_show.html", w, map[string]interface{}{
|
return httpd.RenderPartial("mailbox/_show.html", w, map[string]interface{}{
|
||||||
"ctx": ctx,
|
"ctx": ctx,
|
||||||
"name": name,
|
"name": name,
|
||||||
@@ -156,7 +155,7 @@ func MailboxHTML(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("ReadBody(%q) failed: %v", id, err)
|
return fmt.Errorf("ReadBody(%q) failed: %v", id, err)
|
||||||
}
|
}
|
||||||
|
// Render partial template
|
||||||
w.Header().Set("Content-Type", "text/html; charset=UTF-8")
|
w.Header().Set("Content-Type", "text/html; charset=UTF-8")
|
||||||
return httpd.RenderPartial("mailbox/_html.html", w, map[string]interface{}{
|
return httpd.RenderPartial("mailbox/_html.html", w, map[string]interface{}{
|
||||||
"ctx": ctx,
|
"ctx": ctx,
|
||||||
@@ -193,7 +192,7 @@ func MailboxSource(w http.ResponseWriter, req *http.Request, ctx *httpd.Context)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("ReadRaw(%q) failed: %v", id, err)
|
return fmt.Errorf("ReadRaw(%q) failed: %v", id, err)
|
||||||
}
|
}
|
||||||
|
// Output message source
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
if _, err := io.WriteString(w, *raw); err != nil {
|
if _, err := io.WriteString(w, *raw); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -221,7 +220,6 @@ func MailboxDownloadAttach(w http.ResponseWriter, req *http.Request, ctx *httpd.
|
|||||||
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
|
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
mb, err := ctx.DataStore.MailboxFor(name)
|
mb, err := ctx.DataStore.MailboxFor(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This doesn't indicate not found, likely an IO error
|
// This doesn't indicate not found, likely an IO error
|
||||||
@@ -247,7 +245,7 @@ func MailboxDownloadAttach(w http.ResponseWriter, req *http.Request, ctx *httpd.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
part := body.Attachments[num]
|
part := body.Attachments[num]
|
||||||
|
// Output attachment
|
||||||
w.Header().Set("Content-Type", "application/octet-stream")
|
w.Header().Set("Content-Type", "application/octet-stream")
|
||||||
w.Header().Set("Content-Disposition", "attachment")
|
w.Header().Set("Content-Disposition", "attachment")
|
||||||
if _, err := io.Copy(w, part); err != nil {
|
if _, err := io.Copy(w, part); err != nil {
|
||||||
@@ -275,7 +273,6 @@ func MailboxViewAttach(w http.ResponseWriter, req *http.Request, ctx *httpd.Cont
|
|||||||
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
|
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
mb, err := ctx.DataStore.MailboxFor(name)
|
mb, err := ctx.DataStore.MailboxFor(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This doesn't indicate not found, likely an IO error
|
// This doesn't indicate not found, likely an IO error
|
||||||
@@ -301,7 +298,7 @@ func MailboxViewAttach(w http.ResponseWriter, req *http.Request, ctx *httpd.Cont
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
part := body.Attachments[num]
|
part := body.Attachments[num]
|
||||||
|
// Output attachment
|
||||||
w.Header().Set("Content-Type", part.ContentType)
|
w.Header().Set("Content-Type", part.ContentType)
|
||||||
if _, err := io.Copy(w, part); err != nil {
|
if _, err := io.Copy(w, part); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -16,17 +16,30 @@ func RootIndex(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to load greeting: %v", err)
|
return fmt.Errorf("Failed to load greeting: %v", err)
|
||||||
}
|
}
|
||||||
|
// Get flash messages, save session
|
||||||
|
errorFlash := ctx.Session.Flashes("errors")
|
||||||
|
if err = ctx.Session.Save(req, w); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Render template
|
||||||
return httpd.RenderTemplate("root/index.html", w, map[string]interface{}{
|
return httpd.RenderTemplate("root/index.html", w, map[string]interface{}{
|
||||||
"ctx": ctx,
|
"ctx": ctx,
|
||||||
"greeting": template.HTML(string(greeting)),
|
"errorFlash": errorFlash,
|
||||||
|
"greeting": template.HTML(string(greeting)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// RootMonitor serves the Inbucket monitor page
|
// RootMonitor serves the Inbucket monitor page
|
||||||
func RootMonitor(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) {
|
func RootMonitor(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) {
|
||||||
|
// Get flash messages, save session
|
||||||
|
errorFlash := ctx.Session.Flashes("errors")
|
||||||
|
if err = ctx.Session.Save(req, w); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Render template
|
||||||
return httpd.RenderTemplate("root/monitor.html", w, map[string]interface{}{
|
return httpd.RenderTemplate("root/monitor.html", w, map[string]interface{}{
|
||||||
"ctx": ctx,
|
"ctx": ctx,
|
||||||
|
"errorFlash": errorFlash,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,8 +51,15 @@ func RootStatus(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (e
|
|||||||
config.GetPOP3Config().IP4port)
|
config.GetPOP3Config().IP4port)
|
||||||
webListener := fmt.Sprintf("%s:%d", config.GetWebConfig().IP4address.String(),
|
webListener := fmt.Sprintf("%s:%d", config.GetWebConfig().IP4address.String(),
|
||||||
config.GetWebConfig().IP4port)
|
config.GetWebConfig().IP4port)
|
||||||
|
// Get flash messages, save session
|
||||||
|
errorFlash := ctx.Session.Flashes("errors")
|
||||||
|
if err = ctx.Session.Save(req, w); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Render template
|
||||||
return httpd.RenderTemplate("root/status.html", w, map[string]interface{}{
|
return httpd.RenderTemplate("root/status.html", w, map[string]interface{}{
|
||||||
"ctx": ctx,
|
"ctx": ctx,
|
||||||
|
"errorFlash": errorFlash,
|
||||||
"version": config.Version,
|
"version": config.Version,
|
||||||
"buildDate": config.BuildDate,
|
"buildDate": config.BuildDate,
|
||||||
"smtpListener": smtpListener,
|
"smtpListener": smtpListener,
|
||||||
|
|||||||
Reference in New Issue
Block a user