Skip to content

Commit

Permalink
Merge branch 'mer_server_url' into 'master'
Browse files Browse the repository at this point in the history
[buteo-sync-plugin-carddav] Improve Ubports and server url support. Contributes to JB#51505

See merge request mer-core/buteo-sync-plugin-carddav!21
  • Loading branch information
chriadam committed Oct 6, 2020
2 parents ee92a8c + ead1f4f commit 529c34e
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/auth.cpp
Expand Up @@ -22,6 +22,8 @@

#include "auth_p.h"
#include <LogMacros.h>
#include <QDir>
#include <QUrl>

#ifdef USE_SAILFISHKEYPROVIDER
#include <sailfishkeyprovider.h>
Expand Down Expand Up @@ -87,29 +89,48 @@ void Auth::signIn(int accountId)
}

// determine the remote URL from the account settings, and then sign in.
m_account->selectService(srv);
if (!m_account->enabled()) {
Accounts::AccountService globalSrv(m_account, Accounts::Service());
Accounts::AccountService accSrv(m_account, srv);
if (!accSrv.isEnabled()) {
LOG_WARNING("Service:" << srv.name() << "is not enabled for account:" << m_account->id());
emit signInError();
return;
}
m_ignoreSslErrors = m_account->value("ignore_ssl_errors").toBool();
m_serverUrl = m_account->value("server_address").toString();
m_addressbookPath = m_account->value("addressbook_path").toString(); // optional, may be empty.
m_ignoreSslErrors = accSrv.value("ignore_ssl_errors").toBool();
m_serverUrl = accSrv.value("server_address").toString();
if (m_serverUrl.isEmpty()) {
QUrl host(globalSrv.value("host").toString());
QString path = accSrv.value("server_path").toString();
if (!path.isEmpty()) {
if (path[0] != '/') {
/* If "server_path" holds a relative path, then let's assume
* it's relative to the host path. This nicely handles the case
* of NextCloud/OwnCloud installations: "host" defines the base
* URL, whereas "server_path" would be the subdirectory where
* the DAV stuff is located.
*/
path = QDir::cleanPath(host.path() + '/' + path);
}
host.setPath(path);
}
m_serverUrl = host.toString();
}

m_addressbookPath = accSrv.value("addressbook_path").toString(); // optional, may be empty.
if (m_serverUrl.isEmpty()) {
LOG_WARNING(Q_FUNC_INFO << "no valid server url setting in account" << accountId);
emit signInError();
return;
}

m_ident = m_account->credentialsId() > 0 ? SignOn::Identity::existingIdentity(m_account->credentialsId()) : 0;
m_ident = accSrv.authData().credentialsId() > 0 ?
SignOn::Identity::existingIdentity(accSrv.authData().credentialsId()) : 0;
if (!m_ident) {
LOG_WARNING(Q_FUNC_INFO << "no valid credentials for account" << accountId);
emit signInError();
return;
}

Accounts::AccountService accSrv(m_account, srv);
QString method = accSrv.authData().method();
QString mechanism = accSrv.authData().mechanism();
SignOn::AuthSession *session = m_ident->createSession(method);
Expand Down

0 comments on commit 529c34e

Please sign in to comment.