diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index d5a67a36e..307fb5ebc 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -204,12 +204,19 @@ void Application::slotCheckAuthentication() void Application::slotAuthCheck( const QString& ,QNetworkReply *reply ) { - if( reply->error() == QNetworkReply::AuthenticationRequiredError ) { - qDebug() << "******** Credentials are wrong!"; + if( reply->error() == QNetworkReply::AuthenticationRequiredError ) { // returned if the user is wrong. + qDebug() << "******** Password is wrong!"; QMessageBox::warning(0, tr("No ownCloud Connection"), tr("
Your ownCloud credentials are not correct.
" "Please correct them by starting the configuration dialog from the tray!
")); _actionAddFolder->setEnabled( false ); + } else if( reply->error() == QNetworkReply::OperationCanceledError ) { + // the username was wrong and ownCloudInfo was closing the request after a couple of auth tries. + qDebug() << "******** Username is wrong!"; + QMessageBox::warning(0, tr("No ownCloud Connection"), + tr("Your ownCloud user name is not correct.
" + "Please correct it by starting the configuration dialog from the tray!
")); + _actionAddFolder->setEnabled( false ); } else { qDebug() << "######## Credentials are ok!"; int cnt = _folderMan->setupFolders(); diff --git a/src/mirall/owncloudinfo.cpp b/src/mirall/owncloudinfo.cpp index 365c57422..e4b914339 100644 --- a/src/mirall/owncloudinfo.cpp +++ b/src/mirall/owncloudinfo.cpp @@ -30,6 +30,7 @@ namespace Mirall QNetworkAccessManager* ownCloudInfo::_manager = 0; SslErrorDialog *ownCloudInfo::_sslErrorDialog = 0; bool ownCloudInfo::_certsUntrusted = false; +int ownCloudInfo::_authAttempts = 0; ownCloudInfo::ownCloudInfo( const QString& connectionName, QObject *parent ) : @@ -122,13 +123,23 @@ void ownCloudInfo::slotMkdirFinished() } -void ownCloudInfo::slotAuthentication( QNetworkReply*, QAuthenticator *auth ) +void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *auth ) { - if( auth ) { + if( auth && reply ) { + _authAttempts++; MirallConfigFile cfgFile; - qDebug() << "Authenticating request!"; - auth->setUser( cfgFile.ownCloudUser( _connection ) ); - auth->setPassword( cfgFile.ownCloudPasswd( _connection )); + qDebug() << "Authenticating request for " << reply->url(); + qDebug() << "Our Url: " << cfgFile.ownCloudUrl(_connection, true); + if( reply->url().toString().startsWith( cfgFile.ownCloudUrl( _connection, true )) ) { + auth->setUser( cfgFile.ownCloudUser( _connection ) ); + auth->setPassword( cfgFile.ownCloudPasswd( _connection )); + } else { + qDebug() << "WRN: attempt to authenticate to different url!"; + } + if( _authAttempts > 10 ) { + qDebug() << "Too many attempts to authenticate. Stop request."; + reply->close(); + } } } diff --git a/src/mirall/owncloudinfo.h b/src/mirall/owncloudinfo.h index 749cc96e6..8c3bd45fb 100644 --- a/src/mirall/owncloudinfo.h +++ b/src/mirall/owncloudinfo.h @@ -86,6 +86,7 @@ private: QHash