Use new account update API

This commit is contained in:
2022-11-01 16:56:46 +01:00
parent 666291a1d6
commit cd8bf8afe4
10 changed files with 162 additions and 111 deletions

View File

@@ -1,113 +1,73 @@
<script>
import { onMount } from "svelte";
import FilePicker from "../file_viewer/FilePicker.svelte";
import SuccessMessage from "../util/SuccessMessage.svelte";
import ThemePicker from "../util/ThemePicker.svelte";
import Form from "./../util/Form.svelte";
let password_change = {
name: "password_change",
let account_settings = {
name: "account_settings",
fields: [
{
name: "old_password",
label: "Current password",
type: "current_password",
}, {
name: "new_password",
label: "New password",
type: "new_password",
}, {
name: "new_password2",
label: "New password again",
type: "new_password",
description: "we need you to repeat your password so you " +
"won't be locked out of your account if you make a " +
"typing error"
},
],
submit_label: `<i class="icon">save</i> Save`,
on_submit: async fields => {
if (fields.new_password != fields.new_password2) {
return {success: false, message: "Passwords do not match! Please enter the same password in both fields"}
}
const form = new FormData()
form.append("old_password", fields.old_password)
form.append("new_password", fields.new_password)
const resp = await fetch(
window.api_endpoint+"/user/password",
{ method: "PUT", body: form }
);
if(resp.status >= 400) {
return {error_json: await resp.json()}
}
return {success: true, message: "Success! Your password has been updated"}
},
}
let email_change = {
name: "email_change",
fields: [
{
name: "new_email",
name: "email",
label: "E-mail address",
type: "email",
default_value: window.user.email,
description: `we will send an e-mail to the new address to
verify that it's real. The address will be saved once the
link in the message is clicked. If the e-mail doesn't arrive
right away please check your spam box too. Leave the field
empty to remove your current e-mail address from your
account`,
},
],
submit_label: `<i class="icon">save</i> Save`,
on_submit: async fields => {
const form = new FormData()
form.append("new_email", fields.new_email)
const resp = await fetch(
window.api_endpoint+"/user/email_reset",
{ method: "PUT", body: form }
);
if(resp.status >= 400) {
return {error_json: await resp.json()}
}
return {success: true, message: "Success! E-mail sent. Click the link in the message to verify your new address"}
},
}
let name_change = {
name: "name_change",
fields: [
{
name: "new_username",
description: `We will send an e-mail to the new address to verify
that it's real. The address will be saved once the link in the
message is clicked. If the e-mail doesn't arrive right away
please check your spam box too. Leave the field empty to remove
your current e-mail address from your account`,
separator: true
}, {
name: "password_old",
label: "Current password",
type: "current_password",
discription: `Enter your password here if you would like to change
your password.`
}, {
name: "password_new1",
label: "New password",
type: "new_password",
}, {
name: "password_new2",
label: "New password again",
type: "new_password",
description: `We need you to repeat your password so you won't be
locked out of your account if you make a typing error`,
separator: true,
}, {
name: "username",
label: "Name",
type: "username",
default_value: window.user.username,
description: `changing your username also changes the name used to
description: `Changing your username also changes the name used to
log in. If you forget your username you can still log in using
your e-mail address if you have one configured`,
},
],
submit_label: `<i class="icon">save</i> Save`,
on_submit: async fields => {
if (fields.password_new1 != fields.password_new2) {
return {
success: false,
message: "Passwords do not match! Please enter the same password in both fields"
}
}
const form = new FormData()
form.append("new_username", fields.new_username)
form.append("email", fields.email)
form.append("password_old", fields.password_old)
form.append("password_new", fields.password_new1)
form.append("username", fields.username)
const resp = await fetch(
window.api_endpoint+"/user/username",
window.api_endpoint+"/user",
{ method: "PUT", body: form }
);
if(resp.status >= 400) {
return {error_json: await resp.json()}
}
return {success: true, message: "Success! You are now known as "+fields.new_username}
return {success: true, message: "Success! Your changes have been saved"}
},
}
let delete_account = {
name: "delete_account",
fields: [
@@ -144,23 +104,10 @@ let delete_account = {
<section>
<br/>
<div class="highlight_border">
<h3>Change password</h3>
<Form config={password_change}></Form>
<h3>Account settings</h3>
<Form config={account_settings}></Form>
</div>
<br/>
<div class="highlight_border">
<h3>Change e-mail address</h3>
<Form config={email_change}></Form>
</div>
<br/>
<div class="highlight_border">
<h3>Change name</h3>
<Form config={name_change}></Form>
</div>
<br/>
<div class="highlight_border">
<h3>Delete account</h3>
<Form config={delete_account}></Form>

View File

@@ -7,18 +7,21 @@ import SuccessMessage from "../util/SuccessMessage.svelte";
let loading = false
let success_message
let hotlinking = window.user.hotlinking_enabled
let transfer_cap = window.user.monthly_transfer_cap / 1e9
let skip_viewer = window.user.skip_file_viewer
const update = async () => {
loading = true
const form = new FormData()
form.append("update", "limits")
form.append("hotlinking_enabled", hotlinking)
form.append("transfer_cap", transfer_cap*1e9)
form.append("skip_file_viewer", skip_viewer)
try {
const resp = await fetch(
window.api_endpoint+"/user/subscription",
window.api_endpoint+"/user",
{ method: "PUT", body: form },
)
if(resp.status >= 400) {
@@ -37,13 +40,11 @@ const update = async () => {
}
}
let hotlinking = window.user.hotlinking_enabled
let toggle_hotlinking = () => {
hotlinking = !hotlinking
update()
}
let transfer_cap = window.user.monthly_transfer_cap / 1e9
let transfer_used = 0
let load_transfer_used = () => {
let today = new Date()
@@ -65,6 +66,11 @@ let load_transfer_used = () => {
})
}
let toggle_skip_viewer = () => {
skip_viewer = !skip_viewer
update()
}
onMount(() => {
load_transfer_used()
})
@@ -118,6 +124,26 @@ onMount(() => {
mostly useful for prepaid plans, but it works for patreon plans too.
Set to 0 to disable the limit.
</p>
<h2>Skip download page</h2>
<p>
This setting only applies to your account, others will still see the
download page when visiting your files. When this is enabled you will be
redirected to the file download API when clicking a pixeldrain link.
This means that images, videos and PDF files will be opened directly in
your browser, and other files are immediately downloaded to your device.
This only works for single file links, not albums.
</p>
<p>
You will need a Pro subscription to use this feature.
</p>
<button on:click={toggle_skip_viewer}>
{#if skip_viewer}
<i class="icon green">check</i> ON (click to turn off)
{:else}
<i class="icon red">close</i> OFF (click to turn on)
{/if}
</button>
</section>
<style>

View File

@@ -12,11 +12,11 @@ let embed_domains = ""
const save_embed = async () => {
loading = true
const form = new FormData()
form.append("domains", embed_domains)
form.append("embed_domains", embed_domains)
try {
const resp = await fetch(
window.api_endpoint+"/user/file_embed",
window.api_endpoint+"/user",
{ method: "PUT", body: form }
);
if(resp.status >= 400) {

View File

@@ -11,12 +11,11 @@ const update = async () => {
loading = true
const form = new FormData()
form.append("update", "subscription")
form.append("subscription", subscription)
try {
const resp = await fetch(
window.api_endpoint+"/user/subscription",
window.api_endpoint+"/user",
{ method: "PUT", body: form },
)
if(resp.status >= 400) {