uncomment xyetu
This commit is contained in:
parent
2e598a2190
commit
d0773333ae
@ -26,11 +26,15 @@ export async function checkAuth() {
|
||||
|
||||
export function checkAuthSync() {
|
||||
let result = getAuthInfo();
|
||||
// console.log('+');
|
||||
if (!result) return false;
|
||||
// console.log('-');
|
||||
try {
|
||||
let decoded = jwtDecode(result.a);
|
||||
// console.log('жопа');
|
||||
return !isPast(parseISO(new Date(decoded.exp * 1000).toISOString()));
|
||||
} catch (e) {
|
||||
// console.log('хуй');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<script>
|
||||
|
||||
import { getAuthInfo, saveAuthInfo } from "$lib/auth/Auth";
|
||||
import { AuthStorage } from "$lib/tools/storages/auth-storage";
|
||||
import { redirect } from "$lib/tools/url/URLTools";
|
||||
import { jwtDecode } from "jwt-decode";
|
||||
|
||||
@ -54,7 +55,10 @@
|
||||
<div class="navbar-end">
|
||||
<button on:click={()=>{
|
||||
saveAuthInfo("");
|
||||
redirect("/admin/");
|
||||
AuthStorage.update((s)=>{
|
||||
s.logged = false;
|
||||
});
|
||||
redirect("/admin/login");
|
||||
}} class="btn btn-error btn-outline">Выход</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -5,14 +5,19 @@
|
||||
import Navbar from "../lib/ui-components/navbar.svelte";
|
||||
import { checkAuth, checkAuthSync } from "../lib/auth/Auth";
|
||||
import { redirect } from "$lib/tools/url/URLTools";
|
||||
import { AuthStorage } from "$lib/tools/storages/auth-storage";
|
||||
|
||||
let loggedIn = false;
|
||||
let authCheckInProgress = false;
|
||||
|
||||
|
||||
AuthStorage.subscribe((s)=>{
|
||||
loggedIn = s.logged;
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
|
||||
if (!checkAuthSync() && window.location.pathname !== "/login") {
|
||||
if (!checkAuthSync() && !window.location.pathname.toLocaleLowerCase().includes("/login")) {
|
||||
redirect("/admin/login");
|
||||
}
|
||||
else if (checkAuthSync())
|
||||
|
@ -1,9 +1,8 @@
|
||||
<script>
|
||||
import { redirect } from "$lib/tools/url/URLTools";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
onMount(()=>{
|
||||
document.getElementById("ref")?.click();
|
||||
redirect("/admin/userslist");
|
||||
});
|
||||
</script>
|
||||
|
||||
<a href={"/admin/userslist"} class="hidden" id="ref"></a>
|
@ -2,8 +2,9 @@
|
||||
import { makePost } from "$lib/tools/requests/Requests";
|
||||
import { sayError, sayInfo, sayWarning } from "$lib/tools/toaster/Toaster";
|
||||
import { onMount } from "svelte";
|
||||
import {checkAuth, saveAuthInfo} from "../../lib/auth/Auth";
|
||||
import { checkAuth, saveAuthInfo } from "../../lib/auth/Auth";
|
||||
import { redirect } from "$lib/tools/url/URLTools";
|
||||
import { AuthStorage } from "$lib/tools/storages/auth-storage";
|
||||
|
||||
//6da8a96a-7253-45e2-a3c1-e00d5ecdc65d - valid
|
||||
let tokenValid = true;
|
||||
@ -23,20 +24,20 @@
|
||||
totpValid = true;
|
||||
showLoadingSpinner = true;
|
||||
const result = await makePost("client/login", {
|
||||
"user_token": input_token.value,
|
||||
"totp": input_totp.value
|
||||
user_token: input_token.value,
|
||||
totp: input_totp.value,
|
||||
});
|
||||
if(result.error)
|
||||
{
|
||||
if (result.error) {
|
||||
sayError("Ошибка входа!");
|
||||
tokenValid = false;
|
||||
totpValid = false;
|
||||
showLoadingSpinner = false;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
saveAuthInfo(result.data.token);
|
||||
AuthStorage.update((s) => {
|
||||
s.logged = true;
|
||||
});
|
||||
redirect("/admin/");
|
||||
showLoadingSpinner = false;
|
||||
return;
|
||||
@ -87,15 +88,31 @@
|
||||
on:click={() => {
|
||||
sendLogin();
|
||||
}}
|
||||
class="btn btn-primary text-lg">
|
||||
class="btn btn-primary text-lg"
|
||||
>
|
||||
Войти
|
||||
{#if showLoadingSpinner}
|
||||
<svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-black" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||
<svg
|
||||
class="animate-spin -ml-1 mr-3 h-5 w-5 text-black"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<circle
|
||||
class="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
stroke-width="4"
|
||||
></circle>
|
||||
<path
|
||||
class="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||
></path>
|
||||
</svg>
|
||||
{/if}
|
||||
</button
|
||||
>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user