mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 13:35:58 +03:00
Removed use of CredentialStore from class and added setter for
credentials. This makes handling of temporar credentials for the setup dialog easier and streamlines the code.
This commit is contained in:
parent
cece465947
commit
fa6331a40a
2 changed files with 74 additions and 8 deletions
|
@ -16,7 +16,6 @@
|
||||||
#include "mirall/mirallconfigfile.h"
|
#include "mirall/mirallconfigfile.h"
|
||||||
#include "mirall/version.h"
|
#include "mirall/version.h"
|
||||||
#include "mirall/theme.h"
|
#include "mirall/theme.h"
|
||||||
#include "mirall/credentialstore.h"
|
|
||||||
|
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
@ -26,6 +25,8 @@
|
||||||
#include <QHttp>
|
#include <QHttp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define DEFAULT_CONNECTION QLatin1String("default");
|
||||||
|
|
||||||
namespace Mirall
|
namespace Mirall
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -131,8 +132,14 @@ void ownCloudInfo::mkdirRequest( const QString& dir )
|
||||||
conMode = QHttp::ConnectionModeHttps;
|
conMode = QHttp::ConnectionModeHttps;
|
||||||
|
|
||||||
QHttp* qhttp = new QHttp(QString(url.encodedHost()), conMode, 0, this);
|
QHttp* qhttp = new QHttp(QString(url.encodedHost()), conMode, 0, this);
|
||||||
qhttp->setUser( CredentialStore::instance()->user(_connection),
|
|
||||||
CredentialStore::instance()->password(_connection) );
|
QString con = _configHandle;
|
||||||
|
if( con.isEmpty() ) con = DEFAULT_CONNECTION;
|
||||||
|
if( _credentials.contains(con)) {
|
||||||
|
oCICredentials creds = _credentials.value(con);
|
||||||
|
|
||||||
|
qhttp->setUser( creds.user, creds.passwd );
|
||||||
|
}
|
||||||
|
|
||||||
connect(qhttp, SIGNAL(requestStarted(int)), this,SLOT(qhttpRequestStarted(int)));
|
connect(qhttp, SIGNAL(requestStarted(int)), this,SLOT(qhttpRequestStarted(int)));
|
||||||
connect(qhttp, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool)));
|
connect(qhttp, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool)));
|
||||||
|
@ -147,7 +154,16 @@ void ownCloudInfo::mkdirRequest( const QString& dir )
|
||||||
header.setValue("Connection", "keep-alive");
|
header.setValue("Connection", "keep-alive");
|
||||||
header.setContentType("application/x-www-form-urlencoded"); //important
|
header.setContentType("application/x-www-form-urlencoded"); //important
|
||||||
header.setContentLength(0);
|
header.setContentLength(0);
|
||||||
header.setValue("Authorization", CredentialStore::instance()->basicAuthHeader());
|
|
||||||
|
QString con = _configHandle;
|
||||||
|
if( con.isEmpty() ) con = DEFAULT_CONNECTION;
|
||||||
|
if( _credentials.contains(con)) {
|
||||||
|
oCICredentials creds = _credentials.value(con);
|
||||||
|
QString concatenated = creds.user + QLatin1Char(':') + creds.passwd;
|
||||||
|
const QString b(QLatin1String("Basic "));
|
||||||
|
QByteArray data = b.toLocal8Bit() + concatenated.toLocal8Bit().toBase64();
|
||||||
|
header.setValue("Authorization", data);
|
||||||
|
}
|
||||||
|
|
||||||
int david = qhttp->request(header,0,0);
|
int david = qhttp->request(header,0,0);
|
||||||
//////////////// connect(davinfo, SIGNAL(dataSendProgress(int,int)), this, SLOT(SendStatus(int, int)));
|
//////////////// connect(davinfo, SIGNAL(dataSendProgress(int,int)), this, SLOT(SendStatus(int, int)));
|
||||||
|
@ -242,8 +258,18 @@ void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *aut
|
||||||
MirallConfigFile cfgFile( configHandle );
|
MirallConfigFile cfgFile( configHandle );
|
||||||
qDebug() << "Authenticating request for " << reply->url();
|
qDebug() << "Authenticating request for " << reply->url();
|
||||||
if( reply->url().toString().startsWith( cfgFile.ownCloudUrl( _connection, true )) ) {
|
if( reply->url().toString().startsWith( cfgFile.ownCloudUrl( _connection, true )) ) {
|
||||||
auth->setUser( CredentialStore::instance()->user() ); //_connection ) );
|
|
||||||
auth->setPassword( CredentialStore::instance()->password() ); // _connection ));
|
QString con = configHandle;
|
||||||
|
if( con.isEmpty() ) con = DEFAULT_CONNECTION;
|
||||||
|
if( _credentials.contains(con)) {
|
||||||
|
oCICredentials creds = _credentials.value(con);
|
||||||
|
|
||||||
|
auth->setUser( creds.user );
|
||||||
|
auth->setPassword( creds.passwd );
|
||||||
|
} else {
|
||||||
|
qDebug() << "Unable to get Credentials, not set!";
|
||||||
|
reply->close();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "WRN: attempt to authenticate to different url - attempt " <<_authAttempts;
|
qDebug() << "WRN: attempt to authenticate to different url - attempt " <<_authAttempts;
|
||||||
}
|
}
|
||||||
|
@ -251,7 +277,6 @@ void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *aut
|
||||||
qDebug() << "Too many attempts to authenticate. Stop request.";
|
qDebug() << "Too many attempts to authenticate. Stop request.";
|
||||||
reply->close();
|
reply->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ownCloudInfo::configHandle(QNetworkReply *reply)
|
QString ownCloudInfo::configHandle(QNetworkReply *reply)
|
||||||
|
@ -431,6 +456,24 @@ void ownCloudInfo::slotError( QNetworkReply::NetworkError err)
|
||||||
qDebug() << "ownCloudInfo Network Error: " << err;
|
qDebug() << "ownCloudInfo Network Error: " << err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ownCloudInfo::setCredentials( const QString& user, const QString& passwd,
|
||||||
|
const QString& configHandle )
|
||||||
|
{
|
||||||
|
QString con( configHandle );
|
||||||
|
if( configHandle.isEmpty() )
|
||||||
|
con = DEFAULT_CONNECTION;
|
||||||
|
|
||||||
|
if( _credentials.contains(con) ) {
|
||||||
|
qDebug() << "Overwriting credentials for connection " << con;
|
||||||
|
}
|
||||||
|
|
||||||
|
oCICredentials creds;
|
||||||
|
creds.user = user;
|
||||||
|
creds.passwd = passwd;
|
||||||
|
creds.connection = con;
|
||||||
|
_credentials[con] = creds;
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
void ownCloudInfo::setupHeaders( QNetworkRequest & req, quint64 size )
|
void ownCloudInfo::setupHeaders( QNetworkRequest & req, quint64 size )
|
||||||
{
|
{
|
||||||
|
@ -441,7 +484,16 @@ void ownCloudInfo::setupHeaders( QNetworkRequest & req, quint64 size )
|
||||||
req.setRawHeader( QByteArray("Host"), url.host().toUtf8() );
|
req.setRawHeader( QByteArray("Host"), url.host().toUtf8() );
|
||||||
req.setRawHeader( QByteArray("User-Agent"), QString::fromLatin1("mirall-%1")
|
req.setRawHeader( QByteArray("User-Agent"), QString::fromLatin1("mirall-%1")
|
||||||
.arg(QLatin1String(MIRALL_STRINGIFY(MIRALL_VERSION))).toAscii());
|
.arg(QLatin1String(MIRALL_STRINGIFY(MIRALL_VERSION))).toAscii());
|
||||||
req.setRawHeader( QByteArray("Authorization"), CredentialStore::instance()->basicAuthHeader() );
|
|
||||||
|
QString con = _configHandle;
|
||||||
|
if( con.isEmpty() ) con = DEFAULT_CONNECTION;
|
||||||
|
if( _credentials.contains(con)) {
|
||||||
|
oCICredentials creds = _credentials.value(con);
|
||||||
|
QString concatenated = creds.user + QLatin1Char(':') + creds.passwd;
|
||||||
|
const QString b(QLatin1String("Basic "));
|
||||||
|
QByteArray data = b.toLocal8Bit() + concatenated.toLocal8Bit().toBase64();
|
||||||
|
req.setRawHeader( QByteArray("Authorization"), data );
|
||||||
|
}
|
||||||
|
|
||||||
if (size) {
|
if (size) {
|
||||||
req.setHeader( QNetworkRequest::ContentLengthHeader, size);
|
req.setHeader( QNetworkRequest::ContentLengthHeader, size);
|
||||||
|
|
|
@ -27,6 +27,12 @@
|
||||||
namespace Mirall
|
namespace Mirall
|
||||||
{
|
{
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
QString user;
|
||||||
|
QString passwd;
|
||||||
|
QString connection;
|
||||||
|
} oCICredentials;
|
||||||
|
|
||||||
class ownCloudInfo : public QObject
|
class ownCloudInfo : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -89,6 +95,13 @@ public:
|
||||||
*/
|
*/
|
||||||
QList<QSslCertificate> certificateChain() const;
|
QList<QSslCertificate> certificateChain() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store credentials for a given connection. Empty connection parameter
|
||||||
|
* means "default connection".
|
||||||
|
*/
|
||||||
|
void setCredentials( const QString&, const QString&,
|
||||||
|
const QString& configHandle = QString::null );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// result signal with url- and version string.
|
// result signal with url- and version string.
|
||||||
void ownCloudInfoFound( const QString&, const QString&, const QString&, const QString& );
|
void ownCloudInfoFound( const QString&, const QString&, const QString&, const QString& );
|
||||||
|
@ -138,6 +151,7 @@ private:
|
||||||
QList<QSslCertificate> _certificateChain;
|
QList<QSslCertificate> _certificateChain;
|
||||||
bool _certsUntrusted;
|
bool _certsUntrusted;
|
||||||
int _authAttempts;
|
int _authAttempts;
|
||||||
|
QMap<QString, oCICredentials> _credentials;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue