implemented otp login
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -1,25 +1,46 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
|
||||
let mail = "";
|
||||
let caption = t('user.send_mail');
|
||||
let error = null;
|
||||
const router = useTinyRouter();
|
||||
|
||||
async function submit(ev){
|
||||
ev.preventDefault();
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/reset_pw`;
|
||||
caption = t('user.data_sent');
|
||||
const resp = await fetch(url,{
|
||||
method : 'POST',
|
||||
body : mail
|
||||
});
|
||||
if (resp.ok) {
|
||||
caption = t('user.data_sent');
|
||||
} else {
|
||||
caption = await resp.text();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function checkToken(){
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const token = urlParams.get('token');
|
||||
console.log({token:token,params:urlParams});
|
||||
if (token) {
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/validate/${token}`;
|
||||
const resp = await fetch(url,{
|
||||
credentials: 'include'
|
||||
});
|
||||
if (resp.ok){
|
||||
router.navigate('/user')
|
||||
} else {
|
||||
error = await resp.text();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMount(checkToken);
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
@@ -44,5 +65,8 @@
|
||||
{t('user.enter_email')}
|
||||
</label>
|
||||
<button type="submit">{caption}</button>
|
||||
{#if error}
|
||||
<div class="error">{error}</div>
|
||||
{/if}
|
||||
</fieldset>
|
||||
</form>
|
||||
Reference in New Issue
Block a user