Implemented remote credential storage via qtkeychain
Imported qtkeychain FossilOrigin-Name: 7c068aa8acdae1b86dee004d2d4cd7fb42904186
This commit is contained in:
@@ -2505,12 +2505,18 @@ void MainWindow::on_actionEditRemote_triggered()
|
||||
{
|
||||
QStringList remotes;
|
||||
getSelectionRemotes(remotes);
|
||||
|
||||
if(remotes.empty())
|
||||
return;
|
||||
|
||||
QUrl url(remotes.first());
|
||||
bool exists = KeychainGet(this, url);
|
||||
|
||||
if(!RemoteDialog::run(this, url))
|
||||
return;
|
||||
|
||||
if(exists)
|
||||
KeychainDelete(this, url);
|
||||
|
||||
if(!KeychainSet(this, url))
|
||||
QMessageBox::critical(this, tr("Error"), tr("Could not store information to keychain."), QMessageBox::Ok );
|
||||
}
|
||||
|
@@ -29,8 +29,8 @@ bool RemoteDialog::run(QWidget *parent, QUrl &url)
|
||||
// Set URL components
|
||||
if(!url.isEmpty())
|
||||
{
|
||||
QString qq = url.toString(QUrl::PrettyDecoded|QUrl::RemoveUserInfo);
|
||||
dlg.ui->lineURL->setText(qq);
|
||||
QString url_no_credentials = url.toString(QUrl::PrettyDecoded|QUrl::RemoveUserInfo);
|
||||
dlg.ui->lineURL->setText(url_no_credentials);
|
||||
dlg.ui->lineUserName->setText(url.userName());
|
||||
dlg.ui->linePassword->setText(url.password());
|
||||
}
|
||||
|
@@ -2,6 +2,9 @@
|
||||
#include <QMessageBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFileDialog>
|
||||
#include <QEventLoop>
|
||||
#include "ext/qtkeychain/keychain.h"
|
||||
#define KEYCHAIN_ROOT "Fuel-SCM"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
QMessageBox::StandardButton DialogQuery(QWidget *parent, const QString &title, const QString &query, QMessageBox::StandardButtons buttons)
|
||||
@@ -388,4 +391,56 @@ void BuildNameToModelIndex(name_modelindex_map_t &map, const QStandardItemModel
|
||||
Q_ASSERT(item);
|
||||
BuildNameToModelIndex(map, *item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool KeychainSet(QObject *parent, const QUrl &url)
|
||||
{
|
||||
QEventLoop loop(parent);
|
||||
QKeychain::WritePasswordJob job(url.toString(QUrl::PrettyDecoded|QUrl::RemoveUserInfo));
|
||||
job.connect( &job, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()) );
|
||||
job.setAutoDelete( false );
|
||||
job.setInsecureFallback(false);
|
||||
job.setKey(url.userName());
|
||||
job.setTextData(url.password());
|
||||
job.start();
|
||||
loop.exec();
|
||||
return job.error() == QKeychain::NoError;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool KeychainGet(QObject *parent, QUrl &url)
|
||||
{
|
||||
QEventLoop loop(parent);
|
||||
QKeychain::ReadPasswordJob job(url.toString(QUrl::PrettyDecoded|QUrl::RemoveUserInfo));
|
||||
job.connect( &job, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()));
|
||||
job.setAutoDelete( false );
|
||||
job.setInsecureFallback(false);
|
||||
job.setAutoDelete( false );
|
||||
job.setKey(url.userName());
|
||||
job.start();
|
||||
loop.exec();
|
||||
|
||||
if(job.error() != QKeychain::NoError)
|
||||
return false;
|
||||
|
||||
url.setUserName(job.key());
|
||||
url.setPassword(job.textData());
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool KeychainDelete(QObject* parent, const QUrl& url)
|
||||
{
|
||||
QEventLoop loop(parent);
|
||||
QKeychain::DeletePasswordJob job(url.toString(QUrl::PrettyDecoded|QUrl::RemoveUserInfo));
|
||||
job.connect( &job, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()));
|
||||
job.setAutoDelete( false );
|
||||
job.setInsecureFallback(false);
|
||||
job.setAutoDelete( false );
|
||||
job.setKey(url.userName());
|
||||
job.start();
|
||||
loop.exec();
|
||||
|
||||
return job.error() == QKeychain::NoError;
|
||||
}
|
||||
|
@@ -22,6 +22,9 @@ typedef QMap<QString, QModelIndex> name_modelindex_map_t;
|
||||
void GetStandardItemTextRecursive(QString &name, const QStandardItem &item, const QChar &separator='/');
|
||||
void BuildNameToModelIndex(name_modelindex_map_t &map, const QStandardItem &item);
|
||||
void BuildNameToModelIndex(name_modelindex_map_t &map, const QStandardItemModel &model);
|
||||
bool KeychainSet(QObject* parent, const QUrl& url);
|
||||
bool KeychainGet(QObject* parent, QUrl& url);
|
||||
bool KeychainDelete(QObject* parent, const QUrl& url);
|
||||
|
||||
|
||||
typedef QMap<QString, QString> QStringMap;
|
||||
|
Reference in New Issue
Block a user