Skip to content

Commit 9b8f3d6

Browse files
committed
feat: OKO-109 guest account
1 parent 1e9a539 commit 9b8f3d6

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

backend/src/web/app.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ use super::{ImageContainer, MdnsChannelMessage};
5858

5959
// TODO: Maybe use `std::future::pending::<()>();` instead of sleeping forever
6060

61+
// TODO: Change default admin and guest hashes, remember to search and update where they're hardcoded
6162
const SQLITE_URL: &str = "sqlite://data.db";
6263
const VIDEO_PATH: &str = "./videos/";
6364
const DEFAULT_ADMIN_USERNAME: &str = "admin";
6465
const DEFAULT_ADMIN_PASS_HASH: &str = "$argon2id$v=19$m=19456,t=2,p=1$VE0e3g7DalWHgDwou3nuRA$uC6TER156UQpk0lNQ5+jHM0l5poVjPA1he/Tyn9J4Zw";
66+
const DEFAULT_GUEST_USERNAME: &str = "guest";
67+
const DEFAULT_GUEST_PASS_HASH: &str = "$argon2id$v=19$m=19456,t=2,p=1$VE0e3g7DalWHgDwou3nuRA$uC6TER156UQpk0lNQ5+jHM0l5poVjPA1he/Tyn9J4Zw";
6568
const EXPIRED_SESSION_DELETION_INTERVAL: tokio::time::Duration =
6669
tokio::time::Duration::from_secs(60);
6770
const SESSION_DURATION: Duration = Duration::days(1);
@@ -142,6 +145,21 @@ impl App {
142145
admin.create_using_self(&self.db).await?;
143146
}
144147

148+
// ? Maybe make this optional just in case
149+
let guest_exists = User::get_using_username(&self.db, DEFAULT_GUEST_USERNAME)
150+
.await
151+
.is_ok();
152+
if !guest_exists {
153+
let mut guest = User {
154+
user_id: User::DEFAULT.user_id,
155+
username: "guest".to_string(),
156+
password_hash: DEFAULT_GUEST_PASS_HASH.to_owned(),
157+
created_at: User::DEFAULT.created_at(),
158+
};
159+
160+
guest.create_using_self(&self.db).await?;
161+
}
162+
145163
// Session layer.
146164
//
147165
// This uses `tower-sessions` to establish a layer that will provide the session

frontend/src/routes/Login.svelte

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
import { replace } from "svelte-spa-router";
88
import { user } from "../lib/stores/userStore";
99
10-
let username = "admin";
11-
let password = "hunter42";
10+
const DEFAULT_ADMIN_USERNAME = "admin";
11+
const DEFAULT_ADMIN_PASSWORD = "hunter42";
12+
const DEFAULT_GUEST_USERNAME = "guest";
13+
const DEFAULT_GUEST_PASSWORD = "hunter42";
14+
15+
let username = import.meta.env.DEV ? DEFAULT_ADMIN_USERNAME : "";
16+
let password = import.meta.env.DEV ? DEFAULT_ADMIN_PASSWORD : "";
1217
1318
async function handleSubmit() {
1419
const response = await fetch("/api/login", {
@@ -76,8 +81,21 @@
7681
/>
7782
</div>
7883
</Card.Content>
79-
<Card.Footer>
84+
<Card.Footer class="flex-col gap-4">
8085
<Button id="login" class="w-full" type="submit">Sign in</Button>
86+
<Button
87+
id="login-guest"
88+
variant="outline"
89+
class="w-full"
90+
type="button"
91+
on:click={() => {
92+
username = DEFAULT_GUEST_USERNAME;
93+
password = DEFAULT_GUEST_PASSWORD;
94+
handleSubmit();
95+
}}
96+
>
97+
Sign in as Guest
98+
</Button>
8199
</Card.Footer>
82100
</form>
83101
</Card.Root>

0 commit comments

Comments
 (0)