Compare commits

..

No commits in common. "f78ccd8d9d45891f2af8550ca096ffaeea78f1da" and "2c3d4f86c871ee585fc796c03dbd51bb135d1668" have entirely different histories.

3 changed files with 13 additions and 37 deletions

View File

@ -2,6 +2,7 @@ package security
import (
"fmt"
"math"
"time"
"code.smartsheep.studio/hydrogen/passport/pkg/database"
@ -35,7 +36,7 @@ func NewChallenge(account models.Account, factors []models.AuthFactor, ip, ua st
}
// Thinking of the requirements factors
requirements := lo.Clamp(risk, 1, len(factors))
requirements := int(math.Max(float64(len(factors)), math.Min(float64(risk), 1)))
challenge = models.AuthChallenge{
IpAddress: ip,

View File

@ -1,36 +1,25 @@
import Navbar from "./shared/Navbar.tsx";
import { readProfiles, useUserinfo } from "../stores/userinfo.tsx";
import { createEffect, createSignal, Show } from "solid-js";
import { readProfiles } from "../stores/userinfo.tsx";
import { createSignal, Show } from "solid-js";
import { readWellKnown } from "../stores/wellKnown.tsx";
import { BeforeLeaveEventArgs, useBeforeLeave, useLocation, useNavigate } from "@solidjs/router";
import { BeforeLeaveEventArgs, useBeforeLeave, useNavigate } from "@solidjs/router";
export default function RootLayout(props: any) {
const [ready, setReady] = createSignal(false);
Promise.all([readWellKnown(), readProfiles()]).then(() => setReady(true));
const navigate = useNavigate();
const userinfo = useUserinfo();
const navigate = useNavigate()
const location = useLocation();
useBeforeLeave((e: BeforeLeaveEventArgs) => {
const whitelist = ["/auth/login", "/auth/register", "/users/me/confirm"]
createEffect(() => {
if (ready()) {
keepGate(location.pathname);
if (!whitelist.includes(e.to.toString()) && !e.defaultPrevented) {
e.preventDefault();
navigate(`/auth/login?redirect_uri=${e.to.toString()}`)
}
});
function keepGate(path: string, e?: BeforeLeaveEventArgs) {
const whitelist = ["/auth/login", "/auth/register", "/users/me/confirm"];
if (!userinfo?.isLoggedIn && !whitelist.includes(path)) {
if (!e?.defaultPrevented) e?.preventDefault();
navigate(`/auth/login?redirect_uri=${path}`);
}
}
useBeforeLeave((e: BeforeLeaveEventArgs) => keepGate(e.to.toString().split("?")[0], e));
return (
<Show when={ready()} fallback={
<div class="h-screen w-screen flex justify-center items-center">

View File

@ -15,7 +15,7 @@ export default function LoginPage() {
const [challenge, setChallenge] = createSignal<any>();
const [stage, setStage] = createSignal("starting");
const [searchParams] = useSearchParams();
const[searchParams] = useSearchParams()
const navigate = useNavigate();
@ -212,22 +212,8 @@ export default function LoginPage() {
</div>
</div>
<Show when={searchParams["redirect_uri"]}>
<div id="redirect-info" class="mt-3">
<div role="alert" class="alert shadow-xl">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
class="stroke-info shrink-0 w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<span>You need to login before access that.</span>
</div>
</div>
</Show>
<div class="text-sm text-center mt-3">
<a target="_blank" href="/auth/register?closable=yes" class="link">Haven't an account? Click here to create
one!</a>
<a target="_blank" href="/auth/register?closable=yes" class="link">Haven't an account? Click here to create one!</a>
</div>
</div>
</div>