[virt-tools-list] [v2: virt-viewer: PATCH 3/3] Prefill the username in the authentication dialog
Fabiano Fidêncio
fidencio at redhat.com
Mon Oct 6 11:58:04 UTC 2014
Lets prefill the username entry using the user name of the
current user.
---
Changes since v1:
- Rebase to apply on changed previous patches
---
src/remote-viewer.c | 3 +++
src/virt-viewer-session-spice.c | 16 ++++++++++------
src/virt-viewer-session-vnc.c | 10 +++++++---
src/virt-viewer.c | 4 ++++
4 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index 49981aa..164067d 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -705,6 +705,9 @@ authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED RestProxyAuth *auth,
"username", &username,
NULL);
+ if (username == NULL || *username == '\0')
+ username = g_strdup(g_get_user_name());
+
window = virt_viewer_app_get_main_window(VIRT_VIEWER_APP(user_data));
success = virt_viewer_auth_collect_credentials(virt_viewer_window_get_window(window),
"oVirt",
diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
index 30d6c36..1d05140 100644
--- a/src/virt-viewer-session-spice.c
+++ b/src/virt-viewer-session-spice.c
@@ -532,13 +532,17 @@ virt_viewer_session_spice_main_channel_event(SpiceChannel *channel G_GNUC_UNUSED
error != NULL ? error->message : _("Invalid password"));
self->priv->pass_try++;
- /* A username is *only* pre-filled in case where some authentication
- * error happened. Unfortunately, we don't have a clear way to
- * differantiate between invalid username and invalid password.
- * So, in both cases the username entry will be pre-filled with the
- * username used in the previous attempt. */
- if (username_required)
+ /* The username is firstly pre-filled with the username of the current
+ * user and in case where some authentication error happened, the
+ * username entry will be prefilled with the last username used.
+ * Unfortunately, we don't have a clear way to differantiate bewteen
+ * invalid username and invalid password. So, in both cases the username
+ * entry will be pre-filled with the username used in the previous attempt. */
+ if (username_required) {
g_object_get(self->priv->session, "username", &user, NULL);
+ if (user == NULL || *user == '\0')
+ user = g_strdup(g_get_user_name());
+ }
ret = virt_viewer_auth_collect_credentials(self->priv->main_window,
"SPICE",
diff --git a/src/virt-viewer-session-vnc.c b/src/virt-viewer-session-vnc.c
index 29bd111..5a2dd86 100644
--- a/src/virt-viewer-session-vnc.c
+++ b/src/virt-viewer-session-vnc.c
@@ -283,9 +283,13 @@ virt_viewer_session_vnc_auth_credential(GtkWidget *src G_GNUC_UNUSED,
VirtViewerFile *file = virt_viewer_session_get_file(VIRT_VIEWER_SESSION(self));
if (file != NULL) {
- if (wantUsername && virt_viewer_file_is_set(file, "username")) {
- username = virt_viewer_file_get_username(file);
- wantUsername = FALSE;
+ if (wantUsername) {
+ if (virt_viewer_file_is_set(file, "username")) {
+ username = virt_viewer_file_get_username(file);
+ wantUsername = FALSE;
+ } else {
+ username = g_strdup(g_get_user_name());
+ }
}
if (wantPassword && virt_viewer_file_is_set(file, "password")) {
password = virt_viewer_file_get_password(file);
diff --git a/src/virt-viewer.c b/src/virt-viewer.c
index 4b90a59..b6c02bf 100644
--- a/src/virt-viewer.c
+++ b/src/virt-viewer.c
@@ -653,6 +653,10 @@ virt_viewer_auth_libvirt_credentials(virConnectCredentialPtr cred,
if (username || password) {
VirtViewerWindow *vwin = virt_viewer_app_get_main_window(VIRT_VIEWER_APP(app));
GtkWindow *win = virt_viewer_window_get_window(vwin);
+
+ if (*username == NULL || **username == '\0')
+ *username = g_strdup(g_get_user_name());
+
priv->auth_cancelled = !virt_viewer_auth_collect_credentials(win,
"libvirt",
app->priv->uri,
--
2.1.0
More information about the virt-tools-list
mailing list