feat: password reset new password page

This commit is contained in:
Luka Dekanozishvili 2026-02-03 23:26:21 +01:00
parent 7ad2a64f22
commit 45a8f0b689
2 changed files with 68 additions and 1 deletions

View file

@ -1,5 +1,5 @@
<script>
import Phone from '$lib/Phone.svelte';
import Phone from '$lib/Phone.svelte';
export let data;
</script>

View file

@ -0,0 +1,67 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { page } from "$app/state";
import { PUBLIC_BACKEND_API_HOST } from "$env/static/public";
import ErrorPopup from "$lib/ErrorPopup.svelte";
import { auth, initUserAuthStatus } from "$lib/auth.svelte";
import { getSubdomains } from '$lib/domains.svelte';
let password = '';
let errorMessage: string | null = $state(null);
const token = page.params.token;
async function handleSubmit(e: SubmitEvent) {
e.preventDefault();
errorMessage = null;
try {
const res = await fetch(`${PUBLIC_BACKEND_API_HOST}/api/v1/user/reset-password`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ new_password: password, token })
});
let data = await res.json();
if (!res.ok) {
errorMessage = data?.msg || "Something went wrong";
console.log(errorMessage);
return;
}
alert("Password successfully reset")
goto("/login");
} catch (err: any) {
errorMessage = err?.msg || "Network error";
console.log(errorMessage);
}
}
</script>
<svelte:head>
<title>Reset password | HexName - Free, uncomplicated DNS management</title>
<meta property="og:title" content="Reset password | HexName - Free, uncomplicated DNS management">
<meta name="twitter:title" content="Reset password | HexName - Free, uncomplicated DNS management">
<meta name="description" content="Register our premium domains and manage DNS and DynDNS - so you can focus on what truly matters.">
<meta property="og:description" content="Register our premium domains and manage DNS and DynDNS - so you can focus on what truly matters.">
<meta name="twitter:description" content="Register our premium domains and manage DNS and DynDNS - so you can focus on what truly matters.">
<meta name="robots" content="index, nofollow">
</svelte:head>
<div class="flex flex-col items-center justify-center w-full my-40">
<form
class="formset bg-base-200 border-base-300 rounded-box w-xs border p-4 z-1 translate-y-2"
onsubmit={handleSubmit}>
<h1 class="fieldset-legend">Set a new password</h1>
<div class="my-2">
<label class="text-base-content" for="password">Password</label>
<input class="input validator" minlength="12" title="The password must be at least 12 characters long" id="password" name="password" autocomplete="current-password" type="password" bind:value={password} placeholder="****************" required/>
<p class="validator-hint">The password must be at least 12 characters long</p>
</div>
<button class="btn btn-primary w-full" type="submit">Change password</button>
</form>
<div class="mt-3 h-12 flex items-center">
<ErrorPopup {errorMessage} />
</div>
</div>