2021-11-18 11:12:28 +00:00
|
|
|
<script>
|
|
|
|
import { goto } from '$app/navigation';
|
2022-04-20 19:52:02 +00:00
|
|
|
import { page } from '$app/stores'
|
2021-11-18 11:12:28 +00:00
|
|
|
|
2022-05-15 10:34:19 +00:00
|
|
|
import AuthButton from '../components/AuthButton.svelte';
|
2022-05-15 11:18:43 +00:00
|
|
|
import { user } from '../stores/user';
|
2022-05-15 10:34:19 +00:00
|
|
|
|
2021-11-18 11:12:28 +00:00
|
|
|
let auth = { username: "", password: "" };
|
|
|
|
let pleaseWait = false;
|
|
|
|
|
2022-04-20 19:52:02 +00:00
|
|
|
export let next = $page.url.searchParams.get('next');
|
|
|
|
|
2021-11-18 11:12:28 +00:00
|
|
|
function logmein() {
|
|
|
|
pleaseWait = true;
|
|
|
|
fetch('api/auth', {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify(auth),
|
|
|
|
})
|
|
|
|
.then((response) => {
|
|
|
|
response.json().then((auth) => {
|
|
|
|
pleaseWait = false;
|
2022-04-20 19:52:02 +00:00
|
|
|
if (next && next.indexOf('//') === -1) {
|
|
|
|
goto(next)
|
|
|
|
} else {
|
|
|
|
goto(".");
|
|
|
|
}
|
2021-11-18 11:12:28 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch((response) => {
|
|
|
|
pleaseWait = false;
|
|
|
|
if (response.data)
|
2022-03-02 01:09:53 +00:00
|
|
|
ToastsStore.addToast({
|
|
|
|
color: "danger",
|
2021-11-18 11:12:28 +00:00
|
|
|
title: "Connexion impossible",
|
|
|
|
msg: (response.data ? response.data.errmsg : "Impossible de contacter le serveur"),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-05-15 11:18:43 +00:00
|
|
|
|
|
|
|
$: {
|
|
|
|
if ($user && $user.id) {
|
|
|
|
if (next && next.indexOf('//') === -1) {
|
|
|
|
goto(next)
|
|
|
|
} else {
|
|
|
|
goto(".");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-18 11:12:28 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<form class="col" on:submit|preventDefault={logmein}>
|
|
|
|
<h2>Accès à votre compte</h2>
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="login" class="form-label">CRI login</label>
|
|
|
|
<input class="form-control" id="login" bind:value={auth.username} placeholder="Entrer votre login" autofocus>
|
|
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="password" class="form-label">Mot de passe</label>
|
|
|
|
<input type="password" class="form-control" id="password" bind:value={auth.password} placeholder="Mot de passe">
|
|
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-info">
|
|
|
|
{#if pleaseWait}
|
|
|
|
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
|
|
|
|
{/if}
|
|
|
|
Me connecter
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<div class="col">
|
|
|
|
<h2>OpenId Connect</h2>
|
|
|
|
<div class="text-center">
|
2022-05-15 10:34:19 +00:00
|
|
|
<AuthButton class="btn btn-primary">
|
2021-11-18 11:12:28 +00:00
|
|
|
Me connecter avec mon compte CRI
|
2022-05-15 10:34:19 +00:00
|
|
|
</AuthButton>
|
2021-11-18 11:12:28 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|