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