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 { fail, redirect } from "@sveltejs/kit";
|
||||
|
||||
import Logs from "$lib/server/log"
|
||||
|
||||
import { authorize_password } from "$lib/server/auth";
|
||||
import SessionStore from "$lib/server/session_store";
|
||||
|
||||
|
|
@ -23,19 +25,20 @@ export const actions = {
|
|||
redirect(302, redirect_url);
|
||||
}
|
||||
|
||||
console.log("logging in");
|
||||
|
||||
const params = await request.formData();
|
||||
const username = params.get("username") as string | null;
|
||||
const password = params.get("password") as string | null;
|
||||
|
||||
Logs.user.info(`Login attempt for user ${username}`)
|
||||
|
||||
if (username == null || password == null) {
|
||||
return fail(400, { message: "Invalid request" });
|
||||
}
|
||||
|
||||
const user = await authorize_password(username, password);
|
||||
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)
|
||||
|
|
@ -58,6 +61,8 @@ export const actions = {
|
|||
return fail(403, { message: "Not logged in." });
|
||||
}
|
||||
|
||||
Logs.user.info(`Logging out user ${locals.user}`)
|
||||
|
||||
const token = cookies.get("session_id");
|
||||
if (!token) {
|
||||
console.log("how is this user logged in right now?");
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
<script lang="ts">
|
||||
import type { PageProps } from "./$types";
|
||||
import { enhance } from "$app/forms";
|
||||
import { page } from "$app/state";
|
||||
|
||||
let { form }: PageProps = $props();
|
||||
let { status, form }: PageProps = $props();
|
||||
|
||||
</script>
|
||||
|
||||
|
|
@ -25,6 +26,7 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
<p>{form?.message}<br></p>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
|
|
|||
Loading…
Reference in New Issue