Fix connect widget

Don't use winId as it breaks QQuickWidget (see Qt docs)
Add an isAnonymous() function to check whether the login is there or will not be used
Properly set passwords in the wallet
Do the hashing properly
This commit is contained in:
Luca Beltrame 2015-02-08 23:51:15 +01:00
parent 5035caf3ef
commit d20cc5d3f5
2 changed files with 35 additions and 17 deletions

View file

@ -24,6 +24,7 @@
#include "libdanbooru/danbooruservice.h"
#include <QCryptographicHash>
#include <QDebug>
#include <KWallet>
@ -64,21 +65,20 @@ DanbooruConnectWidget::DanbooruConnectWidget(QVector< QUrl > urlList,
closeButton->setToolTip(i18n("Close dialog and discard changes"));
userLineEdit->setClearButtonEnabled(true);
passwdLineEdit->setClearButtonEnabled(true);
passwdLineEdit->setEchoMode(QLineEdit::Password);
if (anonCheckBox->isChecked()) {
userLineEdit->setEnabled(false);
passwdLineEdit->setEnabled(false);
}
WId winid = this->parentWidget()->winId();
danbooruUrlComboBox->clear();
for (auto item : urlList) {
danbooruUrlComboBox->insertUrl(urlList.indexOf(item), item);
}
m_wallet = Wallet::openWallet(Wallet::NetworkWallet(), winid,
m_wallet = Wallet::openWallet(Wallet::NetworkWallet(), 0,
Wallet::Asynchronous
);
@ -127,7 +127,18 @@ void DanbooruConnectWidget::getWalletData()
}
m_username = valueMap[QLatin1String("username")];
m_password = valueMap[QLatin1String("password")];
QString hashedPassword;
hashedPassword = boardSalts.value(m_boardUrl);
hashedPassword = hashedPassword.arg(hashedPassword ,valueMap[QLatin1String("password")]);
hashedPassword = QCryptographicHash::hash(hashedPassword.toUtf8(),
QCryptographicHash::Sha1).toHex();
m_password = hashedPassword;
userLineEdit->setText(m_username);
passwdLineEdit->setText(valueMap[QLatin1String("password")]);
}
}
@ -165,32 +176,37 @@ QString DanbooruConnectWidget::password() const
void DanbooruConnectWidget::accept()
{
if (m_boardUrl.isEmpty()) {
return;
}
QString hashedPassword;
if (!m_username.isEmpty() && !m_password.isEmpty()) {
if (!userLineEdit->text().isEmpty() && !passwdLineEdit->text().isEmpty()) {
if (m_wallet && !m_wallet->hasEntry(m_boardUrl.url())) {
QMap<QString, QString> dataMap;
dataMap.insert(QLatin1String("username"), m_username);
dataMap.insert(QLatin1String("password"), m_password);
dataMap.insert(QLatin1String("password"), passwdLineEdit->text());
m_wallet->writeMap(m_boardUrl.url(), dataMap);
}
hashedPassword = boardSalts.value(m_boardUrl).arg(m_password);
hashedPassword = QCryptographicHash::hash(hashedPassword.toUtf8(),
QCryptographicHash::Sha1
).toHex();
// Only calculate if we haven't set a password from the wallet already
if (m_password.isEmpty()) {
hashedPassword = boardSalts.value(m_boardUrl);
hashedPassword = hashedPassword.arg(hashedPassword, passwdLineEdit->text());
hashedPassword = QCryptographicHash::hash(hashedPassword.toUtf8(),
QCryptographicHash::Sha1).toHex();
m_password = hashedPassword;
}
}
DanbooruService *service = new DanbooruService(m_boardUrl, m_username,
hashedPassword);
Q_EMIT(connectionEstablished(service));
m_boardUrl = QUrl::fromUserInput(danbooruUrlComboBox->currentText());
Q_EMIT(accepted());
}
bool DanbooruConnectWidget::isAnonymous() const {
return anonCheckBox->isChecked();
hide();
}
}; // namespace Danbooru

View file

@ -52,6 +52,7 @@ public:
QString username() const;
QString password() const;
QUrl boardUrl() const;
bool isAnonymous() const;
private:
QUrl m_boardUrl;
@ -62,6 +63,7 @@ private:
Q_SIGNALS:
void connectionEstablished(DanbooruService *service);
void accepted();
void rejected();
private Q_SLOTS: