mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 13:35:58 +03:00
- Restrict authentication to the configured ownCloud URL
- catch wrong username error correctly and report to user.
This commit is contained in:
parent
b92c22b6df
commit
2f5a3b849c
3 changed files with 26 additions and 7 deletions
|
@ -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("<p>Your ownCloud credentials are not correct.</p>"
|
||||
"<p>Please correct them by starting the configuration dialog from the tray!</p>"));
|
||||
_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("<p>Your ownCloud user name is not correct.</p>"
|
||||
"<p>Please correct it by starting the configuration dialog from the tray!</p>"));
|
||||
_actionAddFolder->setEnabled( false );
|
||||
} else {
|
||||
qDebug() << "######## Credentials are ok!";
|
||||
int cnt = _folderMan->setupFolders();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ private:
|
|||
QHash<QNetworkReply*, QString> _directories;
|
||||
static SslErrorDialog *_sslErrorDialog;
|
||||
static bool _certsUntrusted;
|
||||
static int _authAttempts;
|
||||
};
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue