From fa0029eeb0cfea7b8e6e1fd773d535a94158b3a3 Mon Sep 17 00:00:00 2001 From: Fornax Date: Wed, 15 Nov 2023 12:41:27 +0100 Subject: [PATCH] Remove unused coupon and knoxfs features --- svelte/src/admin_panel/UserManagement.svelte | 116 ------------- webcontroller/subscription_activate.go | 170 ------------------- webcontroller/web_controller.go | 6 - 3 files changed, 292 deletions(-) delete mode 100644 webcontroller/subscription_activate.go diff --git a/svelte/src/admin_panel/UserManagement.svelte b/svelte/src/admin_panel/UserManagement.svelte index dd567ea..49c926f 100644 --- a/svelte/src/admin_panel/UserManagement.svelte +++ b/svelte/src/admin_panel/UserManagement.svelte @@ -1,10 +1,5 @@ - -

Impersonate user

@@ -195,33 +108,4 @@ onMount(get_coupons)
- -

Create coupon codes

-
-
-
- -

Active coupon codes

-
- - - - - - - - {#each coupons as row (row.id)} - - - - - - - {/each} -
IDUsesCredit
{row.id}{row.uses} - -
-
diff --git a/webcontroller/subscription_activate.go b/webcontroller/subscription_activate.go deleted file mode 100644 index 077b47a..0000000 --- a/webcontroller/subscription_activate.go +++ /dev/null @@ -1,170 +0,0 @@ -package webcontroller - -import ( - "fmt" - "html/template" - "net/http" - "strconv" - "time" -) - -func (wc *WebController) knoxfsLinkForm(td *TemplateData, r *http.Request) (f Form) { - f.Name = "link_subscription" - f.Title = "Activate KnoxFS promo" - f.PreFormHTML = template.HTML( - `
- KnoxFS logo -
`, - ) - f.SubmitLabel = "Confirm" - - if r.FormValue("key") == "" { - f.Submitted = true - f.SubmitMessages = []template.HTML{"Subscription ID not found"} - return f - } - - sub, err := td.PixelAPI.GetSubscriptionID(r.FormValue("key")) - if err != nil && err.Error() == "not_found" { - f.Submitted = true - f.SubmitMessages = []template.HTML{"Subscription 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: "Subscription", - DefaultValue: sub.SubscriptionType.Name, - Type: FieldTypeDescription, - }, { - Name: "5", - Label: "Duration", - DefaultValue: fmt.Sprintf("%d days", sub.DurationDays), - Type: FieldTypeDescription, - }, { - Name: "6", - Label: "End date", - DefaultValue: time.Now().AddDate(0, 0, sub.DurationDays).Format("2006-01-02"), - Type: FieldTypeDescription, - }, { - Name: "7", - Description: "When clicking submit this subscription will be linked " + - "to your pixeldrain account and you will be able to use " + - "pixeldrain's pro features. If you already have a pixeldrain " + - "subscription it will be overwritten", - Type: FieldTypeDescription, - }} - if sub.Used { - f.Submitted = true - f.SubmitRed = true - f.SubmitMessages = []template.HTML{"This subscription is already linked to a pixeldrain account. It can't be linked again"} - return f - } - - if f.ReadInput(r) { - if err := td.PixelAPI.PostSubscriptionLink(r.FormValue("key")); err != nil { - formAPIError(err, &f) - } else { - // Request was a success - f.SubmitSuccess = true - f.SubmitMessages = []template.HTML{template.HTML( - "Success! Your account has been upgraded to the " + sub.SubscriptionType.Name + " plan.", - )} - } - } - return f -} - -func (wc *WebController) couponForm(td *TemplateData, r *http.Request) (f Form) { - f.Name = "redeem_coupon" - f.Title = "Redeem coupon code" - f.SubmitLabel = "Redeem" - - if r.FormValue("code") == "" { - f.Submitted = true - f.SubmitMessages = []template.HTML{"Coupon code not found"} - return f - } - - coupon, err := td.PixelAPI.GetCouponID(r.FormValue("code")) - if err != nil && err.Error() == "not_found" { - f.Submitted = true - f.SubmitMessages = []template.HTML{"Coupon code not found"} - return f - } else if err != nil { - f.Submitted = true - formAPIError(err, &f) - return f - } - - f.Fields = []Field{{ - Name: "1", - Label: "", - DefaultValue: "", - Description: `When redeeming this coupon code the value will be ` + - `added to your pixeldrain account. Go to the ` + - `subscription page ` + - `afterwards to activate your subscription.`, - Type: FieldTypeDescription, - }, { - Name: "2", - Label: "Coupon value:", - DefaultValue: fmt.Sprintf("€ %.2f", float64(coupon.Credit)/1e6), - Type: FieldTypeDescription, - }, { - Name: "2", - Label: "Coupon uses left:", - DefaultValue: strconv.Itoa(coupon.Uses), - Type: FieldTypeDescription, - }} - - if coupon.Uses < 1 { - f.Submitted = true - f.SubmitMessages = []template.HTML{"Coupon has been used up"} - 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. ` + - `Click here to log in`, - } - return f - } - - if f.ReadInput(r) { - if err := td.PixelAPI.PostCouponRedeem(r.FormValue("code")); err != nil { - formAPIError(err, &f) - } else { - // Request was a success - f.SubmitSuccess = true - f.SubmitMessages = []template.HTML{template.HTML( - `Success! Your account credit has been increased. Visit the ` + - `subscription page to ` + - `activate your subscription`, - )} - } - } - return f -} diff --git a/webcontroller/web_controller.go b/webcontroller/web_controller.go index 80807e5..bb91a2c 100644 --- a/webcontroller/web_controller.go +++ b/webcontroller/web_controller.go @@ -182,12 +182,6 @@ func New(r *httprouter.Router, prefix string, conf Config) (wc *WebController) { {GET, "user/password_reset_confirm" /**/, wc.serveForm(wc.passwordResetConfirmForm, handlerOpts{NoEmbed: true})}, {PST, "user/password_reset_confirm" /**/, wc.serveForm(wc.passwordResetConfirmForm, handlerOpts{NoEmbed: true})}, - {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{})}, - {PST, "coupon_redeem", wc.serveForm(wc.couponForm, handlerOpts{})}, - // Admin settings {GET, "admin" /* */, wc.serveTemplate("admin", handlerOpts{Auth: true})}, {GET, "admin/status" /* */, wc.serveTemplate("admin", handlerOpts{Auth: true})},