Compare commits

..

No commits in common. "e86169cac4137e35c2b5f7f149858af14deed576" and "c75978786718bcd8dc8fce711e4b4f84602cb99b" have entirely different histories.

3 changed files with 7 additions and 27 deletions

1
.gitignore vendored
View File

@ -1,2 +1 @@
/target /target
Rocket.toml

View File

@ -55,22 +55,12 @@ async fn login(info: Json<LoginInfo>, 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] #[rocket::main]
async fn main() { async fn main() {
let _rocket = rocket::build() let _rocket = rocket::build()
.mount("/", routes![hello, get_book, delay, login, logout]) .mount("/", routes![hello, get_book, delay, login])
.mount("/login", FileServer::from("./web")) .mount("/root", FileServer::from("./web"))
.launch() .launch()
.await .await
.unwrap(); .unwrap();

View File

@ -5,7 +5,7 @@
<title>login test</title> <title>login test</title>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/login/css/style.css" rel="stylesheet"> <link href="/root/css/style.css" rel="stylesheet">
</head> </head>
<body> <body>
@ -22,8 +22,6 @@
<div class="form-test"> <div class="form-test">
<input type="submit" value="Log in" /> <input type="submit" value="Log in" />
</div> </div>
</form>
<button id="logout-button">Log Out</button>
</body> </body>
<script defer> <script defer>
console.log("FUCK YEAH JAVASCRIPT TIME BABYYYYYYY"); console.log("FUCK YEAH JAVASCRIPT TIME BABYYYYYYY");
@ -37,15 +35,8 @@
header: {"Content-Type": "application/json"}, header: {"Content-Type": "application/json"},
body: JSON.stringify({username, password}) body: JSON.stringify({username, password})
}) })
console.log(await token.text()); console.log(await token.text())
}); })
document.getElementById("logout-button").addEventListener("click", async (event) => {
event.preventDefault();
const loggedout = await fetch("/logout", {
method: "POST"
});
console.log(await loggedout.text());
});
</script> </script>
</html> </html>