1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

[PasswordManager] Added updated member to PasswordEntry struct.

This commit is contained in:
nowrep 2013-05-20 11:05:54 +02:00
parent c7c1002fce
commit 54a3509fcb
10 changed files with 43 additions and 33 deletions

View File

@ -109,7 +109,7 @@ QVector<PasswordEntry> AutoFill::getAllFormData()
return m_manager->getAllEntries();
}
void AutoFill::updateLastUsed(const PasswordEntry &data)
void AutoFill::updateLastUsed(PasswordEntry &data)
{
m_manager->updateLastUsed(data);
}
@ -225,20 +225,21 @@ void AutoFill::post(const QNetworkRequest &request, const QByteArray &outgoingDa
return;
}
PasswordEntry updateData = { -1, QString(), QString(), QString(), QByteArray() };
PasswordEntry updateData;
if (isStored(siteUrl)) {
const QVector<PasswordEntry> &list = getFormData(siteUrl);
foreach (const PasswordEntry &data, list) {
if (data.username == formData.username) {
updateLastUsed(data);
updateData = data;
updateLastUsed(updateData);
if (data.password == formData.password) {
updateData.password.clear();
return;
}
updateData = data;
updateData.username = formData.username;
updateData.password = formData.password;
updateData.data = formData.postData;

View File

@ -47,7 +47,7 @@ public:
QVector<PasswordEntry> getFormData(const QUrl &url);
QVector<PasswordEntry> getAllFormData();
void updateLastUsed(const PasswordEntry &data);
void updateLastUsed(PasswordEntry &data);
void addEntry(const QUrl &url, const QString &name, const QString &pass);
void addEntry(const QUrl &url, const PageFormData &formData);

View File

@ -128,7 +128,7 @@ void DatabasePasswordBackend::updateEntry(const PasswordEntry &entry)
mApp->dbWriter()->executeQuery(query);
}
void DatabasePasswordBackend::updateLastUsed(const PasswordEntry &entry)
void DatabasePasswordBackend::updateLastUsed(PasswordEntry &entry)
{
QSqlQuery query;
query.prepare("UPDATE autofill SET last_used=strftime('%s', 'now') WHERE id=?");

View File

@ -32,7 +32,7 @@ public:
void addEntry(const PasswordEntry &entry);
void updateEntry(const PasswordEntry &entry);
void updateLastUsed(const PasswordEntry &entry);
void updateLastUsed(PasswordEntry &entry);
void removeEntry(const PasswordEntry &entry);
void removeAll();

View File

@ -35,7 +35,7 @@ public:
virtual void addEntry(const PasswordEntry &entry) = 0;
virtual void updateEntry(const PasswordEntry &entry) = 0;
virtual void updateLastUsed(const PasswordEntry &entry) = 0;
virtual void updateLastUsed(PasswordEntry &entry) = 0;
virtual void removeEntry(const PasswordEntry &entry) = 0;
virtual void removeAll() = 0;

View File

@ -22,21 +22,22 @@
#include <QVector>
static const int passwordEntryVersion = 1;
static const int passwordEntryVersion = 2;
QDataStream &operator <<(QDataStream &stream, const PasswordEntry &tab)
QDataStream &operator <<(QDataStream &stream, const PasswordEntry &entry)
{
stream << passwordEntryVersion;
stream << tab.host;
stream << tab.id;
stream << tab.username;
stream << tab.password;
stream << tab.data;
stream << entry.host;
stream << entry.id;
stream << entry.username;
stream << entry.password;
stream << entry.data;
stream << entry.updated;
return stream;
}
QDataStream &operator >>(QDataStream &stream, PasswordEntry &tab)
QDataStream &operator >>(QDataStream &stream, PasswordEntry &entry)
{
int version;
stream >> version;
@ -45,11 +46,12 @@ QDataStream &operator >>(QDataStream &stream, PasswordEntry &tab)
return stream;
}
stream >> tab.host;
stream >> tab.id;
stream >> tab.username;
stream >> tab.password;
stream >> tab.data;
stream >> entry.host;
stream >> entry.id;
stream >> entry.username;
stream >> entry.password;
stream >> entry.data;
stream >> entry.updated;
return stream;
}
@ -98,7 +100,7 @@ void PasswordManager::updateEntry(const PasswordEntry &entry)
m_backend->updateEntry(entry);
}
void PasswordManager::updateLastUsed(const PasswordEntry &entry)
void PasswordManager::updateLastUsed(PasswordEntry &entry)
{
ensureLoaded();
m_backend->updateLastUsed(entry);

View File

@ -33,6 +33,9 @@ struct QT_QUPZILLA_EXPORT PasswordEntry {
QString username;
QString password;
QByteArray data;
int updated;
PasswordEntry() : updated(-1) { }
bool isValid() const {
return !password.isEmpty();
@ -42,8 +45,12 @@ struct QT_QUPZILLA_EXPORT PasswordEntry {
return id == other.id;
}
friend QT_QUPZILLA_EXPORT QDataStream &operator<<(QDataStream &stream, const PasswordEntry &tab);
friend QT_QUPZILLA_EXPORT QDataStream &operator>>(QDataStream &stream, PasswordEntry &tab);
bool operator<(const PasswordEntry &other) const {
return updated > other.updated;
}
friend QT_QUPZILLA_EXPORT QDataStream &operator<<(QDataStream &stream, const PasswordEntry &entry);
friend QT_QUPZILLA_EXPORT QDataStream &operator>>(QDataStream &stream, PasswordEntry &entry);
};
class QT_QUPZILLA_EXPORT PasswordManager : public QObject
@ -60,7 +67,7 @@ public:
void addEntry(const PasswordEntry &entry);
void updateEntry(const PasswordEntry &entry);
void updateLastUsed(const PasswordEntry &entry);
void updateLastUsed(PasswordEntry &entry);
void removeEntry(const PasswordEntry &entry);
void removeAllEntries();

View File

@ -1,6 +1,6 @@
include(../../defines.pri)
contains(DEFINES, "KDE_INTEGRATION") {
!mac:unix:contains(DEFINES, "KDE_INTEGRATION") {
TARGET = $$qtLibraryTarget(KWalletPasswords)
SOURCES += kwalletplugin.cpp \

View File

@ -107,22 +107,22 @@ void KWalletPasswordBackend::updateEntry(const PasswordEntry &entry)
}
}
void KWalletPasswordBackend::updateLastUsed(const PasswordEntry &entry)
void KWalletPasswordBackend::updateLastUsed(PasswordEntry &entry)
{
initialize();
QString id = QString("%1/%2").arg(entry.host, QString::number(QDateTime::currentDateTime().toTime_t()));
PasswordEntry stored = entry;
stored.id = id;
m_wallet->removeEntry(entry.id.toString());
m_wallet->writeEntry(stored.id.toString(), encodeEntry(stored));
int index = m_allEntries.indexOf(entry);
entry.id = id;
m_wallet->writeEntry(entry.id.toString(), encodeEntry(entry));
if (index > -1) {
m_allEntries[index] = stored;
m_allEntries[index] = entry;
}
}

View File

@ -37,7 +37,7 @@ public:
void addEntry(const PasswordEntry &entry);
void updateEntry(const PasswordEntry &entry);
void updateLastUsed(const PasswordEntry &entry);
void updateLastUsed(PasswordEntry &entry);
void removeEntry(const PasswordEntry &entry);
void removeAll();