From d46997de1404f58166d15e7821ed372168901f33 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Thu, 27 Apr 2023 10:50:28 +0200 Subject: [PATCH] Remove change password button from sidebar if local auth is disabled --- src/controllers/admin_controller.rs | 16 +++++++-------- src/controllers/settings_controller.rs | 24 +++++++++------------- src/controllers/two_factors_controller.rs | 10 ++++----- templates/settings/account_details.html | 12 +++++------ templates/settings/base_settings_page.html | 8 +++++--- 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/controllers/admin_controller.rs b/src/controllers/admin_controller.rs index 3a2ca63..b6c86cf 100644 --- a/src/controllers/admin_controller.rs +++ b/src/controllers/admin_controller.rs @@ -18,29 +18,29 @@ use crate::utils::string_utils::rand_str; #[derive(Template)] #[template(path = "settings/clients_list.html")] -struct ClientsListTemplate { - _p: BaseSettingsPage, +struct ClientsListTemplate<'a> { + _p: BaseSettingsPage<'a>, clients: Vec, } #[derive(Template)] #[template(path = "settings/providers_list.html")] -struct ProvidersListTemplate { - _p: BaseSettingsPage, +struct ProvidersListTemplate<'a> { + _p: BaseSettingsPage<'a>, providers: Vec, } #[derive(Template)] #[template(path = "settings/users_list.html")] -struct UsersListTemplate { - _p: BaseSettingsPage, +struct UsersListTemplate<'a> { + _p: BaseSettingsPage<'a>, users: Vec, } #[derive(Template)] #[template(path = "settings/edit_user.html")] -struct EditUserTemplate { - _p: BaseSettingsPage, +struct EditUserTemplate<'a> { + _p: BaseSettingsPage<'a>, u: User, clients: Vec, providers: Vec, diff --git a/src/controllers/settings_controller.rs b/src/controllers/settings_controller.rs index d772687..db713e2 100644 --- a/src/controllers/settings_controller.rs +++ b/src/controllers/settings_controller.rs @@ -12,31 +12,29 @@ use crate::data::current_user::CurrentUser; use crate::data::remote_ip::RemoteIP; use crate::data::user::User; -pub(crate) struct BaseSettingsPage { +pub(crate) struct BaseSettingsPage<'a> { pub danger_message: Option, pub success_message: Option, pub page_title: &'static str, pub app_name: &'static str, - pub is_admin: bool, - pub user_name: String, + pub user: &'a User, pub version: &'static str, pub ip_location_api: Option<&'static str>, } -impl BaseSettingsPage { +impl<'a> BaseSettingsPage<'a> { pub fn get( page_title: &'static str, - user: &User, + user: &'a User, danger_message: Option, success_message: Option, - ) -> BaseSettingsPage { + ) -> BaseSettingsPage<'a> { Self { danger_message, success_message, page_title, app_name: APP_NAME, - is_admin: user.admin, - user_name: user.username.to_string(), + user, version: env!("CARGO_PKG_VERSION"), ip_location_api: AppConfig::get().ip_location_service.as_deref(), } @@ -45,15 +43,14 @@ impl BaseSettingsPage { #[derive(Template)] #[template(path = "settings/account_details.html")] -struct AccountDetailsPage { - _p: BaseSettingsPage, - u: User, +struct AccountDetailsPage<'a> { + _p: BaseSettingsPage<'a>, } #[derive(Template)] #[template(path = "settings/change_password.html")] -struct ChangePasswordPage { - _p: BaseSettingsPage, +struct ChangePasswordPage<'a> { + _p: BaseSettingsPage<'a>, min_pwd_len: usize, } @@ -63,7 +60,6 @@ pub async fn account_settings_details_route(user: CurrentUser) -> impl Responder HttpResponse::Ok().body( AccountDetailsPage { _p: BaseSettingsPage::get("Account details", &user, None, None), - u: user, } .render() .unwrap(), diff --git a/src/controllers/two_factors_controller.rs b/src/controllers/two_factors_controller.rs index 5ca30d1..9851195 100644 --- a/src/controllers/two_factors_controller.rs +++ b/src/controllers/two_factors_controller.rs @@ -17,14 +17,14 @@ use crate::data::webauthn_manager::WebAuthManagerReq; #[derive(Template)] #[template(path = "settings/two_factors_page.html")] struct TwoFactorsPage<'a> { - _p: BaseSettingsPage, + _p: BaseSettingsPage<'a>, user: &'a User, } #[derive(Template)] #[template(path = "settings/add_2fa_totp_page.html")] -struct AddTotpPage { - _p: BaseSettingsPage, +struct AddTotpPage<'a> { + _p: BaseSettingsPage<'a>, qr_code: String, account_name: String, secret_key: String, @@ -33,8 +33,8 @@ struct AddTotpPage { #[derive(Template)] #[template(path = "settings/add_webauthn_page.html")] -struct AddWebauhtnPage { - _p: BaseSettingsPage, +struct AddWebauhtnPage<'a> { + _p: BaseSettingsPage<'a>, opaque_state: String, challenge_json: String, max_name_len: usize, diff --git a/templates/settings/account_details.html b/templates/settings/account_details.html index f6bb246..ace56be 100644 --- a/templates/settings/account_details.html +++ b/templates/settings/account_details.html @@ -5,27 +5,27 @@ User ID - {{ u.uid.0 }} + {{ _p.user.uid.0 }} First name - {{ u.first_name }} + {{ _p.user.first_name }} Last name - {{ u.last_name }} + {{ _p.user.last_name }} Username - {{ u.username }} + {{ _p.user.username }} Email - {{ u.email }} + {{ _p.user.email }} Account type - {% if u.admin %}Admin{% else %}Regular user{% endif %} + {% if _p.user.admin %}Admin{% else %}Regular user{% endif %} diff --git a/templates/settings/base_settings_page.html b/templates/settings/base_settings_page.html index a99ec21..ff70d72 100644 --- a/templates/settings/base_settings_page.html +++ b/templates/settings/base_settings_page.html @@ -14,7 +14,7 @@ {{ _p.app_name }} - {% if _p.is_admin %} + {% if _p.user.admin %} Version {{ _p.version }} {% endif %}
@@ -24,18 +24,20 @@ Account details + {% if _p.user.allow_local_login %}
  • Change password
  • + {% endif %}
  • Two-factor authentication
  • - {% if _p.is_admin %} + {% if _p.user.admin %}
  • @@ -59,7 +61,7 @@