Skip to content

Commit 42a32f0

Browse files
committed
better error checking
1 parent d96a164 commit 42a32f0

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Diff for: usr-backend/src/attendance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async fn add_attendance(
2222
State(state): State<&'static UsrState>,
2323
Form(CheckIn { uid }): Form<CheckIn>,
2424
) -> (StatusCode, &'static str) {
25-
let Some(uid) = uid.strip_prefix('u') else {
25+
let Some(uid) = uid.strip_prefix('u').or_else(|| uid.strip_prefix('U')) else {
2626
return (StatusCode::BAD_REQUEST, "");
2727
};
2828
let Ok(uid) = uid.parse::<u32>() else {

Diff for: usr-web/src/routes/(apps)/attendance/+page.svelte

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang=ts>
22
import { PUBLIC_API_ENDPOINT } from '$env/static/public';
3+
let uid = $state("");
34
</script>
45

56
<!-- This iframe prevents redirection -->
@@ -9,10 +10,12 @@
910
<form method="POST" action="{PUBLIC_API_ENDPOINT}/api/attendance/add/attendance" target="dummyframe">
1011
<label>
1112
uID
12-
<input name="uid" placeholder="u1234567" pattern="u[0-9]+" />
13+
<input name="uid" placeholder="u1234567" pattern="^[uU][0-9]+$" bind:value={uid} />
1314
</label>
1415
<button onclick={() => {
15-
alert("Checked In");
16+
if (/^[uU][0-9]+$/.test(uid)) {
17+
alert("Checked In");
18+
}
1619
}}>Check in</button>
1720
</form>
1821

0 commit comments

Comments
 (0)