ezidam: header: display name, username, email

This commit is contained in:
Philippe Loctaux 2023-03-19 00:48:41 +01:00
parent c9ef821d2b
commit 9172155893
4 changed files with 16 additions and 17 deletions

View file

@ -81,12 +81,13 @@ async fn avatar(
}
pub mod content {
use jwt::JwtClaims;
use rocket::serde::Serialize;
#[derive(Serialize)]
#[serde(crate = "rocket::serde")]
pub struct Homepage {
pub abc: String,
pub user: JwtClaims,
}
}
@ -97,18 +98,12 @@ async fn redirect_to_setup(_setup: NeedSetup) -> Redirect {
#[get("/", rank = 2)]
async fn homepage(admin: JwtAdmin) -> Page {
println!("{:?}", admin.0);
Page::Homepage(content::Homepage {
abc: "admin".to_string(),
})
Page::Homepage(content::Homepage { user: admin.0 })
}
#[get("/", rank = 3)]
async fn homepage_user(user: JwtUser) -> Page {
println!("{:?}", user.0);
Page::Homepage(content::Homepage {
abc: "user".to_string(),
})
Page::Homepage(content::Homepage { user: user.0 })
}
#[get("/", rank = 4)]

View file

@ -1,9 +1,4 @@
{% extends "shell" %}
{% block content %}
<div>
<div>
homepage goes here {{ abc }}
</div>
</div>
{% endblock content %}

View file

@ -21,10 +21,17 @@
</div>
<div class="nav-item dropdown">
<a href="#" class="nav-link d-flex lh-1 text-reset p-0" data-bs-toggle="dropdown" aria-label="Open user menu">
<span class="avatar avatar-sm" style="background-image: url(/avatar/ycpkJNdAiz947WB?size=250)"></span>
<span class="avatar avatar-sm" style="background-image: url(/avatar/{{ user.sub }}?size=250)"></span>
<div class="d-none d-xl-block ps-2">
<div>Dunn Slane</div>
<div class="mt-1 small text-muted">Research Nurse</div>
{% if user.name %}
<div>{{ user.name }}</div>
{% else %}
<div>{{ user.username }}</div>
{% endif %}
{% if user.email %}
<div class="mt-1 small text-muted">{{ user.email }}</div>
{% endif %}
</div>
</a>
<div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">

View file

@ -17,6 +17,7 @@ pub struct JwtClaims {
// Custom claims
pub username: String,
pub name: Option<String>,
pub email: Option<String>,
pub is_admin: bool,
pub roles: Vec<String>,
@ -37,6 +38,7 @@ impl JwtClaims {
// Custom claims
username: user.username().to_string(),
name: user.name().map(String::from),
email: user.email().map(String::from),
is_admin: user.is_admin(),
roles,