Make form for linking patreon subscription

This commit is contained in:
2020-10-19 21:28:11 +02:00
parent 55c2f66709
commit e552a3d8a6
5 changed files with 124 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
{{define "patreon_confirm"}}<!DOCTYPE html>
<html lang="en">
<head>
{{template "meta_tags" "E-mail verification"}}
{{template "user_style" .}}
</head>
<body>
{{template "page_top" .}}
<div class="page_content">
<div class="limit_width">
{{if eq .Other "success"}}
<h1>Success!</h1>
<p>
Your account's e-mail address has been updated.
</p>
{{else if eq .Other "not_found"}}
<h1>E-mail change failed</h1>
<p>
This e-mail change request does not exist or has expired.
Please try again if you still want to change your e-mail
address.
</p>
{{else}}
<h1>Error</h1>
<p>
Something went wrong while processing this request. Please
try again later.
</p>
{{end}}
</div>
</div>
{{template "page_bottom" .}}
{{template "analytics"}}
</body>
</html>
{{end}}

View File

@@ -59,6 +59,8 @@
{{if eq $val $field.DefaultValue}}checked="checked"{{end}}/>
<label for="input_{{$field.Name}}_choice_{{$val}}">{{$val}}</label><br/>
{{ end }}
{{else if eq $field.Type "description"}}
<p>{{$field.DefaultValue}}</p>
{{end}}
</td>
{{end}}

View File

@@ -91,6 +91,7 @@ const (
FieldTypeCurrentPassword FieldType = "current-password"
FieldTypeNewPassword FieldType = "new-password"
FieldTypeCaptcha FieldType = "captcha"
FieldTypeDescription FieldType = "description"
)
// ReadInput reads the form of a request and fills in the values for each field.

View File

@@ -217,3 +217,83 @@ func (wc *WebController) usernameForm(td *TemplateData, r *http.Request) (f Form
}
return f
}
func (wc *WebController) patreonLinkForm(td *TemplateData, r *http.Request) (f Form) {
f.Name = "link_patreon_subscription"
f.Title = "Link Patreon pledge to pixeldrain account"
f.SubmitLabel = "Submit"
if r.FormValue("key") == "" {
f.Submitted = true
f.SubmitMessages = []template.HTML{"Patron ID not found"}
return f
}
patron, err := td.PixelAPI.PatreonByID(r.FormValue("key"))
if err != nil && err.Error() == "not_found" {
f.Submitted = true
f.SubmitMessages = []template.HTML{"Patron ID not found"}
return f
} else if err != nil {
f.Submitted = true
formAPIError(err, &f)
return f
}
f.Fields = []Field{{
Name: "1",
Label: "",
DefaultValue: "",
Description: "<h3>Please confirm that the following information is correct:</h3>",
Type: FieldTypeDescription,
}, {
Name: "2",
Label: "Pixeldrain username",
DefaultValue: td.User.Username,
Type: FieldTypeDescription,
}, {
Name: "3",
Label: "Pixeldrain e-mail",
DefaultValue: td.User.Email,
Type: FieldTypeDescription,
}, {
Name: "4",
Label: "Patreon username",
DefaultValue: patron.FullName,
Type: FieldTypeDescription,
}, {
Name: "5",
Label: "Patreon e-mail",
DefaultValue: patron.UserEmail,
Type: FieldTypeDescription,
}, {
Name: "6",
Label: "Subscription name",
DefaultValue: patron.Subscription.Name,
Type: FieldTypeDescription,
}, {
Name: "7",
Label: "Monthly contribution",
DefaultValue: fmt.Sprintf("€ %.2f / month", float64(patron.PledgeAmountCents)/100.0),
Type: FieldTypeDescription,
}, {
Name: "8",
Description: "When clicking submit your patreon pledge will be linked " +
"to your pixeldrain account and you will be able to use " +
"pixeldrain's premium features. If you would like to update or " +
"cancel your subscription later on you can do so through " +
"patreon's dashboard",
Type: FieldTypeDescription,
}}
if f.ReadInput(r) {
if err := td.PixelAPI.PatreonLink(r.FormValue("key")); err != nil {
formAPIError(err, &f)
} else {
// Request was a success
f.SubmitSuccess = true
f.SubmitMessages = []template.HTML{template.HTML("Success!")}
}
}
return f
}

View File

@@ -109,7 +109,7 @@ func New(
{GET, "u/:id/preview" /**/, wc.serveFilePreview},
{GET, "l/:id" /* */, wc.serveListViewer},
{GET, "s/:id" /* */, wc.serveSkynetViewer},
{GET, "t" /* */, wc.serveTemplate("paste", false)},
{GET, "t" /* */, wc.serveTemplate("text_editor", false)},
{GET, "donation" /* */, wc.serveMarkdown("donation.md", false)},
{GET, "subscribe" /* */, wc.serveMarkdown("subscribe.md", false)},
{GET, "widgets" /* */, wc.serveTemplate("widgets", false)},
@@ -138,6 +138,9 @@ func New(
{GET, "user/password_reset_confirm" /**/, wc.serveForm(wc.passwordResetConfirmForm, false)},
{PST, "user/password_reset_confirm" /**/, wc.serveForm(wc.passwordResetConfirmForm, false)},
{GET, "patreon_activate" /* */, wc.serveForm(wc.patreonLinkForm, true)},
{PST, "patreon_activate" /* */, wc.serveForm(wc.patreonLinkForm, true)},
// Admin settings
{GET, "admin" /* */, wc.serveTemplate("admin_panel", true)},
{GET, "admin/globals" /**/, wc.serveForm(wc.adminGlobalsForm, true)},