Added logout and manage account links redirecting to the oauth provider
This commit is contained in:
parent
fe04cf539e
commit
90b7136b8f
17
src/main.rs
17
src/main.rs
|
|
@ -30,7 +30,7 @@ use auth::AuthUser;
|
||||||
|
|
||||||
use rocket::fs::{FileServer, relative};
|
use rocket::fs::{FileServer, relative};
|
||||||
use rocket_dyn_templates::{Template, context};
|
use rocket_dyn_templates::{Template, context};
|
||||||
use rocket::response::Redirect;
|
use rocket::response::{Flash, Redirect};
|
||||||
use inventur_db;
|
use inventur_db;
|
||||||
use rocket_sync_db_pools::{database, diesel};
|
use rocket_sync_db_pools::{database, diesel};
|
||||||
use rocket_oauth2::OAuth2;
|
use rocket_oauth2::OAuth2;
|
||||||
|
|
@ -38,6 +38,7 @@ use std::env;
|
||||||
use dotenvy::dotenv;
|
use dotenvy::dotenv;
|
||||||
use rocket::Config;
|
use rocket::Config;
|
||||||
use rocket::figment::providers::Env;
|
use rocket::figment::providers::Env;
|
||||||
|
use rocket::http::CookieJar;
|
||||||
|
|
||||||
/// Database connection using diesel and rocket_sync_db_pools
|
/// Database connection using diesel and rocket_sync_db_pools
|
||||||
#[database("inventur")]
|
#[database("inventur")]
|
||||||
|
|
@ -66,10 +67,20 @@ async fn home(conn: Db, user: AuthUser) -> Template {
|
||||||
tnames: tnames,
|
tnames: tnames,
|
||||||
columns: cols,
|
columns: cols,
|
||||||
rows: rows,
|
rows: rows,
|
||||||
|
username: user.uname,
|
||||||
|
email: user.email,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/logout")]
|
||||||
|
async fn logout(_user: AuthUser, cookies: &CookieJar<'_>) -> Flash<Redirect> {
|
||||||
|
for cookie in cookies.iter() {
|
||||||
|
cookies.remove_private(cookie.clone());
|
||||||
|
}
|
||||||
|
Flash::success(Redirect::to("https://ldap.randerath.eu/realms/master/protocol/openid-connect/logout"), "Goodbye!")
|
||||||
|
}
|
||||||
|
|
||||||
/// If no user is authenticated, redirect the user to authenticate with the oauth identity provider.
|
/// If no user is authenticated, redirect the user to authenticate with the oauth identity provider.
|
||||||
#[get("/", rank=2)]
|
#[get("/", rank=2)]
|
||||||
async fn login_home() -> Redirect {
|
async fn login_home() -> Redirect {
|
||||||
|
|
@ -103,7 +114,7 @@ async fn rocket() -> _ {
|
||||||
.attach(Template::fairing())
|
.attach(Template::fairing())
|
||||||
.attach(Db::fairing())
|
.attach(Db::fairing())
|
||||||
.attach(OAuth2::<auth::RanderathIdentity>::fairing("oauth"))
|
.attach(OAuth2::<auth::RanderathIdentity>::fairing("oauth"))
|
||||||
.mount("/", routes![auth::oauth_login, auth::oauth_callback, home, login_home, favicon])
|
.mount("/", routes![auth::oauth_login, auth::oauth_callback, home, login_home, favicon, logout])
|
||||||
.mount("/table", routes![table::table, table::table_sec, table::edit_tname, table::create_table, table::import_table, table::delete_table])
|
.mount("/table", routes![table::table, table::table_sec, table::edit_tname, table::create_table, table::import_table, table::delete_table])
|
||||||
.mount("/row", routes![table::new_entry, table::edit_entry, table::delete_entry])
|
.mount("/row", routes![table::new_entry, table::edit_entry, table::delete_entry])
|
||||||
.mount("/column", routes![table::delete_column, table::edit_column, table::create_column])
|
.mount("/column", routes![table::delete_column, table::edit_column, table::create_column])
|
||||||
|
|
@ -112,6 +123,4 @@ async fn rocket() -> _ {
|
||||||
.mount("/css", FileServer::from(relative!("static/css")))
|
.mount("/css", FileServer::from(relative!("static/css")))
|
||||||
.mount("/js", FileServer::from(relative!("static/js")))
|
.mount("/js", FileServer::from(relative!("static/js")))
|
||||||
.mount("/txt", FileServer::from(relative!("static/txt")))
|
.mount("/txt", FileServer::from(relative!("static/txt")))
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,15 @@
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<div class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
{{ username }}
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu dropdown-menu-end px-2">
|
||||||
|
<li class="dropdown-option"><a class="nav-link" href="https://ldap.randerath.eu/realms/master/account">Account</a></li>
|
||||||
|
<li class="dropdown-option"><a class="nav-link" href="/logout">Logout</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user