diff --git a/src/components/admin/pages/Perms.svelte b/src/components/admin/pages/Perms.svelte index a5b108f..63afdd4 100644 --- a/src/components/admin/pages/Perms.svelte +++ b/src/components/admin/pages/Perms.svelte @@ -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; + }
@@ -134,6 +155,27 @@ + {#if $me != null && $me.perms.includes("ADMINISTRATION")} + + + + + + + + + + + + + + {/if}
{:catch error}

{error.toString()}

diff --git a/src/components/repo/user.ts b/src/components/repo/user.ts new file mode 100644 index 0000000..9b4e3b4 --- /dev/null +++ b/src/components/repo/user.ts @@ -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 . + */ + +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 { + await fetchWithToken(this.token, `/user/${id}/admin/password`, { + method: "PUT", + body: password, + }); + } +} + +export const userRepo = derived(tokenStore, ($token) => new UserRepo($token)); \ No newline at end of file diff --git a/src/components/stores/me.ts b/src/components/stores/me.ts new file mode 100644 index 0000000..857e495 --- /dev/null +++ b/src/components/stores/me.ts @@ -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 . + */ + +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()); \ No newline at end of file