Skip to content

Commit

Permalink
Get the number of failed attempts from the plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
adenexter committed Sep 20, 2016
1 parent 92f1607 commit 7ce5ba8
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 52 deletions.
9 changes: 4 additions & 5 deletions rpm/nemo-qml-plugin-devicelock.spec
Expand Up @@ -12,9 +12,8 @@ BuildRequires: pkgconfig(Qt5Network)
BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(keepalive)
BuildRequires: pkgconfig(mce)
BuildRequires: pkgconfig(mlite5)
BuildRequires: pkgconfig(libsystemd-daemon)
Obsoletes: nemo-qml-plugin-devicelock-default
Obsoletes: nemo-qml-plugin-devicelock-default < 0.2.0
Requires: nemo-devicelock-daemon

%description
Expand All @@ -23,7 +22,7 @@ Requires: nemo-devicelock-daemon
%package -n nemo-devicelock-daemon-cli
Summary: The default command line lock code device lock daemon for Nemo Mobile
Group: System/GUI/Other
Requires: %{name} = %{version}
Requires: %{name} = %{version}-%{release}
Provides: nemo-devicelock-daemon

%description -n nemo-devicelock-daemon-cli
Expand All @@ -32,15 +31,15 @@ Provides: nemo-devicelock-daemon
%package devel
Summary: Development libraries for device lock
Group: Development/Libraries
Requires: %{name} = %{version}
Requires: %{name} = %{version}-%{release}

%description devel
%{summary}.

%package host-devel
Summary: Development libraries for device lock daemons
Group: Development/Libraries
Requires: %{name}-devel = %{version}
Requires: %{name}-devel = %{version}-%{release}

%description host-devel
%{summary}.
Expand Down
3 changes: 1 addition & 2 deletions src/daemon/daemon.pro
Expand Up @@ -11,8 +11,7 @@ CONFIG += \
PKGCONFIG += \
dbus-1 \
keepalive \
libsystemd-daemon \
mlite5
libsystemd-daemon

INCLUDEPATH += \
$$PWD/../ \
Expand Down
8 changes: 6 additions & 2 deletions src/nemo-devicelock/authenticator.cpp
Expand Up @@ -139,10 +139,14 @@ void Authenticator::authenticate(const QVariant &challengeCode, Methods methods)
}
});

