Add Password Reset
This commit is contained in:
@@ -23,6 +23,10 @@
|
||||
import {players} from "@stores/stores.ts";
|
||||
import {capitalize} from "../util.ts";
|
||||
import {permsRepo} from "@repo/perms.ts";
|
||||
import {me} from "@stores/me.ts";
|
||||
import SWButton from "@components/styled/SWButton.svelte";
|
||||
import SWModal from "@components/styled/SWModal.svelte";
|
||||
import {userRepo} from "@repo/user.ts";
|
||||
|
||||
let search = "";
|
||||
$: lowerCaseSearch = search.toLowerCase();
|
||||
@@ -36,6 +40,10 @@
|
||||
let prefixEdit = "PREFIX_NONE";
|
||||
let activePerms: string[] = [];
|
||||
|
||||
let resetPasswordModal = false;
|
||||
let resetPassword = "";
|
||||
let resetPasswordRepeat = "";
|
||||
|
||||
function loadPlayer(id: number | null) {
|
||||
if (!id) {
|
||||
return;
|
||||
@@ -80,6 +88,19 @@
|
||||
}
|
||||
|
||||
let permsFuture = $permsRepo.listPerms();
|
||||
|
||||
function resetPW() {
|
||||
if (resetPassword === resetPasswordRepeat) {
|
||||
$userRepo.setPassword(selectedPlayer!, resetPassword);
|
||||
}
|
||||
resetResetPassword();
|
||||
}
|
||||
|
||||
function resetResetPassword() {
|
||||
resetPassword = "";
|
||||
resetPasswordRepeat = "";
|
||||
resetPasswordModal = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col h-screen overflow-hidden">
|
||||
@@ -134,6 +155,27 @@
|
||||
<Button disabled={prefixEdit === (player?.prefix.name ?? "") && activePerms === (player?.perms ?? [])}
|
||||
on:click={save}>Save
|
||||
</Button>
|
||||
{#if $me != null && $me.perms.includes("ADMINISTRATION")}
|
||||
<Button on:click={() => resetPasswordModal = true}>
|
||||
Reset Password
|
||||
</Button>
|
||||
|
||||
<SWModal bind:open={resetPasswordModal} title="Reset Password">
|
||||
<Label for="new_password">New Password</Label>
|
||||
<Input type="password" id="new_password" placeholder="New Password" bind:value={resetPassword}/>
|
||||
<Label for="repeat_password">Repeat Password</Label>
|
||||
<Input type="password" id="repeat_password" placeholder="Repeat Password" bind:value={resetPasswordRepeat}/>
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
<Button class="ml-auto mr-4" on:click={resetResetPassword}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button disabled={resetPassword === "" || resetPassword !== resetPasswordRepeat} on:click={resetPW}>
|
||||
Reset Password
|
||||
</Button>
|
||||
</svelte:fragment>
|
||||
</SWModal>
|
||||
{/if}
|
||||
</div>
|
||||
{:catch error}
|
||||
<p>{error.toString()}</p>
|
||||
|
||||
Reference in New Issue
Block a user