diff --git a/js/ui/components/polkitAgent.js b/js/ui/components/polkitAgent.js index 15307f3cc..20e8b2a50 100644 --- a/js/ui/components/polkitAgent.js +++ b/js/ui/components/polkitAgent.js @@ -31,7 +31,6 @@ const AuthenticationDialog = new Lang.Class({ this.message = message; this.userNames = userNames; this._wasDismissed = false; - this._completed = false; let mainContentBox = new St.BoxLayout({ style_class: 'prompt-dialog-main-layout', vertical: false }); @@ -177,16 +176,16 @@ const AuthenticationDialog = new Lang.Class({ this._identityToAuth = Polkit.UnixUser.new_for_name(userName); this._cookie = cookie; + }, + performAuthentication: function() { + this.destroySession(); this._session = new PolkitAgent.Session({ identity: this._identityToAuth, cookie: this._cookie }); this._session.connect('completed', Lang.bind(this, this._onSessionCompleted)); this._session.connect('request', Lang.bind(this, this._onSessionRequest)); this._session.connect('show-error', Lang.bind(this, this._onSessionShowError)); this._session.connect('show-info', Lang.bind(this, this._onSessionShowInfo)); - }, - - startAuthentication: function() { this._session.initiate(); }, @@ -208,14 +207,14 @@ const AuthenticationDialog = new Lang.Class({ log('polkitAuthenticationAgent: Failed to show modal dialog.' + ' Dismissing authentication request for action-id ' + this.actionId + ' cookie ' + this._cookie); - this._emitDone(false, true); + this._emitDone(true); } }, - _emitDone: function(keepVisible, dismissed) { + _emitDone: function(dismissed) { if (!this._doneEmitted) { this._doneEmitted = true; - this.emit('done', keepVisible, dismissed); + this.emit('done', dismissed); } }, @@ -244,12 +243,16 @@ const AuthenticationDialog = new Lang.Class({ }, _onSessionCompleted: function(session, gainedAuthorization) { - if (this._completed) + if (this._completed || this._doneEmitted) return; this._completed = true; - if (!gainedAuthorization) { + /* Yay, all done */ + if (gainedAuthorization) { + this._emitDone(false); + + } else { /* Unless we are showing an existing error message from the PAM * module (the PAM module could be reporting the authentication * error providing authentication-method specific information), @@ -265,8 +268,10 @@ const AuthenticationDialog = new Lang.Class({ this._infoMessageLabel.hide(); this._nullMessageLabel.hide(); } + + /* Try and authenticate again */ + this.performAuthentication(); } - this._emitDone(!gainedAuthorization, false); }, _onSessionRequest: function(session, request, echo_on) { @@ -310,6 +315,7 @@ const AuthenticationDialog = new Lang.Class({ if (this._session) { if (!this._completed) this._session.cancel(); + this._completed = false; this._session = null; } }, @@ -324,7 +330,7 @@ const AuthenticationDialog = new Lang.Class({ cancel: function() { this._wasDismissed = true; this.close(global.get_current_time()); - this._emitDone(false, true); + this._emitDone(true); }, }); Signals.addSignalMethods(AuthenticationDialog.prototype); @@ -334,7 +340,6 @@ const AuthenticationAgent = new Lang.Class({ _init: function() { this._currentDialog = null; - this._isCompleting = false; this._handle = null; this._native = new Shell.PolkitAuthenticationAgent(); this._native.connect('initiate', Lang.bind(this, this._onInitiate)); @@ -371,45 +376,24 @@ const AuthenticationAgent = new Lang.Class({ // discussion. this._currentDialog.connect('done', Lang.bind(this, this._onDialogDone)); - this._currentDialog.startAuthentication(); + this._currentDialog.performAuthentication(); }, _onCancel: function(nativeAgent) { - this._completeRequest(false, false); + this._completeRequest(false); }, - _onDialogDone: function(dialog, keepVisible, dismissed) { - this._completeRequest(keepVisible, dismissed); + _onDialogDone: function(dialog, dismissed) { + this._completeRequest(dismissed); }, - _reallyCompleteRequest: function(dismissed) { + _completeRequest: function(dismissed) { this._currentDialog.close(); this._currentDialog.destroySession(); this._currentDialog = null; - this._isCompleting = false; - this._native.complete(dismissed) + this._native.complete(dismissed); }, - - _completeRequest: function(keepVisible, wasDismissed) { - if (this._isCompleting) - return; - - this._isCompleting = true; - - if (keepVisible) { - // Give the user 2 seconds to read 'Authentication Failure' before - // dismissing the dialog - Mainloop.timeout_add(2000, - Lang.bind(this, - function() { - this._reallyCompleteRequest(wasDismissed); - return false; - })); - } else { - this._reallyCompleteRequest(wasDismissed); - } - } }); const Component = AuthenticationAgent;