Changeset View
Changeset View
Standalone View
Standalone View
providers/ghprovider/ghdialog.cpp
Show All 15 Lines | |||||
16 | * with this program; if not, write to the Free Software Foundation, Inc., | 16 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include <QLabel> | 20 | #include <QLabel> | ||
21 | #include <QDialogButtonBox> | 21 | #include <QDialogButtonBox> | ||
22 | #include <QPushButton> | 22 | #include <QPushButton> | ||
23 | #include <QVBoxLayout> | 23 | #include <QVBoxLayout> | ||
24 | #include <QInputDialog> | ||||
24 | 25 | | |||
25 | #include <KConfigGroup> | 26 | #include <KConfigGroup> | ||
26 | #include <KLocalizedString> | 27 | #include <KLocalizedString> | ||
27 | #include <KMessageBox> | 28 | #include <KMessageBox> | ||
28 | #include <KPasswordDialog> | 29 | #include <KPasswordDialog> | ||
29 | 30 | | |||
30 | #include <ghdialog.h> | 31 | #include <ghdialog.h> | ||
31 | #include <ghaccount.h> | 32 | #include <ghaccount.h> | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 103 | if(!dlg.exec()) | |||
103 | return; | 104 | return; | ||
104 | 105 | | |||
105 | m_text->setAlignment(Qt::AlignCenter); | 106 | m_text->setAlignment(Qt::AlignCenter); | ||
106 | m_text->setText(i18n("Waiting for response")); | 107 | m_text->setText(i18n("Waiting for response")); | ||
107 | m_account->setName(dlg.username()); | 108 | m_account->setName(dlg.username()); | ||
108 | 109 | | |||
109 | Resource *rs = m_account->resource(); | 110 | Resource *rs = m_account->resource(); | ||
110 | rs->authenticate(dlg.username(), dlg.password()); | 111 | rs->authenticate(dlg.username(), dlg.password()); | ||
112 | connect(rs, &Resource::twoFactorRequested, | ||||
113 | this, &Dialog::twoFactorResponse); | ||||
111 | connect(rs, &Resource::authenticated, | 114 | connect(rs, &Resource::authenticated, | ||
112 | this, &Dialog::authorizeResponse); | 115 | this, &Dialog::authorizeResponse); | ||
113 | } | 116 | } | ||
114 | 117 | | |||
115 | void Dialog::authorizeResponse(const QByteArray &id, const QByteArray &token) | 118 | void Dialog::authorizeResponse(const QByteArray &id, const QByteArray &token) | ||
116 | { | 119 | { | ||
117 | Resource *rs = m_account->resource(); | 120 | Resource *rs = m_account->resource(); | ||
118 | disconnect(rs, &Resource::authenticated, | 121 | disconnect(rs, &Resource::authenticated, | ||
119 | this, &Dialog::authorizeResponse); | 122 | this, &Dialog::authorizeResponse); | ||
120 | 123 | | |||
121 | if (id.isEmpty()) { | 124 | if (id.isEmpty()) { | ||
122 | m_text->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); | 125 | m_text->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); | ||
123 | m_text->setText(i18n(INVALID_ACCOUNT)); | 126 | m_text->setText(i18n(INVALID_ACCOUNT)); | ||
124 | m_account->setName(QString()); | 127 | m_account->setName(QString()); | ||
125 | KMessageBox::sorry(this, i18n("Authentication failed! Please, " | 128 | KMessageBox::sorry(this, i18n("Authentication failed! Please, " | ||
126 | "try again")); | 129 | "try again")); | ||
127 | return; | 130 | return; | ||
128 | } | 131 | } | ||
129 | 132 | | |||
130 | m_account->saveToken(id, token); | 133 | m_account->saveToken(id, token); | ||
131 | syncUser(); | 134 | syncUser(); | ||
132 | } | 135 | } | ||
133 | 136 | | |||
137 | void Dialog::twoFactorResponse() | ||||
138 | { | ||||
139 | auto code = QInputDialog::getText(this, i18n("Authentication Code"), i18n("Authentication Code")); | ||||
140 | Resource* rs = m_account->resource(); | ||||
mwolff: rs -> resource | |||||
zhigalin: It's called `rs` everywhere... | |||||
141 | disconnect(rs, &Resource::twoFactorRequested, this, &Dialog::twoFactorResponse); | ||||
142 | | ||||
143 | rs->twoFactorAuthenticate(code); | ||||
144 | } | ||||
145 | | ||||
134 | void Dialog::syncUser() | 146 | void Dialog::syncUser() | ||
135 | { | 147 | { | ||
136 | Resource *rs = m_account->resource(); | 148 | Resource *rs = m_account->resource(); | ||
137 | connect(rs, &Resource::orgsUpdated, | 149 | connect(rs, &Resource::orgsUpdated, | ||
138 | this, &Dialog::updateOrgs); | 150 | this, &Dialog::updateOrgs); | ||
139 | m_text->setAlignment(Qt::AlignCenter); | 151 | m_text->setAlignment(Qt::AlignCenter); | ||
140 | m_text->setText(i18n("Waiting for response")); | 152 | m_text->setText(i18n("Waiting for response")); | ||
141 | rs->getOrgs(m_account->token()); | 153 | rs->getOrgs(m_account->token()); | ||
Show All 26 Lines |
rs -> resource