Skip to content

Commit a96063a

Browse files
committed
Add third room
1 parent 56d630c commit a96063a

File tree

8 files changed

+298
-250
lines changed

8 files changed

+298
-250
lines changed

app/routes/plinko.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ async def hack_scoreboard(request: Request, token: Optional[str] = Cookie(None))
209209
async def checkin(
210210
request: Request,
211211
token: Optional[str] = Cookie(None),
212-
member_id: Optional[str] = "FAIL",
212+
member_id: Optional[uuid.UUID] = "FAIL",
213213
run: Optional[str] = "FAIL",
214214
session: Session = Depends(get_session),
215215
):
@@ -220,20 +220,19 @@ async def checkin(
220220
if member_id == "FAIL" or run == "FAIL":
221221
return Errors.generate(request, 404, "User Not Found (or run not defined)")
222222

223-
user_data = get_user(session, uuid.UUID(member_id))
223+
user_data = get_user(session, member_id)
224224

225225
if not user_data:
226-
session.query(UserModel).filter(
227-
UserModel.hackucf_id == uuid.UUID(member_id)
228-
).one_or_none()
226+
query = session.query(UserModel).filter(UserModel.hackucf_id == member_id)
227+
user_data = query.first()
229228
if not user_data:
230229
return {
231230
"success": False,
232231
"msg": "Invalid membership ID. Did you show the right QR code?",
233232
"user": {},
234233
}
235234

236-
if user_data.get("assigned_run").lower() != run.lower():
235+
if user_data.assigned_run.lower() != run.lower():
237236
return {
238237
"success": False,
239238
"msg": "You are not competing today.",
@@ -245,8 +244,8 @@ async def checkin(
245244
session.commit()
246245

247246
team_number = -1
248-
if user_data.get("team_number"):
249-
team_number = int(user_data.get("team_number", -1))
247+
if user_data.team_number:
248+
team_number = user_data.team_number
250249

251250
return {"success": True, "msg": "Checked in!", "user": user_data}
252251

app/static/checkin/index.css

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,93 @@
11
* {
2-
margin: 0;
2+
margin: 0;
33
}
44

55
html {
6-
background: #1C1C1C;
7-
color: white;
8-
font-family: "Raleway", "Roboto", sans-serif;
6+
background: #1c1c1c;
7+
color: white;
8+
font-family: "Raleway", "Roboto", sans-serif;
99
}
1010

1111
.card {
12-
max-width: 300px;
13-
width: 100%;
14-
margin: 20vh auto;
15-
padding: 20px;
16-
text-align: center;
12+
max-width: 300px;
13+
width: 100%;
14+
margin: 20vh auto;
15+
padding: 20px;
16+
text-align: center;
1717
}
1818

19-
video, .scan-region-highlight {
20-
object-fit: cover;
21-
width: 300px;
22-
height: 300px;
23-
border-radius: 25px;
19+
video,
20+
.scan-region-highlight {
21+
object-fit: cover;
22+
width: 300px;
23+
height: 300px;
24+
border-radius: 25px;
2425
}
2526

2627
video {
27-
margin: 20px 0;
28+
margin: 20px 0;
2829
}
2930

3031
.ico {
31-
font-size: 200px;
32-
font-weight: bold;
33-
font-family: math, monospace, serif;
32+
font-size: 200px;
33+
font-weight: bold;
34+
font-family: math, monospace, serif;
3435
}
3536

3637
.red {
37-
color: #CC575D;
38+
color: #cc575d;
3839
}
3940

4041
.green {
41-
color: #57CC7F;
42+
color: #57cc7f;
4243
}
4344

4445
.blue {
45-
color: #0B8AD2;
46+
color: #0b8ad2;
4647
}
4748

4849
.gold {
49-
color: #D2990B;
50+
color: #d2990b;
5051
}
5152

5253
.mini_team.green {
53-
color: #009206;
54+
color: #009206;
5455
}
5556

5657
.mini_team.purple {
57-
color: #8e7ac3;
58+
color: #8e7ac3;
5859
}
5960

6061
.team.green {
61-
background: #009206;
62-
color: white;
62+
background: #009206;
63+
color: white;
6364
}
6465

6566
.team.purple {
66-
background: #7D0092;
67-
color: white;
67+
background: #7d0092;
68+
color: white;
69+
}
70+
71+
.team.yellow {
72+
background: #d2990b;
73+
color: white;
6874
}
6975

7076
.team {
71-
border-radius: 5px;
72-
padding: 8px;
77+
border-radius: 5px;
78+
padding: 8px;
7379
}
7480

7581
em {
76-
text-decoration: underline;
82+
text-decoration: underline;
7783
}
7884

79-
#success, #failure, #load {
80-
display: none;
85+
#success,
86+
#failure,
87+
#load {
88+
display: none;
8189
}
8290

8391
h3 {
84-
font-weight: normal;
85-
}
92+
font-weight: normal;
93+
}

app/static/checkin/index.js

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,84 +4,87 @@ const wait = 6;
44
let qrScanner;
55

66
function showPage(id) {
7-
document.getElementById("home").style.display = "none";
8-
document.getElementById("success").style.display = "none";
9-
document.getElementById("failure").style.display = "none";
10-
document.getElementById("load").style.display = "none";
7+
document.getElementById("home").style.display = "none";
8+
document.getElementById("success").style.display = "none";
9+
document.getElementById("failure").style.display = "none";
10+
document.getElementById("load").style.display = "none";
1111

12-
document.getElementById(id).style.display = "block";
12+
document.getElementById(id).style.display = "block";
1313
}
1414

1515
function scannedCode(result) {
16-
// Enter load mode...
17-
qrScanner.stop();
18-
showPage("load");
16+
// Enter load mode...
17+
qrScanner.stop();
18+
showPage("load");
1919

20-
// Send to backend
21-
fetch(`/plinko/checkin?member_id=${result.data}&run=${event.toLowerCase()}`).then(evt => {
22-
// Serialize JSON
23-
return evt.json()
24-
}).then(json => {
25-
if (json.success === false) {
26-
document.getElementById("err_msg").innerText = json.msg;
27-
showPage("failure");
28-
29-
// `wait` second timeout.
30-
setTimeout(() => {
31-
showPage("home");
32-
qrScanner.start();
33-
}, wait * 1000);
34-
} else {
35-
let color = "gold";
36-
let room = "ENG1-186 staff desk"
37-
let team_number = Number(json.user.team_number);
38-
if (team_number >= 1 && team_number <= 8) {
39-
color = "green";
40-
room = "ENG1-187"
41-
} else if (team_number >= 9 && team_number <= 15) {
42-
color = "purple";
43-
room = "ENG1-188";
44-
}
20+
// Send to backend
21+
fetch(`/plinko/checkin?member_id=${result.data}&run=${event.toLowerCase()}`)
22+
.then((evt) => {
23+
// Serialize JSON
24+
return evt.json();
25+
})
26+
.then((json) => {
27+
if (json.success === false) {
28+
document.getElementById("err_msg").innerText = json.msg;
29+
showPage("failure");
4530

31+
// `wait` second timeout.
32+
setTimeout(() => {
33+
showPage("home");
34+
qrScanner.start();
35+
}, wait * 1000);
36+
} else {
37+
let color = "gold";
38+
let room = "ENG1-186 staff desk";
39+
let team_number = Number(json.user.team_number);
40+
if (team_number >= 1 && team_number <= 8) {
41+
color = "green";
42+
room = "ENG1-187";
43+
} else if (team_number >= 9 && team_number <= 15) {
44+
color = "purple";
45+
room = "ENG1-188";
46+
} else if (team_number >= 15 && team_number <= 22) {
47+
color = "yellow";
48+
room = "ENG1-260";
49+
}
4650

47-
// Show result to user.
48-
document.getElementById("name").innerText = `Welcome, ${json.user.first_name}!`;
49-
document.getElementById("flavor").innerHTML = `<h2><span class="team ${color}">You are on Team ${team_number}.</span><h2><br>
51+
// Show result to user.
52+
document.getElementById("name").innerText =
53+
`Welcome, ${json.user.first_name}!`;
54+
document.getElementById("flavor").innerHTML =
55+
`<h2><span class="team ${color}">You are on Team ${team_number}.</span><h2><br>
5056
<h3>Please head to ${room} by following the <em class="mini_team ${color}">${color}</em> signs.</h3>
5157
<h3>Your table will have a <em>Team ${team_number}</em> sign on it.</h3>
5258
`;
53-
showPage("success");
54-
55-
// `wait` second timeout.
56-
setTimeout(() => {
57-
showPage("home");
58-
qrScanner.start();
59-
}, wait * 1000);
60-
}
61-
}).catch(evt => {
62-
document.getElementById("err_msg").innerText = "Invalid QR code.";
63-
showPage("failure");
59+
showPage("success");
6460

61+
// `wait` second timeout.
6562
setTimeout(() => {
66-
showPage("home");
67-
qrScanner.start();
63+
showPage("home");
64+
qrScanner.start();
6865
}, wait * 1000);
66+
}
6967
})
68+
.catch((evt) => {
69+
document.getElementById("err_msg").innerText = "Invalid QR code.";
70+
showPage("failure");
71+
72+
setTimeout(() => {
73+
showPage("home");
74+
qrScanner.start();
75+
}, wait * 1000);
76+
});
7077
}
7178

7279
window.onload = () => {
73-
document.querySelector("b").innerText = event;
80+
document.querySelector("b").innerText = event;
7481

75-
const videoElem = document.querySelector("video");
76-
qrScanner = new QrScanner(
77-
videoElem,
78-
scannedCode,
79-
{
80-
maxScansPerSecond: 10,
81-
highlightScanRegion: true,
82-
returnDetailedScanResult: true
83-
},
84-
);
82+
const videoElem = document.querySelector("video");
83+
qrScanner = new QrScanner(videoElem, scannedCode, {
84+
maxScansPerSecond: 10,
85+
highlightScanRegion: true,
86+
returnDetailedScanResult: true,
87+
});
8588

86-
qrScanner.start();
87-
}
89+
qrScanner.start();
90+
};

0 commit comments

Comments
 (0)