gdm: Move the verificationStatus state machine to ShellUserVerifier

The idea here is that the ShellUserVerifier does all the logic of
identifying the user, and the AuthPrompt is simply the UI on top
of it.

Thus, it makes sense for more of the state machine to be driven by
the ShellUserVerifier.

This will become more apparent in the next commit.
This commit is contained in:
Jasper St. Pierre 2014-03-07 16:14:05 -05:00
parent 6e27ef8ff9
commit 92c283da4d
3 changed files with 23 additions and 30 deletions

View File

@ -24,13 +24,6 @@ const AuthPromptMode = {
UNLOCK_OR_LOG_IN: 1
};
const AuthPromptStatus = {
NOT_VERIFYING: 0,
VERIFYING: 1,
VERIFICATION_FAILED: 2,
VERIFICATION_SUCCEEDED: 3
};
const BeginRequestType = {
PROVIDE_USERNAME: 0,
DONT_PROVIDE_USERNAME: 1
@ -40,8 +33,6 @@ const AuthPrompt = new Lang.Class({
Name: 'AuthPrompt',
_init: function(gdmClient, mode) {
this.verificationStatus = AuthPromptStatus.NOT_VERIFYING;
this._gdmClient = gdmClient;
this._mode = mode;
@ -56,7 +47,6 @@ const AuthPrompt = new Lang.Class({
this._userVerifier.connect('ask-question', Lang.bind(this, this._onAskQuestion));
this._userVerifier.connect('show-message', Lang.bind(this, this._onShowMessage));
this._userVerifier.connect('verification-failed', Lang.bind(this, this._onVerificationFailed));
this._userVerifier.connect('verification-complete', Lang.bind(this, this._onVerificationComplete));
this._userVerifier.connect('reset', Lang.bind(this, this._onReset));
this._userVerifier.connect('smartcard-status-changed', Lang.bind(this, this._onSmartcardStatusChanged));
this._userVerifier.connect('ovirt-user-authenticated', Lang.bind(this, this._onOVirtUserAuthenticated));
@ -133,6 +123,10 @@ const AuthPrompt = new Lang.Class({
this._defaultButtonWell.add_child(this._spinner.actor);
},
get verificationStatus() {
return this._userVerifier.verificationStatus;
},
_onDestroy: function() {
this._userVerifier.clear();
this._userVerifier.disconnectAll();
@ -222,7 +216,7 @@ const AuthPrompt = new Lang.Class({
},
_onOVirtUserAuthenticated: function() {
if (this.verificationStatus != AuthPromptStatus.VERIFICATION_SUCCEEDED)
if (this.verificationStatus != GdmUtil.VerificationStatus.VERIFICATION_SUCCEEDED)
this.reset();
},
@ -237,11 +231,11 @@ const AuthPrompt = new Lang.Class({
// 2) Don't reset if we've already succeeded at verification and
// the user is getting logged in.
if (this._userVerifier.serviceIsDefault(GdmUtil.SMARTCARD_SERVICE_NAME) &&
this.verificationStatus == AuthPromptStatus.VERIFYING &&
this.verificationStatus == GdmUtil.VerificationStatus.VERIFYING &&
this.smartcardDetected)
return;
if (this.verificationStatus != AuthPromptStatus.VERIFICATION_SUCCEEDED)
if (this.verificationStatus != GdmUtil.VerificationStatus.VERIFICATION_SUCCEEDED)
this.reset();
},
@ -256,17 +250,11 @@ const AuthPrompt = new Lang.Class({
this.updateSensitivity(true);
this.setActorInDefaultButtonWell(null);
this.verificationStatus = AuthPromptStatus.VERIFICATION_FAILED;
this.emit('failed');
},
_onVerificationComplete: function() {
this.verificationStatus = AuthPromptStatus.VERIFICATION_SUCCEEDED;
},
_onReset: function() {
this.verificationStatus = AuthPromptStatus.NOT_VERIFYING;
this.reset();
},
@ -430,11 +418,6 @@ const AuthPrompt = new Lang.Class({
},
reset: function() {
if (this.verificationStatus == AuthPromptStatus.VERIFYING)
this._userVerifier.cancel();
this.verificationStatus = AuthPromptStatus.NOT_VERIFYING;
this._queryingService = null;
this.clear();
this._message.opacity = 0;
@ -473,7 +456,6 @@ const AuthPrompt = new Lang.Class({
this.updateSensitivity(false);
this._userVerifier.begin(userName);
this.verificationStatus = AuthPromptStatus.VERIFYING;
},
finish: function(onComplete) {

View File

@ -499,7 +499,7 @@ const LoginDialog = new Lang.Class({
if (disableUserList != this._disableUserList) {
this._disableUserList = disableUserList;
if (this._authPrompt.verificationStatus == AuthPrompt.AuthPromptStatus.NOT_VERIFYING)
if (this._authPrompt.verificationStatus == GdmUtil.VerificationStatus.NOT_VERIFYING)
this._authPrompt.reset();
}
},
@ -509,7 +509,7 @@ const LoginDialog = new Lang.Class({
// Hide the cancel button if the user list is disabled and we're asking for
// a username
if (this._authPrompt.verificationStatus == AuthPrompt.AuthPromptStatus.NOT_VERIFYING && this._disableUserList)
if (this._authPrompt.verificationStatus == GdmUtil.VerificationStatus.NOT_VERIFYING && this._disableUserList)
cancelVisible = false;
else
cancelVisible = true;
@ -574,8 +574,8 @@ const LoginDialog = new Lang.Class({
},
_shouldShowSessionMenuButton: function() {
if (this._authPrompt.verificationStatus != AuthPrompt.AuthPromptStatus.VERIFYING &&
this._authPrompt.verificationStatus != AuthPrompt.AuthPromptStatus.VERIFICATION_FAILED)
if (this._authPrompt.verificationStatus != GdmUtil.VerificationStatus.VERIFYING &&
this._authPrompt.verificationStatus != GdmUtil.VerificationStatus.VERIFICATION_FAILED)
return false;
if (this._user && this._user.is_loaded && this._user.is_logged_in())

View File

@ -119,6 +119,13 @@ function cloneAndFadeOutActor(actor) {
return hold;
}
const VerificationStatus = {
NOT_VERIFYING: 0,
VERIFYING: 1,
VERIFICATION_FAILED: 2,
VERIFICATION_SUCCEEDED: 3
};
const ShellUserVerifier = new Lang.Class({
Name: 'ShellUserVerifier',
@ -161,12 +168,15 @@ const ShellUserVerifier = new Lang.Class({
_reset: function() {
// Clear previous attempts to authenticate
this.verificationStatus = VerificationStatus.NOT_VERIFYING;
this._failCounter = 0;
this._updateDefaultService();
this.emit('reset');
},
begin: function(userName) {
this.verificationStatus = VerificationStatus.VERIFYING;
this._cancellable = new Gio.Cancellable();
this._userName = userName;
this.reauthenticating = false;
@ -479,7 +489,7 @@ const ShellUserVerifier = new Lang.Class({
},
_onVerificationComplete: function() {
this.emit('verification-complete');
this.verificationStatus = VerificationStatus.VERIFICATION_SUCCEEDED;
},
_retry: function() {
@ -496,6 +506,7 @@ const ShellUserVerifier = new Lang.Class({
let canRetry = retry && this._userName &&
this._failCounter < this._settings.get_int(ALLOWED_FAILURES_KEY);
this.verificationStatus = VerificationStatus.VERIFICATION_FAILED;
this.emit('verification-failed');
this._doAfterPendingMessages(Lang.bind(this, function() {