Split checkout widget into separate components
This commit is contained in:
@@ -324,71 +324,6 @@ func (wc *WebController) serveFile(path string) httprouter.Handle {
|
||||
}
|
||||
}
|
||||
|
||||
func (wc *WebController) serveForm(
|
||||
handler func(*TemplateData, *http.Request) Form,
|
||||
opts handlerOpts,
|
||||
) httprouter.Handle {
|
||||
return func(
|
||||
w http.ResponseWriter,
|
||||
r *http.Request,
|
||||
p httprouter.Params,
|
||||
) {
|
||||
if opts.NoEmbed {
|
||||
w.Header().Set("X-Frame-Options", "DENY")
|
||||
}
|
||||
|
||||
var td = wc.newTemplateData(w, r)
|
||||
if opts.Auth && !td.Authenticated {
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
// The handler retuns the form which will be rendered
|
||||
td.Form = handler(td, r)
|
||||
td.Title = td.Form.Title
|
||||
td.Form.Username = td.User.Username
|
||||
|
||||
// Execute the extra actions if any
|
||||
if td.Form.Extra.SetCookie != nil {
|
||||
w.Header().Del("Set-Cookie")
|
||||
http.SetCookie(w, td.Form.Extra.SetCookie)
|
||||
}
|
||||
if td.Form.Extra.RedirectTo != "" {
|
||||
http.Redirect(w, r, td.Form.Extra.RedirectTo, http.StatusSeeOther)
|
||||
log.Debug("redirect: %s", td.Form.Extra.RedirectTo)
|
||||
return // Don't need to render a form if the user is redirected
|
||||
}
|
||||
|
||||
// Remove the recaptcha field if captcha is disabled
|
||||
if wc.captchaKey() == "none" {
|
||||
for i, field := range td.Form.Fields {
|
||||
if field.Type == FieldTypeCaptcha {
|
||||
td.Form.Fields = append(
|
||||
td.Form.Fields[:i],
|
||||
td.Form.Fields[i+1:]...,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the entered values if the request was successful
|
||||
if td.Form.SubmitSuccess {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
for i, field := range td.Form.Fields {
|
||||
field.EnteredValue = ""
|
||||
td.Form.Fields[i] = field
|
||||
}
|
||||
} else if td.Form.Submitted {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
err := wc.templates.Run(w, r, "form_page", td)
|
||||
if err != nil && !util.IsNetError(err) {
|
||||
log.Error("Error executing form page: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wc *WebController) serveForbidden(w http.ResponseWriter, r *http.Request) {
|
||||
log.Debug("Forbidden: %s", r.URL)
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
|
Reference in New Issue
Block a user