diff --git a/src/main.rs b/src/main.rs index fe270ae..28e98fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,12 @@ use std::fs; #[macro_use] extern crate rocket; -use rocket::{tokio::time::{sleep, Duration}, fs::FileServer}; -use rocket::serde::{Deserialize, json::Json}; +use rocket::serde::{json::Json, Deserialize}; +use rocket::{ + fs::FileServer, + http::CookieJar, + tokio::time::{sleep, Duration}, +}; #[get("/")] fn hello() -> String { @@ -31,11 +35,24 @@ struct LoginInfo { } #[post("/login", data = "")] -async fn login(info: Json) -> &'static str { - if info.username == "sadlynotsappho" && info.password == "thebestpasswordofalltime" { - "logged in!" - } else { - "invalid login info :(" +async fn login(info: Json, cookies: &CookieJar<'_>) -> &'static str { + let token = cookies.get_private("token"); + match token { + Some(t) => { + if t.value_trimmed() == "skyetoken" { + "logged in with token" + } else { + "unknown token" + } + } + None => { + if info.username == "sadlynotsappho" && info.password == "thebestpasswordofalltime" { + cookies.add_private(("token", "skyetoken")); + "logged in!" + } else { + "invalid login info :(" + } + } } } @@ -43,9 +60,8 @@ async fn login(info: Json) -> &'static str { async fn main() { let _rocket = rocket::build() .mount("/", routes![hello, get_book, delay, login]) - .mount("/root", FileServer::from("/home/sadlynotsappho/Projects/Rust/Projects/fossil/web")) + .mount("/root", FileServer::from("./web")) .launch() .await .unwrap(); } - diff --git a/web/css/style.css b/web/css/style.css index e69de29..5a4260f 100644 --- a/web/css/style.css +++ b/web/css/style.css @@ -0,0 +1,2 @@ +:root { +} diff --git a/web/index.html b/web/index.html index 0bfb225..e60333d 100644 --- a/web/index.html +++ b/web/index.html @@ -5,14 +5,12 @@ login test - + - - hiii -
+
@@ -27,12 +25,12 @@