Compare commits
No commits in common. "e86169cac4137e35c2b5f7f149858af14deed576" and "c75978786718bcd8dc8fce711e4b4f84602cb99b" have entirely different histories.
e86169cac4
...
c759787867
|
@ -1,2 +1 @@
|
|||
/target
|
||||
Rocket.toml
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -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]
|
||||
async fn main() {
|
||||
let _rocket = rocket::build()
|
||||
.mount("/", routes![hello, get_book, delay, login, logout])
|
||||
.mount("/login", FileServer::from("./web"))
|
||||
.mount("/", routes![hello, get_book, delay, login])
|
||||
.mount("/root", FileServer::from("./web"))
|
||||
.launch()
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<title>login test</title>
|
||||
<meta charset="UTF-8">
|
||||
<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>
|
||||
|
||||
<body>
|
||||
|
@ -22,8 +22,6 @@
|
|||
<div class="form-test">
|
||||
<input type="submit" value="Log in" />
|
||||
</div>
|
||||
</form>
|
||||
<button id="logout-button">Log Out</button>
|
||||
</body>
|
||||
<script defer>
|
||||
console.log("FUCK YEAH JAVASCRIPT TIME BABYYYYYYY");
|
||||
|
@ -37,15 +35,8 @@
|
|||
header: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({username, password})
|
||||
})
|
||||
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());
|
||||
});
|
||||
console.log(await token.text())
|
||||
})
|
||||
</script>
|
||||
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue