~telepathy-kde/telepathy-kde/ktp-auth-handler

« back to all changes in this revision

Viewing changes to x-telepathy-password-auth-operation.cpp

  • Committer: David Edmundson
  • Date: 2012-08-09 19:23:23 UTC
  • Revision ID: kde@davidedmundson.co.uk-20120809192323-u48a6h5tzbyb7p1c
Updated to new WalletInterface

REVIEW:105899

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
XTelepathyPasswordAuthOperation::XTelepathyPasswordAuthOperation(
31
31
        const Tp::AccountPtr &account,
32
32
        Tp::Client::ChannelInterfaceSASLAuthenticationInterface *saslIface,
 
33
        KTp::WalletInterface *walletInterface,
33
34
        bool canTryAgain) :
34
35
    Tp::PendingOperation(account),
35
36
    m_account(account),
36
37
    m_saslIface(saslIface),
 
38
    m_walletInterface(walletInterface),
37
39
    m_canTryAgain(canTryAgain)
38
40
{
39
41
    connect(m_saslIface,
50
52
{
51
53
    if (status == Tp::SASLStatusNotStarted) {
52
54
        kDebug() << "Requesting password";
53
 
        promptUser(m_canTryAgain || !KTp::WalletInterface::hasEntry(m_account, QLatin1String("lastLoginFailed")));
 
55
        promptUser(m_canTryAgain || !m_walletInterface->hasEntry(m_account, QLatin1String("lastLoginFailed")));
54
56
    } else if (status == Tp::SASLStatusServerSucceeded) {
55
57
        kDebug() << "Authentication handshake";
56
58
        m_saslIface->AcceptSASL();
57
59
    } else if (status == Tp::SASLStatusSucceeded) {
58
60
        kDebug() << "Authentication succeeded";
59
 
        if (KTp::WalletInterface::hasEntry(m_account, QLatin1String("lastLoginFailed"))) {
60
 
            KTp::WalletInterface::removeEntry(m_account, QLatin1String("lastLoginFailed"));
 
61
        if (m_walletInterface->hasEntry(m_account, QLatin1String("lastLoginFailed"))) {
 
62
            m_walletInterface->removeEntry(m_account, QLatin1String("lastLoginFailed"));
61
63
        }
62
64
        setFinished();
63
65
    } else if (status == Tp::SASLStatusInProgress) {
70
72
            promptUser(false);
71
73
        } else {
72
74
            kWarning() << "Authentication failed and cannot try again";
73
 
            KTp::WalletInterface::setEntry(m_account, QLatin1String("lastLoginFailed"), QLatin1String("true"));
 
75
            m_walletInterface->setEntry(m_account, QLatin1String("lastLoginFailed"), QLatin1String("true"));
74
76
            // We cannot try again, but we can request again to set the account
75
77
            // online. A new channel will be created, but since we set the
76
78
            // lastLoginFailed entry, next time we will prompt for password
86
88
 
87
89
void XTelepathyPasswordAuthOperation::promptUser(bool isFirstRun)
88
90
{
89
 
    if (KTp::WalletInterface::hasPassword(m_account) && isFirstRun) {
 
91
    if (m_walletInterface->hasPassword(m_account) && isFirstRun) {
90
92
        m_saslIface->StartMechanismWithData(QLatin1String("X-TELEPATHY-PASSWORD"),
91
 
                                            KTp::WalletInterface::password(m_account).toUtf8());
 
93
                                            m_walletInterface->password(m_account).toUtf8());
92
94
    } else {
93
 
        m_dialog = new XTelepathyPasswordPrompt(m_account);
 
95
        m_dialog = new XTelepathyPasswordPrompt(m_account, m_walletInterface);
94
96
        connect(m_dialog.data(),
95
97
                SIGNAL(finished(int)),
96
98
                SLOT(onDialogFinished(int)));
114
116
        if (!m_dialog.isNull()) {
115
117
            if (m_dialog.data()->savePassword()) {
116
118
                kDebug() << "Saving password in wallet";
117
 
                KTp::WalletInterface::setPassword(m_account, m_dialog.data()->password());
 
119
                m_walletInterface->setPassword(m_account, m_dialog.data()->password());
118
120
            }
119
121
            m_saslIface->StartMechanismWithData(QLatin1String("X-TELEPATHY-PASSWORD"), m_dialog.data()->password().toUtf8());
120
122
            m_dialog.data()->deleteLater();