Skip to content

Commit

Permalink
better error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
manglemix committed Feb 5, 2025
1 parent d96a164 commit 42a32f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion usr-backend/src/attendance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async fn add_attendance(
State(state): State<&'static UsrState>,
Form(CheckIn { uid }): Form<CheckIn>,
) -> (StatusCode, &'static str) {
let Some(uid) = uid.strip_prefix('u') else {
let Some(uid) = uid.strip_prefix('u').or_else(|| uid.strip_prefix('U')) else {
return (StatusCode::BAD_REQUEST, "");
};
let Ok(uid) = uid.parse::<u32>() else {
Expand Down
7 changes: 5 additions & 2 deletions usr-web/src/routes/(apps)/attendance/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang=ts>
import { PUBLIC_API_ENDPOINT } from '$env/static/public';
let uid = $state("");
</script>

<!-- This iframe prevents redirection -->
Expand All @@ -9,10 +10,12 @@
<form method="POST" action="{PUBLIC_API_ENDPOINT}/api/attendance/add/attendance" target="dummyframe">
<label>
uID
<input name="uid" placeholder="u1234567" pattern="u[0-9]+" />
<input name="uid" placeholder="u1234567" pattern="^[uU][0-9]+$" bind:value={uid} />
</label>
<button onclick={() => {
alert("Checked In");
if (/^[uU][0-9]+$/.test(uid)) {
alert("Checked In");
}
}}>Check in</button>
</form>

Expand Down

0 comments on commit 42a32f0

Please sign in to comment.