Changeset View
Changeset View
Standalone View
Standalone View
providers/ghprovider/ghdialog.cpp
Show All 16 Lines | |||||
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 <QPointer> | 24 | #include <QPointer> | ||
25 | #include <QInputDialog> | ||||
25 | 26 | | |||
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> | ||
32 | #include <ghresource.h> | 33 | #include <ghresource.h> | ||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 108 | { | |||
109 | dlg->setPrompt(i18n("Enter a login and a password")); | 110 | dlg->setPrompt(i18n("Enter a login and a password")); | ||
110 | if(dlg->exec()) { | 111 | if(dlg->exec()) { | ||
111 | m_text->setAlignment(Qt::AlignCenter); | 112 | m_text->setAlignment(Qt::AlignCenter); | ||
112 | m_text->setText(i18n("Waiting for response")); | 113 | m_text->setText(i18n("Waiting for response")); | ||
113 | m_account->setName(dlg->username()); | 114 | m_account->setName(dlg->username()); | ||
114 | 115 | | |||
115 | Resource *rs = m_account->resource(); | 116 | Resource *rs = m_account->resource(); | ||
116 | rs->authenticate(dlg->username(), dlg->password()); | 117 | rs->authenticate(dlg->username(), dlg->password()); | ||
118 | connect(rs, &Resource::twoFactorAuthRequested, | ||||
119 | this, &Dialog::twoFactorResponse); | ||||
117 | connect(rs, &Resource::authenticated, | 120 | connect(rs, &Resource::authenticated, | ||
118 | this, &Dialog::authorizeResponse); | 121 | this, &Dialog::authorizeResponse); | ||
119 | } | 122 | } | ||
120 | delete dlg; | 123 | delete dlg; | ||
121 | } | 124 | } | ||
122 | 125 | | |||
123 | void Dialog::authorizeResponse(const QByteArray &id, const QByteArray &token, const QString &tokenName) | 126 | void Dialog::authorizeResponse(const QByteArray &id, const QByteArray &token, const QString &tokenName) | ||
124 | { | 127 | { | ||
Show All 18 Lines | 145 | KMessageBox::information(this, i18n("Authentication succeeded.\n\n" | |||
143 | "Created token: \"%1\"\n%2", tokenName, | 146 | "Created token: \"%1\"\n%2", tokenName, | ||
144 | tokenLinkStatementText()), | 147 | tokenLinkStatementText()), | ||
145 | i18n("GitHub Account Authorized")); | 148 | i18n("GitHub Account Authorized")); | ||
146 | } | 149 | } | ||
147 | m_account->saveToken(id, token); | 150 | m_account->saveToken(id, token); | ||
148 | syncUser(); | 151 | syncUser(); | ||
149 | } | 152 | } | ||
150 | 153 | | |||
154 | void Dialog::twoFactorResponse(const QString &transferHeader) | ||||
155 | { | ||||
156 | auto code = QInputDialog::getText(this, i18n("Authentication Code"), i18n("OTP Code")); | ||||
157 | Resource* rs = m_account->resource(); | ||||
mwolff: rs -> resource | |||||
zhigalin: It's called `rs` everywhere... | |||||
158 | disconnect(rs, &Resource::twoFactorAuthRequested, | ||||
159 | this, &Dialog::twoFactorResponse); | ||||
160 | rs->twoFactorAuthenticate(transferHeader, code); | ||||
161 | } | ||||
162 | | ||||
151 | void Dialog::syncUser() | 163 | void Dialog::syncUser() | ||
152 | { | 164 | { | ||
153 | Resource *rs = m_account->resource(); | 165 | Resource *rs = m_account->resource(); | ||
154 | connect(rs, &Resource::orgsUpdated, | 166 | connect(rs, &Resource::orgsUpdated, | ||
155 | this, &Dialog::updateOrgs); | 167 | this, &Dialog::updateOrgs); | ||
156 | m_text->setAlignment(Qt::AlignCenter); | 168 | m_text->setAlignment(Qt::AlignCenter); | ||
157 | m_text->setText(i18n("Waiting for response")); | 169 | m_text->setText(i18n("Waiting for response")); | ||
158 | rs->getOrgs(m_account->token()); | 170 | rs->getOrgs(m_account->token()); | ||
Show All 27 Lines |
rs -> resource