From: Dominik Csapak <d.csapak@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH yew-comp 1/1] login panel: make realm selector optional
Date: Wed, 15 Oct 2025 16:22:59 +0200 [thread overview]
Message-ID: <20251015142310.3633830-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20251015142310.3633830-1-d.csapak@proxmox.com>
in some cases, we don't want to have a realm selector because the user
has to enter e.g. an e-mail address instead (like the PMG mobile
quarantine gui).
Add a property for that that defaults to the current behavior and add a
validator for the username field that checks for an '@' in the middle.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/login_panel.rs | 52 +++++++++++++++++++++++++++++++++++++---------
1 file changed, 42 insertions(+), 10 deletions(-)
diff --git a/src/login_panel.rs b/src/login_panel.rs
index f958871..8e6caa2 100644
--- a/src/login_panel.rs
+++ b/src/login_panel.rs
@@ -1,5 +1,7 @@
use std::rc::Rc;
+use anyhow::bail;
+
use pwt::props::PwtSpace;
use pwt::state::PersistentState;
use pwt::touch::{SnackBar, SnackBarContextExt};
@@ -33,6 +35,11 @@ pub struct LoginPanel {
#[builder]
pub default_realm: AttrValue,
+ /// Determines if the realm box is shown/used
+ #[prop_or(true)]
+ #[builder]
+ pub realm_selectable: bool,
+
/// Mobile Layout
///
/// Use special layout for mobile apps. For example shows error in a [SnackBar]
@@ -176,6 +183,18 @@ impl ProxmoxLoginPanel {
.label_id(username_label_id)
.default(default_username)
.required(true)
+ .validate({
+ let realm_selectable = props.realm_selectable;
+ move |value: &String| {
+ if realm_selectable {
+ return Ok(());
+ } else if let Some((user, realm)) = value.rsplit_once('@') {
+ if !user.is_empty() && !realm.is_empty() {
+ return Ok(());
+ }
+ }
+ bail!("{}", tr!("invalid username"));
+ }})
.autofocus(true),
)
.with_child(
@@ -191,19 +210,19 @@ impl ProxmoxLoginPanel {
.required(true)
.input_type(InputType::Password),
)
- .with_child(
+ .with_optional_child(props.realm_selectable.then_some(
FieldLabel::new(tr!("Realm"))
.id(realm_label_id.clone())
.padding_top(1)
.padding_bottom(PwtSpace::Em(0.25)),
- )
- .with_child(
+ ))
+ .with_optional_child(props.realm_selectable.then_some(
RealmSelector::new()
.name("realm")
.label_id(realm_label_id)
.path(props.domain_path.clone())
- .default(default_realm),
- )
+ .default(default_realm)
+ ))
.with_child(
SubmitButton::new()
.class("pwt-scheme-primary")
@@ -244,7 +263,7 @@ impl ProxmoxLoginPanel {
let (default_username, default_realm) = self.get_defaults(props);
- let input_panel = InputPanel::new()
+ let mut input_panel = InputPanel::new()
.class(pwt::css::Overflow::Auto)
.width("initial") // don't try to minimize size
.padding(4)
@@ -262,14 +281,17 @@ impl ProxmoxLoginPanel {
.name("password")
.required(true)
.input_type(InputType::Password),
- )
- .with_field(
+ );
+
+ if props.realm_selectable {
+ input_panel.add_field(
tr!("Realm"),
RealmSelector::new()
.name("realm")
.path(props.domain_path.clone())
.default(default_realm),
);
+ }
let tfa_dialog = self.challenge.as_ref().map(|challenge| {
TfaDialog::new(challenge.clone())
@@ -450,9 +472,19 @@ impl Component for ProxmoxLoginPanel {
Msg::Submit => {
self.loading = true;
- let username = self.form_ctx.read().get_field_text("username");
let password = self.form_ctx.read().get_field_text("password");
- let realm = self.form_ctx.read().get_field_text("realm");
+ let (username, realm) = if props.realm_selectable {
+ let username = self.form_ctx.read().get_field_text("username");
+ let realm = self.form_ctx.read().get_field_text("realm");
+ (username, realm)
+ } else {
+ self.form_ctx
+ .read()
+ .get_field_text("username")
+ .rsplit_once('@')
+ .map(|(user, realm)| (user.to_string(), realm.to_string()))
+ .unwrap_or_default()
+ };
self.send_login(ctx, username, password, realm);
if let (true, Some(controller)) = (props.mobile, ctx.link().snackbar_controller()) {
--
2.47.3
_______________________________________________
pmg-devel mailing list
pmg-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel
next prev parent reply other threads:[~2025-10-15 14:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 14:22 [pmg-devel] [PATCH pmg-yew-quarantine-gui/proxmox/yew-comp 0/3] fix ldap login for pmg mobile quarantine Dominik Csapak
2025-10-15 14:22 ` [pmg-devel] [PATCH proxmox 1/1] login: fix userid check for '@quarantine' user tickets Dominik Csapak
2025-10-21 18:33 ` [pmg-devel] applied: " Thomas Lamprecht
2025-10-15 14:22 ` Dominik Csapak [this message]
2025-10-22 17:03 ` [pmg-devel] applied: [PATCH yew-comp 1/1] login panel: make realm selector optional Thomas Lamprecht
2025-10-23 6:54 ` Dominik Csapak
2025-10-15 14:23 ` [pmg-devel] [PATCH pmg-yew-quarantine-gui 1/1] login page: disable realm selection Dominik Csapak
2025-10-22 17:35 ` [pmg-devel] applied: " Thomas Lamprecht
2025-10-20 15:03 ` [pmg-devel] [PATCH pmg-yew-quarantine-gui/proxmox/yew-comp 0/3] fix ldap login for pmg mobile quarantine Stoiko Ivanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251015142310.3633830-3-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.