Commit 44d9b91d authored by Thomas Greenwood's avatar Thomas Greenwood
Browse files

Use QUrlQuery to process login credentials

parent c0953e85
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QUrlQuery>
#include <kio/global.h> #include <kio/global.h>
#include "../cloudurls.h" #include "../cloudurls.h"
...@@ -101,19 +102,14 @@ void NextcloudController::wrongUrlDetected() ...@@ -101,19 +102,14 @@ void NextcloudController::wrongUrlDetected()
void NextcloudController::finalUrlHandler(const QUrl &url) void NextcloudController::finalUrlHandler(const QUrl &url)
{ {
// To fetch m_username and m_password from final url // url is of the form: nc://login/server:<server>&user:<loginname>&password:<password>
QString finalURLtoString = url.toString();
int username_ini_pos = finalURLtoString.indexOf(QLatin1String("&user:")) + 6; QUrlQuery urlQuery;
int password_ini_pos = finalURLtoString.indexOf(QLatin1String("&password:")) + 10; urlQuery.setQueryDelimiters(QLatin1Char(':'),QLatin1Char('&'));
int username_size = password_ini_pos - username_ini_pos - 10; urlQuery.setQuery(url.path(QUrl::FullyEncoded).mid(1));
QString username = finalURLtoString.mid(username_ini_pos, username_size);
QString password = finalURLtoString.mid(password_ini_pos); m_username = urlQuery.queryItemValue(QStringLiteral("user"),QUrl::FullyDecoded);
// To replace %40 with @ m_password = urlQuery.queryItemValue(QStringLiteral("password"),QUrl::FullyDecoded);
int position = username.indexOf(QLatin1String("%40"));
username.replace(position, 3, QStringLiteral("@"));
m_username = username;
m_password = password;
serverCheckResult(); serverCheckResult();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment