Add logout button

This commit is contained in:
jude 2023-06-20 08:50:12 +01:00
parent a66db37b33
commit 9d8622f418
5 changed files with 38 additions and 13 deletions

24
Cargo.lock generated
View File

@ -161,6 +161,12 @@ version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]]
name = "base64"
version = "0.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d"
[[package]] [[package]]
name = "base64ct" name = "base64ct"
version = "1.5.3" version = "1.5.3"
@ -346,7 +352,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "344adc371239ef32293cb1c4fe519592fcf21206c79c02854320afcdf3ab4917" checksum = "344adc371239ef32293cb1c4fe519592fcf21206c79c02854320afcdf3ab4917"
dependencies = [ dependencies = [
"aes-gcm", "aes-gcm",
"base64", "base64 0.13.1",
"hkdf", "hkdf",
"percent-encoding", "percent-encoding",
"rand 0.8.5", "rand 0.8.5",
@ -1655,7 +1661,7 @@ version = "4.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eeaf26a72311c087f8c5ba617c96fac67a5c04f430e716ac8d8ab2de62e23368" checksum = "eeaf26a72311c087f8c5ba617c96fac67a5c04f430e716ac8d8ab2de62e23368"
dependencies = [ dependencies = [
"base64", "base64 0.13.1",
"chrono", "chrono",
"getrandom 0.2.8", "getrandom 0.2.8",
"http", "http",
@ -2189,9 +2195,9 @@ checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
[[package]] [[package]]
name = "reminder-rs" name = "reminder-rs"
version = "1.6.13" version = "1.6.14"
dependencies = [ dependencies = [
"base64", "base64 0.21.2",
"chrono", "chrono",
"chrono-tz 0.8.1", "chrono-tz 0.8.1",
"dotenv", "dotenv",
@ -2219,7 +2225,7 @@ dependencies = [
name = "reminder_web" name = "reminder_web"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"base64", "base64 0.13.1",
"chrono", "chrono",
"chrono-tz 0.5.3", "chrono-tz 0.5.3",
"csv", "csv",
@ -2250,7 +2256,7 @@ version = "0.11.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c" checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c"
dependencies = [ dependencies = [
"base64", "base64 0.13.1",
"bytes", "bytes",
"encoding_rs", "encoding_rs",
"futures-core", "futures-core",
@ -2471,7 +2477,7 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55"
dependencies = [ dependencies = [
"base64", "base64 0.13.1",
] ]
[[package]] [[package]]
@ -2637,7 +2643,7 @@ checksum = "82fd5e7b5858ad96e99d440138f34f5b98e1b959ebcd3a1036203b30e78eb788"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"async-tungstenite", "async-tungstenite",
"base64", "base64 0.13.1",
"bitflags", "bitflags",
"bytes", "bytes",
"cfg-if", "cfg-if",
@ -3224,7 +3230,7 @@ version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0" checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0"
dependencies = [ dependencies = [
"base64", "base64 0.13.1",
"byteorder", "byteorder",
"bytes", "bytes",
"http", "http",

View File

@ -26,7 +26,7 @@ rmp-serde = "1.1"
rand = "0.8" rand = "0.8"
levenshtein = "1.0" levenshtein = "1.0"
sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono", "migrate"]} sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono", "migrate"]}
base64 = "0.13" base64 = "0.21.0"
[dependencies.postman] [dependencies.postman]
path = "postman" path = "postman"

View File

@ -134,7 +134,14 @@ pub async fn initialize(
routes::help_iemanager, routes::help_iemanager,
], ],
) )
.mount("/login", routes![routes::login::discord_login, routes::login::discord_callback]) .mount(
"/login",
routes![
routes::login::discord_login,
routes::login::discord_logout,
routes::login::discord_callback
],
)
.mount( .mount(
"/dashboard", "/dashboard",
routes![ routes![

View File

@ -11,7 +11,7 @@ use rocket::{
}; };
use serenity::model::user::User; use serenity::model::user::User;
use crate::consts::DISCORD_API; use crate::{consts::DISCORD_API, routes};
#[get("/discord")] #[get("/discord")]
pub async fn discord_login( pub async fn discord_login(
@ -52,6 +52,15 @@ pub async fn discord_login(
Redirect::to(auth_url.to_string()) Redirect::to(auth_url.to_string())
} }
#[get("/discord/logout")]
pub async fn discord_logout(cookies: &CookieJar<'_>) -> Redirect {
cookies.remove_private(Cookie::named("username"));
cookies.remove_private(Cookie::named("userid"));
cookies.remove_private(Cookie::named("access_token"));
Redirect::to(uri!(routes::index))
}
#[get("/discord/authorized?<code>&<state>")] #[get("/discord/authorized?<code>&<state>")]
pub async fn discord_callback( pub async fn discord_callback(
code: &str, code: &str,

View File

@ -250,7 +250,7 @@
</ul> </ul>
<div class="aside-footer"> <div class="aside-footer">
<p class="menu-label"> <p class="menu-label">
Settings Options
</p> </p>
<ul class="menu-list"> <ul class="menu-list">
<li> <li>
@ -262,6 +262,9 @@
<a class="show-modal" data-modal="chooseTimezoneModal"> <a class="show-modal" data-modal="chooseTimezoneModal">
<span class="icon"><i class="fas fa-map-marked"></i></span> Timezone <span class="icon"><i class="fas fa-map-marked"></i></span> Timezone
</a> </a>
<a href="/login/discord/logout">
<span class="icon"><i class="fas fa-sign-out"></i></span> Log out
</a>
</li> </li>
</ul> </ul>
</div> </div>