diff --git a/.gitignore b/.gitignore index ea8c4bf..c1cdd55 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +Rocket.toml diff --git a/src/main.rs b/src/main.rs index 28e98fa..e7f0d9f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,12 +55,22 @@ async fn login(info: Json, cookies: &CookieJar<'_>) -> &'static str { } } } +#[post("/logout")] +async fn logout(cookies: &CookieJar<'_>) -> &'static str { + let token = cookies.get_private("token"); + if token.is_some() { + cookies.remove_private("token"); + "logged out" + } else { + "not logged in" + } +} #[rocket::main] async fn main() { let _rocket = rocket::build() - .mount("/", routes![hello, get_book, delay, login]) - .mount("/root", FileServer::from("./web")) + .mount("/", routes![hello, get_book, delay, login, logout]) + .mount("/login", FileServer::from("./web")) .launch() .await .unwrap(); diff --git a/web/css/style.css b/web/css/style.css index 5a4260f..4f22b28 100644 --- a/web/css/style.css +++ b/web/css/style.css @@ -1,2 +1,4 @@ :root { + background-color: red; + color: lime; } diff --git a/web/index.html b/web/index.html index e60333d..7ab177d 100644 --- a/web/index.html +++ b/web/index.html @@ -5,7 +5,7 @@ login test - + @@ -22,6 +22,8 @@
+ +