show name of loggedin_user; add logout functionality

This commit is contained in:
philipp 2023-04-03 22:10:12 +02:00
parent 387d93bbaf
commit 303624ab83
3 changed files with 15 additions and 4 deletions

View File

@ -52,6 +52,13 @@ async fn login(
Flash::success(Redirect::to("/"), "Login erfolgreich")
}
pub fn routes() -> Vec<Route> {
routes![index, login]
#[get("/logout")]
async fn logout(cookies: &CookieJar<'_>, _user: User) -> Flash<Redirect> {
cookies.remove_private(Cookie::named("loggedin_user"));
Flash::success(Redirect::to("/auth"), "Logout erfolgreich")
}
pub fn routes() -> Vec<Route> {
routes![index, login, logout]
}

View File

@ -7,8 +7,8 @@ use crate::model::user::User;
mod auth;
#[get("/")]
fn index(_user: User) -> Template {
Template::render("index", context! {})
fn index(user: User) -> Template {
Template::render("index", context! {loggedin_user: user})
}
#[catch(401)] //unauthorized

View File

@ -2,6 +2,10 @@
{% block content %}
{% if loggedin_user %}
Hi {{ loggedin_user.name }}. <a href="/auth/logout">LOGOUT</a>
{% endif %}
{% if flash %}
{% if flash.0 == "success" %}
<div class="row">