update user.rs file and integration in main file
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user