[Pkg-owncloud-commits] [owncloud-client] 106/164: SetupW: Display proper error messages if password or user was wrong.

Sandro Knauß hefee-guest at moszumanska.debian.org
Sun Mar 22 11:56:59 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 396f38598fa7f9e04adc4bd9a963fbd8f95a5161
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Fri Mar 6 16:36:21 2015 +0100

    SetupW: Display proper error messages if password or user was wrong.
    
    If the password or user was wrong during setup, the client showed a
    ConnectionClosed error instead of a proper Username or password wrong
    message. This was because in HTTPCredentials::slotAuthentication, the
    reply is closed, and a property is set to indicate the auth problem.
    
    This patch now checks at all occurences of networkErrors if it might
    have been an authentication problem, and displays something useful.
    
    There is a good chance that this is a sufficient fix for
    owncloud/enterprise#556
---
 src/gui/folderwizard.cpp              |  8 ++++++--
 src/gui/owncloudsetupwizard.cpp       | 21 ++++++++++++++++-----
 src/libsync/connectionvalidator.cpp   |  8 +++++++-
 src/libsync/creds/httpcredentials.cpp |  7 +++----
 src/libsync/networkjobs.cpp           | 25 ++++++++++++++++++++-----
 src/libsync/networkjobs.h             |  5 ++++-
 6 files changed, 56 insertions(+), 18 deletions(-)

