Compare commits

...

3 Commits

Author SHA1 Message Date
0ed0928a7b proper station code creation; Fixes #3
All checks were successful
CI/CD Pipeline / test (push) Successful in 4m8s
CI/CD Pipeline / deploy (push) Successful in 2m55s
2025-04-14 15:12:15 +02:00
da33c0411d link to /route; Fixes #27 2025-04-14 15:02:45 +02:00
786c122dcd remove js error 2025-04-14 14:59:10 +02:00
6 changed files with 23 additions and 5 deletions

1
Cargo.lock generated
View File

@@ -2233,6 +2233,7 @@ dependencies = [
"futures",
"maud",
"password-auth",
"rand 0.9.0",
"rust-i18n",
"serde",
"sqlx",

View File

@@ -21,6 +21,7 @@ password-auth = "1.0"
tower-sessions-sqlx-store-chrono = { version = "0.14", features = ["sqlite"] }
tracing-subscriber = "0.3"
futures = "0.3"
rand = "0.9"
[dev-dependencies]

View File

@@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS station (
amount_people INTEGER,
last_login DATETIME,
ready BOOLEAN NOT NULL DEFAULT false,
pw TEXT NOT NULL DEFAULT (upper(hex(randomblob(4)))),
pw TEXT NOT NULL,
lat REAL,
lng REAL
);

View File

@@ -6,6 +6,11 @@ use crate::{
};
use axum::Router;
use chrono::{DateTime, Local, NaiveDateTime, Utc};
use rand::{
distr::{Distribution, Uniform},
rng,
};
use serde::{Deserialize, Serialize};
use sqlx::{FromRow, SqlitePool};
@@ -78,8 +83,17 @@ impl Station {
.unwrap();
}
fn generate_random_alphanumeric(length: usize) -> String {
let mut rng = rng();
let chars: Vec<char> = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().collect();
let dist = Uniform::new(0, chars.len()).unwrap();
(0..length).map(|_| chars[dist.sample(&mut rng)]).collect()
}
pub(crate) async fn create(db: &SqlitePool, name: &str) -> Result<(), String> {
sqlx::query!("INSERT INTO station(name) VALUES (?)", name)
let code = Self::generate_random_alphanumeric(8);
sqlx::query!("INSERT INTO station(name, pw) VALUES (?, ?)", name, code)
.execute(db)
.await
.map_err(|e| e.to_string())?;

View File

@@ -517,8 +517,10 @@ async fn index(State(db): State<Arc<SqlitePool>>, session: Session) -> Markup {
}
}
@if station.routes(&db).await.is_empty() {
em data-tooltip=(t!("station_warning_not_assigned_route")) {
"⚠️ "
a href="/admin/route" {
em data-tooltip=(t!("station_warning_not_assigned_route")) {
"⚠️ "
}
}
}
a href=(format!("/admin/station/{}", station.id)){

View File

@@ -82,7 +82,7 @@ async fn view(
iconAnchor: [12, 41]
}});
currentMarker = L.marker([{lat}, {lng}], {{icon: myIcon}}).addTo(map);
map.setView([lat, lng], 14);
map.setView([{lat}, {lng}], 14);
"))
}
div {