forked from Ruderverein-Donau-Linz/rowt
show name of loggedin_user; add logout functionality
This commit is contained in:
parent
387d93bbaf
commit
303624ab83
@ -52,6 +52,13 @@ async fn login(
|
|||||||
Flash::success(Redirect::to("/"), "Login erfolgreich")
|
Flash::success(Redirect::to("/"), "Login erfolgreich")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn routes() -> Vec<Route> {
|
#[get("/logout")]
|
||||||
routes![index, login]
|
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]
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ use crate::model::user::User;
|
|||||||
mod auth;
|
mod auth;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index(_user: User) -> Template {
|
fn index(user: User) -> Template {
|
||||||
Template::render("index", context! {})
|
Template::render("index", context! {loggedin_user: user})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[catch(401)] //unauthorized
|
#[catch(401)] //unauthorized
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
{% if loggedin_user %}
|
||||||
|
Hi {{ loggedin_user.name }}. <a href="/auth/logout">LOGOUT</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if flash %}
|
{% if flash %}
|
||||||
{% if flash.0 == "success" %}
|
{% if flash.0 == "success" %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user