14
14
*/
15
15
16
16
#include " creds/httpcredentialsgui.h"
17
+
17
18
#include " account.h"
18
19
#include " application.h"
19
20
#include " basicloginwidget.h"
29
30
#include < QNetworkReply>
30
31
#include < QTimer>
31
32
33
+ namespace {
34
+ auto isOAuthC ()
35
+ {
36
+ return QStringLiteral (" oauth" );
37
+ }
38
+
39
+ const QString userC ()
40
+ {
41
+ return QStringLiteral (" user" );
42
+ }
43
+ }
44
+
32
45
33
46
namespace OCC {
34
47
35
48
Q_LOGGING_CATEGORY (lcHttpCredentialsGui, " sync.credentials.http.gui" , QtInfoMsg)
36
49
50
+ HttpCredentialsGui::HttpCredentialsGui (Account *account)
51
+ : HttpCredentials(account)
52
+ {
53
+ }
54
+
37
55
void HttpCredentialsGui::openBrowser ()
38
56
{
39
57
OC_ASSERT (isUsingOAuth ());
@@ -58,11 +76,13 @@ void HttpCredentialsGui::askFromUser()
58
76
59
77
void HttpCredentialsGui::askFromUserAsync ()
60
78
{
79
+ // TODO are we logged out
80
+ // _account
61
81
if (isUsingOAuth ()) {
62
82
restartOAuth ();
63
83
} else {
64
84
// First, we will check what kind of auth we need.
65
- auto job = new DetermineAuthTypeJob (_account ->sharedFromThis (), this );
85
+ auto job = new DetermineAuthTypeJob (account () ->sharedFromThis (), this );
66
86
QObject::connect (job, &DetermineAuthTypeJob::authType, this , [this ](DetermineAuthTypeJob::AuthType type) {
67
87
_authType = type;
68
88
if (type == DetermineAuthTypeJob::AuthType::OAuth) {
@@ -114,7 +134,7 @@ void HttpCredentialsGui::showDialog()
114
134
// make sure it's cleaned up since it's not owned by the account settings (also prevents memory leaks)
115
135
dialog->setAttribute (Qt::WA_DeleteOnClose);
116
136
117
- dialog->setTopLabelText (tr (" Please enter your password to log in to the account %1." ).arg (_account ->displayName ()));
137
+ dialog->setTopLabelText (tr (" Please enter your password to log in to the account %1." ).arg (account () ->displayName ()));
118
138
119
139
auto *contentWidget = qobject_cast<BasicLoginWidget *>(dialog->contentWidget ());
120
140
contentWidget->forceUsername (user ());
@@ -160,7 +180,7 @@ QUrl HttpCredentialsGui::authorisationLink() const
160
180
161
181
void HttpCredentialsGui::restartOAuth ()
162
182
{
163
- _asyncAuth.reset (new AccountBasedOAuth (_account ->sharedFromThis (), this ));
183
+ _asyncAuth.reset (new AccountBasedOAuth (account () ->sharedFromThis (), this ));
164
184
connect (_asyncAuth.data (), &OAuth::result,
165
185
this , &HttpCredentialsGui::asyncAuthResult);
166
186
connect (_asyncAuth.data (), &OAuth::destroyed,
@@ -169,4 +189,33 @@ void HttpCredentialsGui::restartOAuth()
169
189
emit authorisationLinkChanged ();
170
190
}
171
191
192
+ HttpCredentialsGui::HttpCredentialsGui (AccountState *accountState, const QString &loginUser, const QString &password)
193
+ : HttpCredentials(accountState->account ().get(), DetermineAuthTypeJob::AuthType::Basic, loginUser, password)
194
+ {
195
+ }
196
+
197
+ HttpCredentialsGui::HttpCredentialsGui (AccountState *accountState, const QString &davUser, const QString &password, const QString &refreshToken)
198
+ : HttpCredentials(accountState->account ().get(), DetermineAuthTypeJob::AuthType::OAuth, davUser, password)
199
+ {
200
+ _refreshToken = refreshToken;
201
+ }
202
+
203
+ HttpCredentialsGui *HttpCredentialsGui::fromSettings (AccountState *accountState)
204
+ {
205
+ auto *out = new HttpCredentialsGui (accountState->account ().get ());
206
+ out->_user = accountState->account ()->credentialSetting (out, userC ()).toString ();
207
+ Q_ASSERT (!out->_user .isEmpty ());
208
+
209
+ const auto isOauth = accountState->account ()->credentialSetting (out, isOAuthC ()).toBool ();
210
+ out->_authType = isOauth ? DetermineAuthTypeJob::AuthType::OAuth : DetermineAuthTypeJob::AuthType::Basic;
211
+
212
+ out->fetchFromKeychain ();
213
+ return out;
214
+ }
215
+ void HttpCredentialsGui::persist ()
216
+ {
217
+ account ()->setCredentialSetting (this , userC (), _user);
218
+ account ()->setCredentialSetting (this , isOAuthC (), isUsingOAuth ());
219
+ HttpCredentials::persist ();
220
+ }
172
221
} // namespace OCC
0 commit comments