Remove unused coupon and knoxfs features

This commit is contained in:
2023-11-15 12:41:27 +01:00
parent 97185fe237
commit fa0029eeb0
3 changed files with 0 additions and 292 deletions

View File

@@ -1,10 +1,5 @@
<script> <script>
import { onMount } from "svelte";
import Euro from "../util/Euro.svelte";
import Form from "../util/Form.svelte"; import Form from "../util/Form.svelte";
import LoadingIndicator from "../util/LoadingIndicator.svelte";
let loading = true
let credit_form = { let credit_form = {
name: "give_credit", name: "give_credit",
@@ -97,90 +92,8 @@ let impersonate_form = {
return {success: true, message: "Success"} return {success: true, message: "Success"}
}, },
} }
let coupon_form = {
name: "make_coupon",
fields: [
{
name: "id",
label: "Code",
type: "text",
default_value: "",
}, {
name: "credit",
label: "Credit",
type: "decimal",
default_value: 0,
}, {
name: "uses",
label: "Uses",
type: "number",
default_value: "",
},
],
submit_label: `<i class="icon">send</i> Create`,
on_submit: async fields => {
const form = new FormData()
form.append("id", fields.id)
form.append("credit", fields.credit*1e6)
form.append("uses", fields.uses)
const resp = await fetch(
window.api_endpoint+"/coupon",
{ method: "POST", body: form }
);
if(resp.status >= 400) {
return {error_json: await resp.json()}
}
get_coupons()
return {success: true, message: "Success: Coupon created"}
},
}
let coupons = []
const get_coupons = async () => {
loading = true;
try {
const resp = await fetch(window.api_endpoint+"/coupon");
if(resp.status >= 400) {
throw new Error(resp.text());
}
coupons = await resp.json()
coupons.sort((a, b) => {
return a.id.localeCompare(b.id)
});
} catch (err) {
alert(err);
} finally {
loading = false;
}
};
const delete_coupon = async (id) => {
if (!confirm("Delete this coupon code?\n\n"+id)) {
return
}
try {
const resp = await fetch(
window.api_endpoint+"/coupon/"+encodeURI(id),
{ method: "DELETE" }
);
if(resp.status >= 400) {
throw new Error(await resp.text());
}
} catch (err) {
alert("Failed to delete ban! "+err)
}
get_coupons();
}
onMount(get_coupons)
</script> </script>
<LoadingIndicator loading={loading}/>
<section> <section>
<h2>Impersonate user</h2> <h2>Impersonate user</h2>
<div class="highlight_shaded"> <div class="highlight_shaded">
@@ -195,33 +108,4 @@ onMount(get_coupons)
<div class="highlight_shaded"> <div class="highlight_shaded">
<Form config={credit_form}></Form> <Form config={credit_form}></Form>
</div> </div>
<h2>Create coupon codes</h2>
<div class="highlight_shaded">
<Form config={coupon_form}></Form>
</div>
<h3>Active coupon codes</h3>
<div class="table_scroll">
<table style="text-align: left;">
<tr>
<td>ID</td>
<td>Uses</td>
<td>Credit</td>
<td></td>
</tr>
{#each coupons as row (row.id)}
<tr>
<td>{row.id}</td>
<td>{row.uses}</td>
<td><Euro amount={row.credit}></Euro></td>
<td>
<button on:click|preventDefault={() => {delete_coupon(row.id)}} class="button button_red round">
<i class="icon">delete</i>
</button>
</td>
</tr>
{/each}
</table>
</div>
</section> </section>

View File

@@ -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(
`<div style="text-align: center;">
<img src="/res/img/knoxfs.png" alt="KnoxFS logo" style="max-width: 14em;" />
</div>`,
)
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: "<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: "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 ` +
`<a href="/user/prepaid/subscriptions" target="_blank">subscription page</a> ` +
`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. ` +
`<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)
} else {
// Request was a success
f.SubmitSuccess = true
f.SubmitMessages = []template.HTML{template.HTML(
`Success! Your account credit has been increased. Visit the ` +
`<a href="/user/prepaid/subscriptions">subscription page</a> to ` +
`activate your subscription`,
)}
}
}
return f
}

View File

@@ -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})}, {GET, "user/password_reset_confirm" /**/, wc.serveForm(wc.passwordResetConfirmForm, handlerOpts{NoEmbed: true})},
{PST, "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 // Admin settings
{GET, "admin" /* */, wc.serveTemplate("admin", handlerOpts{Auth: true})}, {GET, "admin" /* */, wc.serveTemplate("admin", handlerOpts{Auth: true})},
{GET, "admin/status" /* */, wc.serveTemplate("admin", handlerOpts{Auth: true})}, {GET, "admin/status" /* */, wc.serveTemplate("admin", handlerOpts{Auth: true})},