diff --git a/ui/src/lib/api/user.ts b/ui/src/lib/api/user.ts index a3a29ad..91ca0c4 100644 --- a/ui/src/lib/api/user.ts +++ b/ui/src/lib/api/user.ts @@ -18,3 +18,40 @@ export async function authUser(form: LoginForm): Promise { }); return await handleApiResponse(res); } + +export async function forgotAccountPassword(email: string): any { + const res = await fetch('api/users', { + method: 'PATCH', + headers: {'Accept': 'application/json'}, + body: JSON.stringify({ + email, + kind: 'recovery', + }), + }); + return await handleApiResponse(res); +} + +export async function recoverAccount(userid: string, key: string, password: string): any { + userid = encodeURIComponent(userid); + const res = await fetch(`api/users/${userid}/recovery`, { + method: 'POST', + headers: {'Accept': 'application/json'}, + body: JSON.stringify({ + key, + password, + }), + }); + return await handleApiResponse(res); +} + +export async function validateEmail(userid: string, key: string): any { + userid = encodeURIComponent(userid); + const res = await fetch(`api/users/${userid}/email`, { + method: 'POST', + headers: {'Accept': 'application/json'}, + body: JSON.stringify({ + key, + }), + }); + return await handleApiResponse(res); +} diff --git a/ui/src/lib/components/ForgottenPasswordForm.svelte b/ui/src/lib/components/ForgottenPasswordForm.svelte new file mode 100644 index 0000000..dded1e2 --- /dev/null +++ b/ui/src/lib/components/ForgottenPasswordForm.svelte @@ -0,0 +1,93 @@ + + +
+

+ {$t('email.recover')}. +

+ + + + + + + + + +
diff --git a/ui/src/lib/components/RecoverAccountForm.svelte b/ui/src/lib/components/RecoverAccountForm.svelte new file mode 100644 index 0000000..9354074 --- /dev/null +++ b/ui/src/lib/components/RecoverAccountForm.svelte @@ -0,0 +1,120 @@ + + +
+

+ {$t('password.fill')} +

+ + + + passwordState = checkWeakPassword(value)} + /> + + + + + + passwordConfirmState = checkPasswordConfirmation(value, passwordConfirmation)} + /> + + + + + +
diff --git a/ui/src/lib/locales/en.json b/ui/src/lib/locales/en.json index d88a123..b058a1c 100644 --- a/ui/src/lib/locales/en.json +++ b/ui/src/lib/locales/en.json @@ -123,6 +123,7 @@ "email": { "address": "Email address", "instruction": { + "bad-link": "The link you follow is invalid. Check you copy the entier link and retry.", "check-inbox": "Please check your inbox in order to validate your e-mail address.", "new-confirmation": "If you need a new confirmation e-mail, just enter your address in the form below.", "validate-address": "In order to validate your e-mail address, please check your inbox, and follow the link contained in the message.", diff --git a/ui/src/routes/forgotten-password/+page.svelte b/ui/src/routes/forgotten-password/+page.svelte new file mode 100644 index 0000000..b50bc0a --- /dev/null +++ b/ui/src/routes/forgotten-password/+page.svelte @@ -0,0 +1,24 @@ + + + + {#if error} + + {error} + + {:else if !data.user} + + {:else} + + {/if} + diff --git a/ui/src/routes/forgotten-password/+page.ts b/ui/src/routes/forgotten-password/+page.ts new file mode 100644 index 0000000..b077fb1 --- /dev/null +++ b/ui/src/routes/forgotten-password/+page.ts @@ -0,0 +1,11 @@ +import type { Load } from '@sveltejs/kit'; + +export const load: Load = async({ url }: {url: URL}) => { + const user = url.searchParams.get("u"); + const key = url.searchParams.get("k"); + + return { + user, + key, + }; +}