response->onError([this]() {
response->onError([this](const QDBusError &dbusError) {
m_authenticating = false;

emit error(SoftwareError);
if (dbusError.name() == QStringLiteral("org.nemomobile.devicelock.Authenticator.LockedOut")) {
emit error(LockedOut);
} else {
emit error(SoftwareError);
}
emit authenticatingChanged();
});

Expand Down
2 changes: 1 addition & 1 deletion src/nemo-devicelock/devicereset.cpp
Expand Up @@ -68,7 +68,7 @@ void DeviceReset::clearDevice(const QVariant &authenticationToken, ResetMode mod
response->onFinished([this]() {
emit clearingDevice();
});
response->onError([this]() {
response->onError([this](const QDBusError &) {
emit clearDeviceError();
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/nemo-devicelock/encryptionsettings.cpp
Expand Up @@ -75,7 +75,7 @@ void EncryptionSettings::encryptHome(const QVariant &authenticationToken)
response->onFinished([this]() {
emit encryptingHome();
});
response->onError([this]() {
response->onError([this](const QDBusError &) {
emit encryptHomeError();
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/nemo-devicelock/fingerprintsettings.cpp
Expand Up @@ -278,7 +278,7 @@ void FingerprintSettings::acquireFinger(const QVariant &authenticationToken)
emit samplesRemainingChanged();
});

response->onError([this]() {
response->onError([this](const QDBusError &) {
m_isAcquiring = false;

emit acquisitionError(CannotContinue);
Expand Down
37 changes: 16 additions & 21 deletions src/nemo-devicelock/host/cli/cliauthenticator.cpp
Expand Up @@ -45,7 +45,6 @@ namespace NemoDeviceLock
CliAuthenticator::CliAuthenticator(QObject *parent)
: HostAuthenticator(parent)
, m_watcher(LockCodeWatcher::instance())
, m_attemptCount(QStringLiteral("/desktop/nemo/devicelock/attempt_count"))
{
connect(m_watcher.data(), &LockCodeWatcher::lockCodeSetChanged,
this, &CliAuthenticator::availableMethodsChanged);
Expand Down Expand Up @@ -79,7 +78,7 @@ Authenticator::Methods CliAuthenticator::authenticate(

if (m_watcher->lockCodeSet()) {
const int maximum = maximumAttempts();
const int attempts = m_attemptCount.value(0).toInt();
const int attempts = currentAttempts();

if (maximum > 0 && attempts >= maximum) {
QDBusContext::sendErrorReply(QStringLiteral("org.nemomobile.devicelock.Authenticator.LockedOut"));
Expand Down Expand Up @@ -121,29 +120,27 @@ void CliAuthenticator::enterLockCode(const QString &authenticator, const QString
}
});

command->onFailure([this, connection, authenticator]() {
command->onFailure([this, connection, authenticator](int exitCode) {
const int maximum = maximumAttempts();

if (maximum > 0) {
const int attempts = m_attemptCount.value(0).toInt() + 1;
m_attemptCount.set(attempts);
if (!checkConnection(connection, authenticator)) {
return;
} else if (maximum > 0 && exitCode < 0) {
const int attempts = -exitCode;
sendFeedback(
connection,
authenticator,
Authenticator::IncorrectLockCode,
qMax(0, maximum - attempts));

if (checkConnection(connection, authenticator)) {
sendFeedback(
connection,
authenticator,
Authenticator::IncorrectLockCode,
qMax(0, maximum - attempts));
if (attempts >= maximum) {
sendError(connection, authenticator, Authenticator::LockedOut);

if (attempts >= maximum) {
sendError(connection, authenticator, Authenticator::LockedOut);
clearConnection();

clearConnection();

authenticationEnded(false);
}
authenticationEnded(false);
}
} else if (checkConnection(connection, authenticator)) {
} else {
sendFeedback(connection, authenticator, Authenticator::IncorrectLockCode, -1);
}
});
Expand All @@ -159,8 +156,6 @@ void CliAuthenticator::lockCodeValidated(const QString &lockCode)

void CliAuthenticator::confirmAuthentication(const QVariant &authenticationToken)
{
m_attemptCount.set(0);

sendAuthenticated(m_authenticatorConnection, m_authenticatorPath, authenticationToken);
clearConnection();

Expand Down
3 changes: 0 additions & 3 deletions src/nemo-devicelock/host/cli/cliauthenticator.h
Expand Up @@ -35,8 +35,6 @@

#include <nemo-devicelock/host/hostauthenticator.h>

#include <MGConfItem>

#include <QDBusConnection>
#include <QSharedDataPointer>

Expand Down Expand Up @@ -78,7 +76,6 @@ class CliAuthenticator : public HostAuthenticator
void clearConnection();

QExplicitlySharedDataPointer<LockCodeWatcher> m_watcher;
MGConfItem m_attemptCount;
QString m_authenticatorConnection;
QString m_authenticatorPath;
};
Expand Down
2 changes: 1 addition & 1 deletion src/nemo-devicelock/host/cli/clidevicelock.cpp
Expand Up @@ -75,7 +75,7 @@ void CliDeviceLock::unlock(const QString &, const QVariant &authenticationToken)
setState(DeviceLock::Unlocked);
});

command->onFailure([this, connection, message]() {
command->onFailure([this, connection, message](int) {
connection.send(message.createErrorReply(QDBusError::AccessDenied, QString()));
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/nemo-devicelock/host/cli/clidevicelocksettings.cpp
Expand Up @@ -66,7 +66,7 @@ void CliDeviceLockSettings::changeSetting(
command->onSuccess([this, connection, message]() {
connection.send(message.createReply());
});
command->onFailure([this, connection, message]() {
command->onFailure([this, connection, message](int) {
connection.send(message.createErrorReply(QDBusError::AccessDenied, QString()));
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/nemo-devicelock/host/cli/clidevicereset.cpp
Expand Up @@ -69,7 +69,7 @@ void CliDeviceReset::clearDevice(
command->onSuccess([this, connection, message]() {
connection.send(message.createReply());
});
command->onFailure([this, connection, message]() {
command->onFailure([this, connection, message](int) {
connection.send(message.createErrorReply(QDBusError::AccessDenied, QString()));
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/nemo-devicelock/host/cli/cliencryptionsettings.cpp
Expand Up @@ -63,7 +63,7 @@ void CliEncryptionSettings::encryptHome(const QString &, const QVariant &authent
command->onSuccess([this, connection, message]() {
connection.send(message.createReply());
});
command->onFailure([this, connection, message]() {
command->onFailure([this, connection, message](int) {
connection.send(message.createErrorReply(QDBusError::AccessDenied, QString()));
});
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/nemo-devicelock/host/cli/clilockcodesettings.cpp
Expand Up @@ -75,7 +75,7 @@ void CliLockCodeSettings::change(const QString &oldCode, const QString &newCode)

connection.send(message.createReply());
});
command->onFailure([this, connection, message]() {
command->onFailure([this, connection, message](int) {
connection.send(message.createErrorReply(QDBusError::AccessDenied, QString()));
});
} else {
Expand All @@ -97,7 +97,7 @@ void CliLockCodeSettings::clear(const QString &code)

connection.send(message.createReply());
});
command->onFailure([this, connection, message]() {
command->onFailure([this, connection, message](int) {
connection.send(message.createErrorReply(QDBusError::AccessDenied, QString()));
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/nemo-devicelock/host/cli/lockcodewatcher.cpp
Expand Up @@ -77,7 +77,7 @@ void PluginCommand::processFinished(int exitCode, QProcess::ExitStatus status)
} else if (exitCode == 0 && status == QProcess::NormalExit) {
emit succeeded();
} else {
emit failed();
emit failed(exitCode);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/nemo-devicelock/host/cli/lockcodewatcher.h
Expand Up @@ -61,7 +61,7 @@ class PluginCommand : public QProcess

signals:
void succeeded();
void failed();
void failed(int exitCode);

private:
friend class LockCodeWatcher;
Expand Down
3 changes: 1 addition & 2 deletions src/nemo-devicelock/host/host.pro
Expand Up @@ -12,8 +12,7 @@ QT += dbus
PKGCONFIG += \
dbus-1 \
keepalive \
libsystemd-daemon \
mlite5
libsystemd-daemon

INCLUDEPATH += \
$$PWD/.. \
Expand Down
5 changes: 5 additions & 0 deletions src/nemo-devicelock/host/hostauthenticator.cpp
Expand Up @@ -84,6 +84,11 @@ int HostAuthenticator::maximumAttempts() const
return m_settings->maximumAttempts;
}

int HostAuthenticator::currentAttempts() const
{
return m_settings->currentAttempts;
}

void HostAuthenticator::sendAuthenticated(
const QString &connection, const QString &path, const QVariant &authenticationToken)
{
Expand Down
1 change: 1 addition & 0 deletions src/nemo-devicelock/host/hostauthenticator.h
Expand Up @@ -86,6 +86,7 @@ class HostAuthenticator : public HostObject
virtual void cancel(const QString &authenticator) = 0;

int maximumAttempts() const;
int currentAttempts() const;

void sendAuthenticated(
const QString &connectionName, const QString &path, const QVariant &authenticationToken);
Expand Down
4 changes: 2 additions & 2 deletions src/nemo-devicelock/lockcodesettings.cpp
Expand Up @@ -79,7 +79,7 @@ void LockCodeSettings::change(const QString &oldCode, const QString &newCode)
emit changed();
});

response->onError([this]() {
response->onError([this](const QDBusError &) {
emit changeError();
});
}
Expand All @@ -92,7 +92,7 @@ void LockCodeSettings::clear(const QString &currentCode)
emit cleared();
});

response->onError([this]() {
response->onError([this](const QDBusError &) {
emit clearError();
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/nemo-devicelock/private/clientauthorization.cpp
Expand Up @@ -117,7 +117,7 @@ void ClientAuthorization::requestChallenge()
}
});

response->onError([this]() {
response->onError([this](const QDBusError &) {
if (m_status == RequestingChallenge) {
m_status = NoChallenge;

Expand Down
4 changes: 2 additions & 2 deletions src/nemo-devicelock/private/connection.h
Expand Up @@ -68,8 +68,8 @@ class PendingCall : public QDBusPendingCallWatcher

template <typename T> void onError(const T &handler)
{
connect(this, &PendingCall::failure, [handler](const QDBusError &) {
handler();
connect(this, &PendingCall::failure, [handler](const QDBusError &error) {
handler(error);
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/nemo-devicelock/private/settingswatcher.cpp
Expand Up @@ -43,6 +43,7 @@ const char * const SettingsWatcher::automaticLockingKey = "/desktop/nemo/devicel
const char * const SettingsWatcher::minimumLengthKey = "/desktop/nemo/devicelock/code_min_length";
const char * const SettingsWatcher::maximumLengthKey = "/desktop/nemo/devicelock/code_max_length";
const char * const SettingsWatcher::maximumAttemptsKey = "/desktop/nemo/devicelock/maximum_attempts";
const char * const SettingsWatcher::currentAttemptsKey = "/desktop/nemo/devicelock/current_attempts";
const char * const SettingsWatcher::peekingAllowedKey = "/desktop/nemo/devicelock/peeking_allowed";
const char * const SettingsWatcher::sideloadingAllowedKey = "/desktop/nemo/devicelock/sideloading_allowed";
const char * const SettingsWatcher::showNotificationsKey = "/desktop/nemo/devicelock/show_notification";
Expand All @@ -58,6 +59,7 @@ SettingsWatcher::SettingsWatcher(QObject *parent)
, minimumLength(5)
, maximumLength(42)
, maximumAttempts(-1)
, currentAttempts(0)
, peekingAllowed(1)
, sideloadingAllowed(-1)
, showNotifications(1)
Expand Down Expand Up @@ -112,12 +114,13 @@ static void read(

void SettingsWatcher::reloadSettings()
{
QSettings settings(QStringLiteral("/usr/share/lipstick/devicelock/devicelock_settings.conf"), QSettings::IniFormat);
QSettings settings(m_settingsPath, QSettings::IniFormat);

read(settings, this, automaticLockingKey, 10, &SettingsWatcher::automaticLocking, &SettingsWatcher::automaticLockingChanged);
read(settings, this, minimumLengthKey, 5, &SettingsWatcher::minimumLength, &SettingsWatcher::minimumLengthChanged);
read(settings, this, maximumLengthKey, 42, &SettingsWatcher::maximumLength, &SettingsWatcher::maximumLengthChanged);
read(settings, this, maximumAttemptsKey, -1, &SettingsWatcher::maximumAttempts, &SettingsWatcher::maximumAttemptsChanged);
read(settings, this, currentAttemptsKey, 0, &SettingsWatcher::currentAttempts, &SettingsWatcher::currentAttemptsChanged);
read(settings, this, peekingAllowedKey, 1, &SettingsWatcher::peekingAllowed, &SettingsWatcher::peekingAllowedChanged);
read(settings, this, sideloadingAllowedKey, -1, &SettingsWatcher::sideloadingAllowed, &SettingsWatcher::sideloadingAllowedChanged);
read(settings, this, showNotificationsKey, 1, &SettingsWatcher::showNotifications, &SettingsWatcher::showNotificationsChanged);
Expand Down
3 changes: 3 additions & 0 deletions src/nemo-devicelock/private/settingswatcher.h
Expand Up @@ -53,6 +53,7 @@ class NEMODEVICELOCK_EXPORT SettingsWatcher : public QObject, public QSharedData
int minimumLength;
int maximumLength;
int maximumAttempts;
int currentAttempts;
int peekingAllowed;
int sideloadingAllowed;
int showNotifications;
Expand All @@ -64,6 +65,7 @@ class NEMODEVICELOCK_EXPORT SettingsWatcher : public QObject, public QSharedData
static const char * const minimumLengthKey;
static const char * const maximumLengthKey;
static const char * const maximumAttemptsKey;
static const char * const currentAttemptsKey;
static const char * const peekingAllowedKey;
static const char * const sideloadingAllowedKey;
static const char * const showNotificationsKey;
Expand All @@ -74,6 +76,7 @@ class NEMODEVICELOCK_EXPORT SettingsWatcher : public QObject, public QSharedData
signals:
void automaticLockingChanged();
void maximumAttemptsChanged();
void currentAttemptsChanged();
void minimumLengthChanged();
void maximumLengthChanged();
void peekingAllowedChanged();
Expand Down

0 comments on commit 7ce5ba8

Please sign in to comment.