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:
		
					parent
					
						
							
								5035caf3ef
							
						
					
				
			
			
				commit
				
					
						d20cc5d3f5
					
				
			
		
					 2 changed files with 35 additions and 17 deletions
				
			
		| 
						 | 
					@ -24,6 +24,7 @@
 | 
				
			||||||
#include "libdanbooru/danbooruservice.h"
 | 
					#include "libdanbooru/danbooruservice.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QCryptographicHash>
 | 
					#include <QCryptographicHash>
 | 
				
			||||||
 | 
					#include <QDebug>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <KWallet>
 | 
					#include <KWallet>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -64,21 +65,20 @@ DanbooruConnectWidget::DanbooruConnectWidget(QVector< QUrl > urlList,
 | 
				
			||||||
    closeButton->setToolTip(i18n("Close dialog and discard changes"));
 | 
					    closeButton->setToolTip(i18n("Close dialog and discard changes"));
 | 
				
			||||||
    userLineEdit->setClearButtonEnabled(true);
 | 
					    userLineEdit->setClearButtonEnabled(true);
 | 
				
			||||||
    passwdLineEdit->setClearButtonEnabled(true);
 | 
					    passwdLineEdit->setClearButtonEnabled(true);
 | 
				
			||||||
 | 
					    passwdLineEdit->setEchoMode(QLineEdit::Password);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (anonCheckBox->isChecked()) {
 | 
					    if (anonCheckBox->isChecked()) {
 | 
				
			||||||
        userLineEdit->setEnabled(false);
 | 
					        userLineEdit->setEnabled(false);
 | 
				
			||||||
        passwdLineEdit->setEnabled(false);
 | 
					        passwdLineEdit->setEnabled(false);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    WId winid = this->parentWidget()->winId();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    danbooruUrlComboBox->clear();
 | 
					    danbooruUrlComboBox->clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (auto item : urlList) {
 | 
					    for (auto item : urlList) {
 | 
				
			||||||
        danbooruUrlComboBox->insertUrl(urlList.indexOf(item), item);
 | 
					        danbooruUrlComboBox->insertUrl(urlList.indexOf(item), item);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_wallet = Wallet::openWallet(Wallet::NetworkWallet(), winid,
 | 
					    m_wallet = Wallet::openWallet(Wallet::NetworkWallet(), 0,
 | 
				
			||||||
                                  Wallet::Asynchronous
 | 
					                                  Wallet::Asynchronous
 | 
				
			||||||
                                 );
 | 
					                                 );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -127,7 +127,18 @@ void DanbooruConnectWidget::getWalletData()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        m_username = valueMap[QLatin1String("username")];
 | 
					        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()
 | 
					void DanbooruConnectWidget::accept()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (m_boardUrl.isEmpty()) {
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QString hashedPassword;
 | 
					    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())) {
 | 
					        if (m_wallet && !m_wallet->hasEntry(m_boardUrl.url())) {
 | 
				
			||||||
            QMap<QString, QString> dataMap;
 | 
					            QMap<QString, QString> dataMap;
 | 
				
			||||||
            dataMap.insert(QLatin1String("username"), m_username);
 | 
					            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);
 | 
					            m_wallet->writeMap(m_boardUrl.url(), dataMap);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        hashedPassword = boardSalts.value(m_boardUrl).arg(m_password);
 | 
					        // Only calculate if we haven't set a password from the wallet already
 | 
				
			||||||
        hashedPassword = QCryptographicHash::hash(hashedPassword.toUtf8(),
 | 
					        if (m_password.isEmpty()) {
 | 
				
			||||||
                         QCryptographicHash::Sha1
 | 
					
 | 
				
			||||||
                                                 ).toHex();
 | 
					            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,
 | 
					    m_boardUrl = QUrl::fromUserInput(danbooruUrlComboBox->currentText());
 | 
				
			||||||
            hashedPassword);
 | 
					    Q_EMIT(accepted());
 | 
				
			||||||
    Q_EMIT(connectionEstablished(service));
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool DanbooruConnectWidget::isAnonymous() const {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return anonCheckBox->isChecked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    hide();
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}; // namespace Danbooru
 | 
					}; // namespace Danbooru
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,6 +52,7 @@ public:
 | 
				
			||||||
    QString username() const;
 | 
					    QString username() const;
 | 
				
			||||||
    QString password() const;
 | 
					    QString password() const;
 | 
				
			||||||
    QUrl boardUrl() const;
 | 
					    QUrl boardUrl() const;
 | 
				
			||||||
 | 
					    bool isAnonymous() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    QUrl  m_boardUrl;
 | 
					    QUrl  m_boardUrl;
 | 
				
			||||||
| 
						 | 
					@ -62,6 +63,7 @@ private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Q_SIGNALS:
 | 
					Q_SIGNALS:
 | 
				
			||||||
    void connectionEstablished(DanbooruService *service);
 | 
					    void connectionEstablished(DanbooruService *service);
 | 
				
			||||||
 | 
					    void accepted();
 | 
				
			||||||
    void rejected();
 | 
					    void rejected();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private Q_SLOTS:
 | 
					private Q_SLOTS:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue