void XTelepathyPasswordAuthOperation::storeCredentials(const QString &secret)
{
    QString username = m_account->parameters().value(QStringLiteral("account")).toString();
    Accounts::Manager *manager = KAccounts::accountsManager();
    Accounts::Account *account = manager->account(m_accountStorageId);
    SignOn::Identity *identity;

    if (account) {
        Accounts::AccountService *service = new Accounts::AccountService(account, manager->service(QString()), this);
        Accounts::AuthData authData = service->authData();
        identity = SignOn::Identity::existingIdentity(authData.credentialsId(), this);
    } else {
        // there's no valid KAccounts account, so let's try creating one
        QString providerName = QStringLiteral("ktp-");

        providerName.append(m_account->serviceName());

        qDebug() << "Creating account with providerName" << providerName;

        account = manager->createAccount(providerName);
        account->setDisplayName(m_account->displayName());
        account->setValue("uid", m_account->objectPath());
        account->setValue("username", username);
        account->setValue(QStringLiteral("auth/mechanism"), QStringLiteral("password"));
        account->setValue(QStringLiteral("auth/method"), QStringLiteral("password"));

        account->setEnabled(true);

        Accounts::ServiceList services = account->services();
        Q_FOREACH(const Accounts::Service &service, services) {
            account->selectService(service);
            account->setEnabled(true);
        }
    }
Exemple #2
0
bool accountExists(){

    Accounts::Manager *manager;
    manager = new Accounts::Manager();
    Accounts::AccountIdList accl = manager->accountList();
    Accounts::Account *a;
    Accounts::ServiceList ss;
    for(int i =0; i<accl.length(); i++)
    {

        a = manager->account(accl[i]);
        ss = a->services();

        for (int j=0; j<ss.length(); j++){

            if(ss[j]->name()=="waxmpp"){

                if(a->valueAsString("imsi") == Utilities::getImsi()){
                    return true;
                }
            }
         }
     }
    return false;
}
Accounts::Account* AccountsModelPrivate::accountById(int id)
{
    if (m_accHash.contains(id)) {
        return m_accHash.value(id);
    }

    Accounts::Account* account = m_manager->account(id);
    if (!account) {
        qDebug() << "\t Failed to get the account from manager";
        return 0;
    }

    connect(account, SIGNAL(displayNameChanged(QString)), q, SLOT(accountUpdated()));

    m_accHash[id] = account;
    return account;
}