Skip to content

Commit

Permalink
Merge pull request #9 from nbitzz/mail-unlink-lol
Browse files Browse the repository at this point in the history
Allow user to detach their email
  • Loading branch information
nbitzz authored Oct 1, 2023
2 parents 7d3b1b5 + 142bee3 commit fb57af0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions assets/icons/change_email.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/disconnect_email.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/server/routes/authRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ authRoutes.get("/confirm_email/:code", requiresAccount, (req,res) => {
}
})

authRoutes.post("/remove_email", requiresAccount, (req,res) => {
let acc = res.locals.acc as Accounts.Account

if (acc.email) {
delete acc.email;
Accounts.save()
res.send("email detached")
}
else ServeError(res, 400, "email not attached")
})

let pwReset = new Map<string, {code: string, expiry: NodeJS.Timeout, requestedAt:number}>()
let prcIdx = new Map<string, string>()

Expand Down
33 changes: 33 additions & 0 deletions src/svelte/elem/prompts/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,39 @@ export function forgotPassword(optPicker) {
})
}

export function emailPotentialRemove(optPicker) {
optPicker.picker("What would you like to do?",[
{
name: "Set a new email",
icon: "/static/assets/icons/change_email.svg",
description: "",
id: "set"
},
{
name: "Disconnect email",
icon: "/static/assets/icons/disconnect_email.svg",
description: "",
id: "disconnect"
}
]).then((exp) => {
if (exp && exp.selected) {
switch (exp.selected) {
case "set":
emailChange(optPicker);
break
case "disconnect":
fetch("/auth/remove_email", {method: "POST"}).then((response) => {
if (response.status != 200) {
optPicker.picker(`${response.status} ${response.headers.get("x-backup-status-message") || response.statusText || ""}`,[])
}

fetchAccountData()
})
}
}
})
}

export function emailChange(optPicker) {
optPicker.picker("Change email",[
{
Expand Down
2 changes: 1 addition & 1 deletion src/svelte/elem/pulldowns/Accounts.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
<p>Change username</p>
</button>

<button on:click={() => accOpts.emailChange(optPicker)}>
<button on:click={() => ($account.email ? accOpts.emailPotentialRemove : accOpts.emailChange)(optPicker)}>
<img src="/static/assets/icons/mail.svg" alt="change email">
<p>Change email{#if $account.email}<span class="monospaceText"><br />{$account.email}</span>{/if}</p>
</button>
Expand Down

0 comments on commit fb57af0

Please sign in to comment.