Skip to content
Snippets Groups Projects
Commit 87a901cb authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Sébastien Blin
Browse files

newaccountmodel: account creation


This patch fixes next problems:
-check profile type after adding account to accounts list and
updating account details. Otherwise profile type is always INVALID
-add option to create SIP account with URI, to avoid creating an entry
with empty uri in db
-do not save ring account with empty uri
-set account credentials before saving configuration to save a new
credentials in .yml

Gitlab: #402

Change-Id: I98b2f00d0f879930067bcbe2d305569d27ec90a2
Reviewed-by: default avatarSebastien Blin <sebastien.blin@savoirfairelinux.com>
parent 17bf71c3
Branches
Tags
No related merge requests found
/****************************************************************************
* Copyright (C) 2017-2018 Savoir-faire Linux *
* Copyright (C) 2017-2018 Savoir-faire Linux *
* Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> *
* Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> *
* Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
......@@ -155,13 +156,15 @@ public:
* @param archivePath
* @param password of the archive (unused for SIP)
* @param pin of the archive (unused for SIP)
* @param uri of the account (for SIP)
* @return the created account
*/
static std::string createNewAccount(profile::Type type,
const std::string& displayName = "",
const std::string& archivePath = "",
const std::string& password = "",
const std::string& pin = "");
const std::string& pin = "",
const std::string& uri = "");
/**
* Set an account to the first position
......
......@@ -2,6 +2,7 @@
* Copyright (C) 2017-2018 Savoir-faire Linux *
* Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> *
* Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> *
* Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
......@@ -199,7 +200,14 @@ NewAccountModel::setAccountConfig(const std::string& accountId,
details[ConfProperties::TYPE] = (accountInfo.profileInfo.type == profile::Type::RING) ? QString(ProtocolNames::RING) : QString(ProtocolNames::SIP);
if (accountInfo.profileInfo.type == profile::Type::RING) {
details[ConfProperties::USERNAME] = toQString(accountInfo.profileInfo.uri).prepend((accountInfo.profileInfo.type == profile::Type::RING) ? "ring:" : "");
} else {
} else if (accountInfo.profileInfo.type == profile::Type::SIP) {
MapStringString credentials;
credentials[ConfProperties::USERNAME] = toQString(confProperties.username);
credentials[ConfProperties::PASSWORD] = toQString(confProperties.password);
credentials[ConfProperties::REALM] = confProperties.realm.empty()? QString("*") : toQString(confProperties.realm);
QVector<MapStringString> credentialsVec;
credentialsVec.append(credentials);
ConfigurationManager::instance().setCredentials(accountId.c_str(), credentialsVec);
details[ConfProperties::USERNAME] = toQString(confProperties.username);
}
configurationManager.setAccountDetails(QString::fromStdString(accountId), details);
......@@ -373,7 +381,11 @@ NewAccountModelPimpl::updateAccounts()
if (accountInfo == accounts.end()) {
qDebug("detected new account %s", id.toStdString().c_str());
addToAccounts(id.toStdString());
if (accountInfo->second.profileInfo.type == profile::Type::SIP) {
auto updatedAccountInfo = accounts.find(id.toStdString());
if (updatedAccountInfo == accounts.end()) {
return;
}
if (updatedAccountInfo->second.profileInfo.type == profile::Type::SIP) {
// NOTE: At this point, a SIP account is ready, but not a Ring
// account. Indeed, the keys are not generated at this point.
// See slotAccountStatusChanged for more details.
......@@ -423,20 +435,6 @@ NewAccountModelPimpl::slotAccountDetailsChanged(const std::string& accountId, co
}
accountInfo->second.fromDetails(convertMap(details));
// Refresh credentials for SIP accounts
if (accountInfo->second.profileInfo.type == profile::Type::SIP) {
auto& confProperties = accountInfo->second.confProperties;
MapStringString credentials;
using namespace DRing::Account;
credentials[ConfProperties::USERNAME] = toQString(confProperties.username);
credentials[ConfProperties::PASSWORD] = toQString(confProperties.password);
credentials[ConfProperties::REALM] = confProperties.realm.empty()? QString("*") : toQString(confProperties.realm);
QVector<MapStringString> credentialsVec;
credentialsVec.append(credentials);
ConfigurationManager::instance().setCredentials(accountId.c_str(), credentialsVec);
}
emit linked.accountStatusChanged(accountId);
}
......@@ -542,14 +540,16 @@ NewAccountModelPimpl::addToAccounts(const std::string& accountId)
std::string accountType = newAcc.profileInfo.type == profile::Type::RING ?
DRing::Account::ProtocolNames::RING :
DRing::Account::ProtocolNames::SIP;
auto accountProfileId = authority::database::getOrInsertProfile(database,
if (accountType == DRing::Account::ProtocolNames::SIP || !newAcc.profileInfo.uri.empty()) {
auto accountProfileId = authority::database::getOrInsertProfile(database,
newAcc.profileInfo.uri,
newAcc.profileInfo.alias,
"",
accountType);
// Retrieve avatar from database
newAcc.profileInfo.avatar = authority::database::getAvatarForProfileId(database, accountProfileId);
// Retrieve avatar from database
newAcc.profileInfo.avatar = authority::database::getAvatarForProfileId(database, accountProfileId);
}
// Init models for this account
newAcc.callModel = std::make_unique<NewCallModel>(newAcc, callbacksHandler);
......@@ -811,7 +811,8 @@ NewAccountModel::createNewAccount(profile::Type type,
const std::string& displayName,
const std::string& archivePath,
const std::string& password,
const std::string& pin)
const std::string& pin,
const std::string& uri)
{
MapStringString details = type == profile::Type::SIP?
......@@ -825,6 +826,9 @@ NewAccountModel::createNewAccount(profile::Type type,
details[ConfProperties::ARCHIVE_PASSWORD] = password.c_str();
details[ConfProperties::ARCHIVE_PIN] = pin.c_str();
details[ConfProperties::ARCHIVE_PATH] = archivePath.c_str();
if (type == profile::Type::SIP) {
details[ConfProperties::USERNAME] = uri.c_str();
}
QString accountId = ConfigurationManager::instance().addAccount(details);
return accountId.toStdString();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment