Fix coupon form a bit

This commit is contained in:
2021-11-29 23:32:25 +01:00
parent ef083ff087
commit d37bddb720
3 changed files with 11 additions and 3 deletions

View File

@@ -9,7 +9,6 @@
</div>
{{else}}
<div id="submit_result" class="highlight_red">
Something went wrong, please correct these errors before continuing:<br/>
<ul>
{{range $msg := .SubmitMessages}}
<li>{{$msg}}</li>

View File

@@ -226,6 +226,15 @@ func (wc *WebController) couponForm(td *TemplateData, r *http.Request) (f Form)
return f
}
if !td.Authenticated {
f.Submitted = true
f.SubmitMessages = []template.HTML{
`You need to log in to a pixeldrain account to use the coupon. ` +
`<a href="/login">Click here to log in</a>`,
}
return f
}
if f.ReadInput(r) {
if err := td.PixelAPI.PostCouponRedeem(r.FormValue("code")); err != nil {
formAPIError(err, &f)

View File

@@ -193,8 +193,8 @@ func New(
{GET, "knoxfs_activate", wc.serveForm(wc.knoxfsLinkForm, handlerOpts{Auth: true})},
{PST, "knoxfs_activate", wc.serveForm(wc.knoxfsLinkForm, handlerOpts{Auth: true})},
{GET, "coupon_redeem", wc.serveForm(wc.couponForm, handlerOpts{Auth: true})},
{PST, "coupon_redeem", wc.serveForm(wc.couponForm, handlerOpts{Auth: true})},
{GET, "coupon_redeem", wc.serveForm(wc.couponForm, handlerOpts{})},
{PST, "coupon_redeem", wc.serveForm(wc.couponForm, handlerOpts{})},
// Admin settings
{GET, "admin" /* */, wc.serveTemplate("admin", handlerOpts{Auth: true})},