add logout button and functionality
This commit is contained in:
parent
c759787867
commit
57f3fe601d
|
@ -1 +1,2 @@
|
||||||
/target
|
/target
|
||||||
|
Rocket.toml
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -55,12 +55,22 @@ 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])
|
.mount("/", routes![hello, get_book, delay, login, logout])
|
||||||
.mount("/root", FileServer::from("./web"))
|
.mount("/login", FileServer::from("./web"))
|
||||||
.launch()
|
.launch()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
:root {
|
:root {
|
||||||
|
background-color: red;
|
||||||
|
color: lime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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="/root/css/style.css" rel="stylesheet">
|
<link href="/login/css/style.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
@ -22,6 +22,8 @@
|
||||||
<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");
|
||||||
|
@ -35,8 +37,15 @@
|
||||||
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>
|
||||||
|
|
Loading…
Reference in New Issue