Remove change password button from sidebar if local auth is disabled
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pierre HUBERT 2023-04-27 10:50:28 +02:00
parent 21cc77b9c2
commit d46997de14
5 changed files with 34 additions and 36 deletions

View File

@ -18,29 +18,29 @@ use crate::utils::string_utils::rand_str;
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/clients_list.html")] #[template(path = "settings/clients_list.html")]
struct ClientsListTemplate { struct ClientsListTemplate<'a> {
_p: BaseSettingsPage, _p: BaseSettingsPage<'a>,
clients: Vec<Client>, clients: Vec<Client>,
} }
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/providers_list.html")] #[template(path = "settings/providers_list.html")]
struct ProvidersListTemplate { struct ProvidersListTemplate<'a> {
_p: BaseSettingsPage, _p: BaseSettingsPage<'a>,
providers: Vec<Provider>, providers: Vec<Provider>,
} }
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/users_list.html")] #[template(path = "settings/users_list.html")]
struct UsersListTemplate { struct UsersListTemplate<'a> {
_p: BaseSettingsPage, _p: BaseSettingsPage<'a>,
users: Vec<User>, users: Vec<User>,
} }
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/edit_user.html")] #[template(path = "settings/edit_user.html")]
struct EditUserTemplate { struct EditUserTemplate<'a> {
_p: BaseSettingsPage, _p: BaseSettingsPage<'a>,
u: User, u: User,
clients: Vec<Client>, clients: Vec<Client>,
providers: Vec<Provider>, providers: Vec<Provider>,

View File

@ -12,31 +12,29 @@ use crate::data::current_user::CurrentUser;
use crate::data::remote_ip::RemoteIP; use crate::data::remote_ip::RemoteIP;
use crate::data::user::User; use crate::data::user::User;
pub(crate) struct BaseSettingsPage { pub(crate) struct BaseSettingsPage<'a> {
pub danger_message: Option<String>, pub danger_message: Option<String>,
pub success_message: Option<String>, pub success_message: Option<String>,
pub page_title: &'static str, pub page_title: &'static str,
pub app_name: &'static str, pub app_name: &'static str,
pub is_admin: bool, pub user: &'a User,
pub user_name: String,
pub version: &'static str, pub version: &'static str,
pub ip_location_api: Option<&'static str>, pub ip_location_api: Option<&'static str>,
} }
impl BaseSettingsPage { impl<'a> BaseSettingsPage<'a> {
pub fn get( pub fn get(
page_title: &'static str, page_title: &'static str,
user: &User, user: &'a User,
danger_message: Option<String>, danger_message: Option<String>,
success_message: Option<String>, success_message: Option<String>,
) -> BaseSettingsPage { ) -> BaseSettingsPage<'a> {
Self { Self {
danger_message, danger_message,
success_message, success_message,
page_title, page_title,
app_name: APP_NAME, app_name: APP_NAME,
is_admin: user.admin, user,
user_name: user.username.to_string(),
version: env!("CARGO_PKG_VERSION"), version: env!("CARGO_PKG_VERSION"),
ip_location_api: AppConfig::get().ip_location_service.as_deref(), ip_location_api: AppConfig::get().ip_location_service.as_deref(),
} }
@ -45,15 +43,14 @@ impl BaseSettingsPage {
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/account_details.html")] #[template(path = "settings/account_details.html")]
struct AccountDetailsPage { struct AccountDetailsPage<'a> {
_p: BaseSettingsPage, _p: BaseSettingsPage<'a>,
u: User,
} }
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/change_password.html")] #[template(path = "settings/change_password.html")]
struct ChangePasswordPage { struct ChangePasswordPage<'a> {
_p: BaseSettingsPage, _p: BaseSettingsPage<'a>,
min_pwd_len: usize, min_pwd_len: usize,
} }
@ -63,7 +60,6 @@ pub async fn account_settings_details_route(user: CurrentUser) -> impl Responder
HttpResponse::Ok().body( HttpResponse::Ok().body(
AccountDetailsPage { AccountDetailsPage {
_p: BaseSettingsPage::get("Account details", &user, None, None), _p: BaseSettingsPage::get("Account details", &user, None, None),
u: user,
} }
.render() .render()
.unwrap(), .unwrap(),

View File

@ -17,14 +17,14 @@ use crate::data::webauthn_manager::WebAuthManagerReq;
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/two_factors_page.html")] #[template(path = "settings/two_factors_page.html")]
struct TwoFactorsPage<'a> { struct TwoFactorsPage<'a> {
_p: BaseSettingsPage, _p: BaseSettingsPage<'a>,
user: &'a User, user: &'a User,
} }
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/add_2fa_totp_page.html")] #[template(path = "settings/add_2fa_totp_page.html")]
struct AddTotpPage { struct AddTotpPage<'a> {
_p: BaseSettingsPage, _p: BaseSettingsPage<'a>,
qr_code: String, qr_code: String,
account_name: String, account_name: String,
secret_key: String, secret_key: String,
@ -33,8 +33,8 @@ struct AddTotpPage {
#[derive(Template)] #[derive(Template)]
#[template(path = "settings/add_webauthn_page.html")] #[template(path = "settings/add_webauthn_page.html")]
struct AddWebauhtnPage { struct AddWebauhtnPage<'a> {
_p: BaseSettingsPage, _p: BaseSettingsPage<'a>,
opaque_state: String, opaque_state: String,
challenge_json: String, challenge_json: String,
max_name_len: usize, max_name_len: usize,

View File

@ -5,27 +5,27 @@
<tbody> <tbody>
<tr> <tr>
<th scope="row">User ID</th> <th scope="row">User ID</th>
<td>{{ u.uid.0 }}</td> <td>{{ _p.user.uid.0 }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">First name</th> <th scope="row">First name</th>
<td>{{ u.first_name }}</td> <td>{{ _p.user.first_name }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Last name</th> <th scope="row">Last name</th>
<td>{{ u.last_name }}</td> <td>{{ _p.user.last_name }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Username</th> <th scope="row">Username</th>
<td>{{ u.username }}</td> <td>{{ _p.user.username }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Email</th> <th scope="row">Email</th>
<td>{{ u.email }}</td> <td>{{ _p.user.email }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Account type</th> <th scope="row">Account type</th>
<td>{% if u.admin %}Admin{% else %}Regular user{% endif %}</td> <td>{% if _p.user.admin %}Admin{% else %}Regular user{% endif %}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -14,7 +14,7 @@
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto link-dark text-decoration-none"> <a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto link-dark text-decoration-none">
<span class="fs-4">{{ _p.app_name }}</span> <span class="fs-4">{{ _p.app_name }}</span>
</a> </a>
{% if _p.is_admin %} {% if _p.user.admin %}
<span>Version {{ _p.version }}</span> <span>Version {{ _p.version }}</span>
{% endif %} {% endif %}
<hr> <hr>
@ -24,18 +24,20 @@
Account details Account details
</a> </a>
</li> </li>
{% if _p.user.allow_local_login %}
<li> <li>
<a href="/settings/change_password" class="nav-link link-dark"> <a href="/settings/change_password" class="nav-link link-dark">
Change password Change password
</a> </a>
</li> </li>
{% endif %}
<li> <li>
<a href="/settings/two_factors" class="nav-link link-dark"> <a href="/settings/two_factors" class="nav-link link-dark">
Two-factor authentication Two-factor authentication
</a> </a>
</li> </li>
{% if _p.is_admin %} {% if _p.user.admin %}
<hr/> <hr/>
<li> <li>
<a href="/admin/clients" class="nav-link link-dark"> <a href="/admin/clients" class="nav-link link-dark">
@ -59,7 +61,7 @@
<a href="#" class="d-flex align-items-center link-dark text-decoration-none dropdown-toggle" id="dropdownUser" <a href="#" class="d-flex align-items-center link-dark text-decoration-none dropdown-toggle" id="dropdownUser"
data-bs-toggle="dropdown" aria-expanded="false"> data-bs-toggle="dropdown" aria-expanded="false">
<img src="/assets/img/account.png" alt="" width="32" height="32" class="rounded-circle me-2"> <img src="/assets/img/account.png" alt="" width="32" height="32" class="rounded-circle me-2">
<strong>{{ _p.user_name }}</strong> <strong>{{ _p.user.username }}</strong>
</a> </a>
<ul class="dropdown-menu text-small shadow" aria-labelledby="dropdownUser"> <ul class="dropdown-menu text-small shadow" aria-labelledby="dropdownUser">
<li><a class="dropdown-item" href="/logout">Sign out</a></li> <li><a class="dropdown-item" href="/logout">Sign out</a></li>