Add Password Reset
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Chaoscaot 2024-03-25 00:39:43 +01:00
Ursprung 899b41d051
Commit 195a66fd60
3 geänderte Dateien mit 102 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -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>

36
src/components/repo/user.ts Normale Datei
Datei anzeigen

@ -0,0 +1,36 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {fetchWithToken, tokenStore} from "@repo/repo.ts";
import {derived} from "svelte/store";
export class UserRepo {
constructor(private token: string) {
}
public async setPassword(id: number, password: string): Promise<void> {
await fetchWithToken(this.token, `/user/${id}/admin/password`, {
method: "PUT",
body: password,
});
}
}
export const userRepo = derived(tokenStore, ($token) => new UserRepo($token));

24
src/components/stores/me.ts Normale Datei
Datei anzeigen

@ -0,0 +1,24 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {cached} from "@stores/cached.ts";
import {get} from "svelte/store";
import {dataRepo} from "@repo/data.ts";
export const me = cached(null, async () => get(dataRepo).getMe());