added failure message to login page
This commit is contained in:
parent
d65c3ed447
commit
862d635012
|
|
@ -2,6 +2,8 @@ import type { Actions } from "@sveltejs/kit";
|
||||||
import type { PageServerLoad } from "./$types";
|
import type { PageServerLoad } from "./$types";
|
||||||
import { fail, redirect } from "@sveltejs/kit";
|
import { fail, redirect } from "@sveltejs/kit";
|
||||||
|
|
||||||
|
import Logs from "$lib/server/log"
|
||||||
|
|
||||||
import { authorize_password } from "$lib/server/auth";
|
import { authorize_password } from "$lib/server/auth";
|
||||||
import SessionStore from "$lib/server/session_store";
|
import SessionStore from "$lib/server/session_store";
|
||||||
|
|
||||||
|
|
@ -23,19 +25,20 @@ export const actions = {
|
||||||
redirect(302, redirect_url);
|
redirect(302, redirect_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("logging in");
|
|
||||||
|
|
||||||
const params = await request.formData();
|
const params = await request.formData();
|
||||||
const username = params.get("username") as string | null;
|
const username = params.get("username") as string | null;
|
||||||
const password = params.get("password") as string | null;
|
const password = params.get("password") as string | null;
|
||||||
|
|
||||||
|
Logs.user.info(`Login attempt for user ${username}`)
|
||||||
|
|
||||||
if (username == null || password == null) {
|
if (username == null || password == null) {
|
||||||
return fail(400, { message: "Invalid request" });
|
return fail(400, { message: "Invalid request" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await authorize_password(username, password);
|
const user = await authorize_password(username, password);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return fail(403, { message: "Benutzername oder Passwort falsch.", username: username })
|
return fail(403, { message: "Benutzername oder Passwort ist falsch.", username: username })
|
||||||
}
|
}
|
||||||
|
|
||||||
const expiry_date = new Date(Date.now() + 15*60*1000)
|
const expiry_date = new Date(Date.now() + 15*60*1000)
|
||||||
|
|
@ -58,6 +61,8 @@ export const actions = {
|
||||||
return fail(403, { message: "Not logged in." });
|
return fail(403, { message: "Not logged in." });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logs.user.info(`Logging out user ${locals.user}`)
|
||||||
|
|
||||||
const token = cookies.get("session_id");
|
const token = cookies.get("session_id");
|
||||||
if (!token) {
|
if (!token) {
|
||||||
console.log("how is this user logged in right now?");
|
console.log("how is this user logged in right now?");
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { PageProps } from "./$types";
|
import type { PageProps } from "./$types";
|
||||||
import { enhance } from "$app/forms";
|
import { enhance } from "$app/forms";
|
||||||
|
import { page } from "$app/state";
|
||||||
|
|
||||||
let { form }: PageProps = $props();
|
let { status, form }: PageProps = $props();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -25,6 +26,7 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
|
<p>{form?.message}<br></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue