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")
|
||||
}
|
||||
|
||||
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]
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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">
|
||||
|
Loading…
x
Reference in New Issue
Block a user