diff --git a/src/gui/folderwizard.cpp b/src/gui/folderwizard.cpp
index c1a583f..1160ca5 100644
--- a/src/gui/folderwizard.cpp
+++ b/src/gui/folderwizard.cpp
@@ -293,8 +293,12 @@ void FolderWizardRemotePath::slotCreateRemoteFolderFinished(QNetworkReply::Netwo
 void FolderWizardRemotePath::slotHandleNetworkError(QNetworkReply *reply)
 {
     qDebug() << "** webdav mkdir request failed:" << reply->error();
-    showWarn(tr("Failed to create the folder on %1. Please check manually.")
-             .arg(Theme::instance()->appNameGUI()));
+    if( authenticationFailHappened(reply)) {
+        showWarn(tr("Authentication failed accessing %1").arg(Theme::instance()->appNameGUI()));
+    } else {
+        showWarn(tr("Failed to create the folder on %1. Please check manually.")
+                 .arg(Theme::instance()->appNameGUI()));
+    }
 }
 
 static QTreeWidgetItem* findFirstChild(QTreeWidgetItem *parent, const QString& text)
diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp
index 13c3b55..9cbdd20 100644
--- a/src/gui/owncloudsetupwizard.cpp
+++ b/src/gui/owncloudsetupwizard.cpp
@@ -245,16 +245,27 @@ bool OwncloudSetupWizard::checkDowngradeAdvised(QNetworkReply* reply)
 void OwncloudSetupWizard::slotConnectionCheck(QNetworkReply* reply)
 {
     QString msg = reply->errorString();
-    switch (reply->error()) {
+    QNetworkReply::NetworkError err = reply->error();
+
+    // int errCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+
+    switch (err) {
     case QNetworkReply::NoError:
     case QNetworkReply::ContentNotFoundError:
         _ocWizard->successfulStep();
         break;
     default:
-        if (!_ocWizard->account()->credentials()->stillValid(reply)) {
-            msg = tr("Access forbidden by server. To verify that you have proper access, "
-                     "<a href=\"%1\">click here</a> to access the service with your browser.")
-                    .arg(_ocWizard->account()->url().toString());
+        if( authenticationFailHappened(reply) ) {
+            // if the authentication fails, the request is canceled in HttpCredentials::slotAuthentication
+            // because of that, we need to check this here.
+            msg = tr("Credential Error: The entered username or password is wrong.");
+        } else {
+
+            if (!_ocWizard->account()->credentials()->stillValid(reply)) {
+                msg = tr("Access forbidden by server. To verify that you have proper access, "
+                         "<a href=\"%1\">click here</a> to access the service with your browser.")
+                        .arg(_ocWizard->account()->url().toString());
+            }
         }
         _ocWizard->show();
         if (_ocWizard->currentId() == WizardCommon::Page_ShibbolethCreds) {
diff --git a/src/libsync/connectionvalidator.cpp b/src/libsync/connectionvalidator.cpp
index e586fb3..51398c2 100644
--- a/src/libsync/connectionvalidator.cpp
+++ b/src/libsync/connectionvalidator.cpp
@@ -104,8 +104,14 @@ void ConnectionValidator::slotStatusFound(const QUrl&url, const QVariantMap &inf
 // status.php could not be loaded (network or server issue!).
 void ConnectionValidator::slotNoStatusFound(QNetworkReply *reply)
 {
+    if( authenticationFailHappened(reply) ) {
+        // it is an authentication problem, username and password are wrong.
+        // see HttpCredentials::slotAuthentication
+        _errors.append(tr("Authentication error: Either username or password are wrong."));
+    } else {
+        _errors.append( reply->errorString() );
+    }
     _errors.append(tr("Unable to connect to %1").arg(_account->url().toString()));
-    _errors.append( reply->errorString() );
     reportResult( StatusNotFound );
 }
 
diff --git a/src/libsync/creds/httpcredentials.cpp b/src/libsync/creds/httpcredentials.cpp
index 92ef227..0d20226 100644
--- a/src/libsync/creds/httpcredentials.cpp
+++ b/src/libsync/creds/httpcredentials.cpp
@@ -77,7 +77,6 @@ namespace
 const char userC[] = "user";
 const char certifPathC[] = "certificatePath";
 const char certifPasswdC[] = "certificatePasswd";
-const char authenticationFailedC[] = "owncloud-authentication-failed";
 } // ns
 
 class HttpCredentialsAccessManager : public AccessManager {
@@ -247,12 +246,12 @@ void HttpCredentials::fetch()
         _readPwdFromDeprecatedPlace = true;
     }
 }
+
 bool HttpCredentials::stillValid(QNetworkReply *reply)
 {
     return ((reply->error() != QNetworkReply::AuthenticationRequiredError)
             // returned if user or password is incorrect
-            && (reply->error() != QNetworkReply::OperationCanceledError
-                || !reply->property(authenticationFailedC).toBool()));
+            && !authenticationFailHappened(reply));
 }
 
 void HttpCredentials::slotReadJobDone(QKeychain::Job *job)
@@ -377,7 +376,7 @@ void HttpCredentials::slotAuthentication(QNetworkReply* reply, QAuthenticator* a
     // instead of utf8 encoding. Instead, we send it manually. Thus, if we reach this signal,
     // those credentials were invalid and we terminate.
     qDebug() << "Stop request: Authentication failed for " << reply->url().toString();
-    reply->setProperty(authenticationFailedC, true);
+    setAuthenticationFailed(reply);
     reply->close();
 }
 
diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp
index 3de56fc..49bbc10 100644
--- a/src/libsync/networkjobs.cpp
+++ b/src/libsync/networkjobs.cpp
@@ -40,7 +40,6 @@ Q_DECLARE_METATYPE(QTimer*)
 
 namespace OCC {
 
-
 AbstractNetworkJob::AbstractNetworkJob(AccountPtr account, const QString &path, QObject *parent)
     : QObject(parent)
     , _duration(0)
@@ -153,13 +152,15 @@ void AbstractNetworkJob::slotFinished()
 {
     _timer.stop();
 
-    if( _reply->error() == QNetworkReply::SslHandshakeFailedError ) {
+    QNetworkReply::NetworkError error = _reply->error();
+
+    if( error == QNetworkReply::SslHandshakeFailedError ) {
         qDebug() << "SslHandshakeFailedError: " << reply()->errorString() << " : can be caused by a webserver wanting SSL client certificates";
     }
     
-    if( _reply->error() != QNetworkReply::NoError ) {
-        qDebug() << Q_FUNC_INFO << _reply->error() << _reply->errorString();
-        if (_reply->error() == QNetworkReply::ProxyAuthenticationRequiredError) {
+    if( error != QNetworkReply::NoError ) {
+        qDebug() << Q_FUNC_INFO << error << _reply->errorString();
+        if (error == QNetworkReply::ProxyAuthenticationRequiredError) {
             qDebug() << Q_FUNC_INFO << _reply->rawHeader("Proxy-Authenticate");
         }
         emit networkError(_reply);
@@ -494,6 +495,20 @@ bool LsColJob::finished()
 namespace {
 const char statusphpC[] = "status.php";
 const char owncloudDirC[] = "owncloud/";
+const char authenticationFailedC[] = "owncloud-authentication-failed";
+}
+
+bool authenticationFailHappened( QNetworkReply *reply )
+{
+    return ( reply && reply->error() == QNetworkReply::OperationCanceledError &&
+             reply->property(authenticationFailedC).toBool() );
+}
+
+void setAuthenticationFailed( QNetworkReply *reply)
+{
+    if( reply ) {
+        reply->setProperty(authenticationFailedC, true);
+    }
 }
 
 CheckServerJob::CheckServerJob(AccountPtr account, QObject *parent)
diff --git a/src/libsync/networkjobs.h b/src/libsync/networkjobs.h
index 96cda0a..33c0def 100644
--- a/src/libsync/networkjobs.h
+++ b/src/libsync/networkjobs.h
@@ -32,7 +32,6 @@ namespace OCC {
 
 class AbstractSslErrorHandler;
 
-
 /**
  * @brief Internal Helper class
  */
@@ -44,6 +43,10 @@ private:
     QPointer<QTimer> _timer;
 };
 
+
+bool authenticationFailHappened( QNetworkReply *reply );
+void setAuthenticationFailed( QNetworkReply *reply);
+
 /**
  * @brief The AbstractNetworkJob class
  */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list