Files
yale-user-access/packages/frontend/app/components/LoginForm.vue
T
LiamPietralla d0425c8cb2 Harden backend auth, validation and error handling
- Rate limit login (5 attempts/min per IP) with a JSON 429 response
- Constant-time password comparison; refuse login if no password is configured
- Explicit SameSite=Strict auth cookie; log failed logins with client IP
- Stop logging door codes (update log lines and the SMS body)
- Replace per-action try/catch -> 400 with a global exception handler (JSON 500)
- Return proper statuses: 404 for missing person, 502 for failed lock writes
- Validate codes as ASCII digits only (int.TryParse accepted +/-/whitespace)
- Validate person name and E.164 phone number; reject sending an unset code
- Rename TwiloOptions -> TwilioOptions and fix message typos
- Expose Program for integration tests
2026-11-16 12:23:31 +11:00

67 lines
1.9 KiB
Vue

<script setup lang='ts'>
import { ref } from 'vue';
import { type ApiResponse } from '~/types/api-response';
const password = ref('');
const passwordError = ref('');
const authenticated = useCookie<boolean>('authenticated');
const runtimeConfig = useRuntimeConfig();
const handleLogin = async (event: Event) => {
// Prevent default form submission
event.preventDefault();
// Reset the error
passwordError.value = '';
// Send a request to the api to login
const response = await fetch(`${runtimeConfig.public.apiBaseUrl}/api/Authentication/login`, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json'
},
body: `"${password.value}"`
});
// Parse the response
const apiResponse = await response.json() as ApiResponse<boolean>;
if (apiResponse.success) {
// If the response was successful, login and redirect to the home page
authenticated.value = true;
navigateTo('/');
} else {
// Otherwise, set the error
passwordError.value = apiResponse.error ?? 'Unknown error';
}
}
</script>
<template>
<div class="bg-zinc-800 text-slate-300 text-center w-full md:w-96 rounded-md">
<h1 class="text-7xl mt-5">Yale</h1>
<div>
<h4 class="hr text-2xl mt-3">User Access</h4>
</div>
<form @submit="handleLogin">
<YaleFormInput type="password" v-model="password" placeholder="Password" class="block mt-10 w-5/6 mx-auto" />
<p class="mt-3 w-5/6 mx-auto text-red-600" v-if="passwordError">{{ passwordError }}</p>
<YaleButton type="submit" class="mb-8 mt-3 w-5/6 mx-auto ">Login</YaleButton>
</form>
</div>
</template>
<style>
.hr {
display: inline-block;
}
.hr::after {
content: '';
display: block;
border-top: 2px solid theme('colors.slate.300');
margin-top: .1rem;
}
</style>