Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb45803' into 'master'
Handle authentication evaluating state when checking code

See merge request mer-core/nemo-qml-plugin-devicelock!42
  • Loading branch information
rainemak committed May 27, 2019
2 parents bba8611 + d62f20a commit cc0339b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion rpm/nemo-qml-plugin-devicelock.spec
@@ -1,6 +1,6 @@
Name: nemo-qml-plugin-devicelock
Summary: Device lock plugin for Nemo Mobile
Version: 0.2.1
Version: 0.2.21
Release: 1
Group: System/Libraries
License: LGPLv2.1
Expand Down
21 changes: 17 additions & 4 deletions src/nemo-devicelock/host/hostauthenticator.cpp
Expand Up @@ -45,6 +45,7 @@ namespace NemoDeviceLock

static const auto authenticatorInterface = QStringLiteral("org.nemomobile.devicelock.client.Authenticator");
static const auto securityCodeInterface = QStringLiteral("org.nemomobile.devicelock.client.SecurityCodeSettings");
static const auto attemptsRemaining = QStringLiteral("attemptsRemaining");

HostAuthenticatorAdaptor::HostAuthenticatorAdaptor(HostAuthenticator *authenticator)
: QDBusAbstractAdaptor(authenticator)
Expand Down Expand Up @@ -493,13 +494,19 @@ void HostAuthenticator::authorize()

void HostAuthenticator::checkCodeFinished(int result)
{
const FeedbackFunction feebackFunction = (m_state & EvaluatingFlag)
? &HostAuthenticationInput::authenticationResumed
: static_cast<void (HostAuthenticationInput::*)(AuthenticationInput::Feedback, const QVariantMap &, Authenticator::Methods)>(&HostAuthenticationInput::feedback);

m_state = State(m_state & ~EvaluatingFlag);

switch (m_state) {
case Authenticating:
case RequestingPermission:
switch (result) {
case Evaluating:
authenticationEvaluating();
m_state = State(m_state | EvaluatingFlag);
return;
case Success:
case SecurityCodeExpired:
Expand Down Expand Up @@ -528,10 +535,12 @@ void HostAuthenticator::checkCodeFinished(int result)
case AuthenticatingForChange:
switch (result) {
case Evaluating:
authenticationEvaluating();
m_state = State(m_state | EvaluatingFlag);
return;
case Success:
case SecurityCodeExpired:
enterCodeChangeState(&HostAuthenticationInput::feedback, Authenticator::SecurityCode);
enterCodeChangeState(feebackFunction, Authenticator::SecurityCode);
return;
case LockedOut:
lockedOut();
Expand All @@ -544,6 +553,8 @@ void HostAuthenticator::checkCodeFinished(int result)
case AuthenticatingForClear: {
switch (result) {
case Evaluating:
authenticationEvaluating();
m_state = State(m_state | EvaluatingFlag);
return;
case Success:
if (clearCode(m_currentCode)) {
Expand All @@ -563,19 +574,21 @@ void HostAuthenticator::checkCodeFinished(int result)
return;
}


const int attempts = result;
const int maximum = maximumAttempts();

QVariantMap data;
if (maximum > 0 && attempts > 0) {
feedback(AuthenticationInput::IncorrectSecurityCode, qMax(0, maximum - attempts));
data.insert(attemptsRemaining, qMax(0, maximum - attempts));
(this->*feebackFunction)(AuthenticationInput::IncorrectSecurityCode, data, Authenticator::Methods());

if (attempts >= maximum) {
lockedOut();
return;
}
} else {
feedback(AuthenticationInput::IncorrectSecurityCode, -1);
data.insert(attemptsRemaining, -1);
(this->*feebackFunction)(AuthenticationInput::IncorrectSecurityCode, data, Authenticator::Methods());
}
}

Expand Down
1 change: 1 addition & 0 deletions src/nemo-devicelock/lib.pro
Expand Up @@ -61,6 +61,7 @@ target.path = /usr/lib
QMAKE_PKGCONFIG_NAME = nemodevicelock
QMAKE_PKGCONFIG_DESCRIPTION = Library for Nemo device lock.
QMAKE_PKGCONFIG_LIBDIR = $$target.path
QMAKE_PKGCONFIG_VERSION = $$VERSION
QMAKE_PKGCONFIG_INCDIR = /usr/include
QMAKE_PKGCONFIG_DESTDIR = pkgconfig
QMAKE_PKGCONFIG_VERSION = $$VERSION
Expand Down

0 comments on commit cc0339b

Please sign in to comment.