diff --git a/res/template/account/patreon_confirm.html b/res/template/account/patreon_confirm.html new file mode 100644 index 0000000..6e00006 --- /dev/null +++ b/res/template/account/patreon_confirm.html @@ -0,0 +1,37 @@ +{{define "patreon_confirm"}} + + + {{template "meta_tags" "E-mail verification"}} + {{template "user_style" .}} + + + {{template "page_top" .}} + +
+
+ {{if eq .Other "success"}} +

Success!

+

+ Your account's e-mail address has been updated. +

+ {{else if eq .Other "not_found"}} +

E-mail change failed

+

+ This e-mail change request does not exist or has expired. + Please try again if you still want to change your e-mail + address. +

+ {{else}} +

Error

+

+ Something went wrong while processing this request. Please + try again later. +

+ {{end}} +
+
+ {{template "page_bottom" .}} + {{template "analytics"}} + + +{{end}} diff --git a/res/template/fragments/form.html b/res/template/fragments/form.html index ef2882c..7c89ce5 100644 --- a/res/template/fragments/form.html +++ b/res/template/fragments/form.html @@ -59,6 +59,8 @@ {{if eq $val $field.DefaultValue}}checked="checked"{{end}}/>
{{ end }} + {{else if eq $field.Type "description"}} +

{{$field.DefaultValue}}

{{end}} {{end}} diff --git a/webcontroller/forms.go b/webcontroller/forms.go index 9448760..dffc0d2 100644 --- a/webcontroller/forms.go +++ b/webcontroller/forms.go @@ -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. diff --git a/webcontroller/user_settings.go b/webcontroller/user_settings.go index 892bf61..ae70bb0 100644 --- a/webcontroller/user_settings.go +++ b/webcontroller/user_settings.go @@ -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: "

Please confirm that the following information is correct:

", + 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 +} diff --git a/webcontroller/web_controller.go b/webcontroller/web_controller.go index a32d297..3e7f4e3 100644 --- a/webcontroller/web_controller.go +++ b/webcontroller/web_controller.go @@ -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)},