update user.rs file and integration in main file

This commit is contained in:
2026-03-31 16:21:46 +02:00
parent 3a6bd21b59
commit 6a5774667e
5 changed files with 79 additions and 10 deletions

View File

@@ -4,9 +4,12 @@ use std::path::Path;
use tokio::fs::File;
use tokio::io::{self, AsyncReadExt};
use tower_http::services::ServeDir;
mod user;
#[tokio::main]
async fn main() {
let db = user::DataBase::open(String::from("user"));
db.create_table("users", "name TEXT, level TEXT, password TEXT");
let app = Router::new()
.route("/", get(handler))
.route("/game", get(game))
@@ -34,6 +37,20 @@ async fn game() -> Html<String> {
Html(html_content)
}
async fn register() -> Html<String> {
let html_content = read_html_from_file("../web/templates/view/register.html")
.await
.unwrap_or_else(|_| "<h1>Error loading HTML file</h1>".to_string());
Html(html_content)
}
async fn login() -> Html<String> {
let html_content = read_html_from_file("../web/templates/view/login.html")
.await
.unwrap_or_else(|_| "<h1>Error loading HTML file</h1>".to_string());
Html(html_content)
}
async fn read_html_from_file<P: AsRef<Path>>(path: P) -> io::Result<String> {
let mut file = File::open(path).await?;
let mut contents = String::new();