Commit 81fe5599 authored by Krzysztof Nowicki's avatar Krzysztof Nowicki
Browse files

Save OAuth2 settings and retrieved tokens upon config dialog exit

parent 8edc86eb
...@@ -208,7 +208,16 @@ void EwsConfigDialog::save() ...@@ -208,7 +208,16 @@ void EwsConfigDialog::save()
mSettings->setUserAgent(QString()); mSettings->setUserAgent(QString());
} }
mSettings->setPassword(mUi->passwordEdit->password()); if (mUi->authUsernameRadioButton->isChecked()) {
mSettings->setPassword(mUi->passwordEdit->password());
mSettings->setAuthMode(QStringLiteral("username-password"));
}
#ifdef HAVE_NETWORKAUTH
if (mUi->authOAuth2RadioButton->isChecked()) {
mSettings->setTokens(mAccessToken, mRefreshToken);
mSettings->setAuthMode(QStringLiteral("oauth2"));
}
#endif
mSettings->save(); mSettings->save();
} }
...@@ -323,7 +332,16 @@ void EwsConfigDialog::dialogAccepted() ...@@ -323,7 +332,16 @@ void EwsConfigDialog::dialogAccepted()
if (mTryConnectNeeded) { if (mTryConnectNeeded) {
EwsClient cli; EwsClient cli;
cli.setUrl(mUi->kcfg_BaseUrl->text()); cli.setUrl(mUi->kcfg_BaseUrl->text());
cli.setCredentials(fullUsername(), mUi->passwordEdit->password()); #ifdef HAVE_NETWORKAUTH
if (mUi->authOAuth2RadioButton->isChecked()) {
cli.setOAuthData(mUi->kcfg_Email->text(), mSettings->oAuth2AppId(), mSettings->oAuth2ReturnUri());
cli.setOAuthTokens(mAccessToken, mRefreshToken);
connect(&cli, &EwsClient::oAuthTokensChanged, this, &EwsConfigDialog::tokensRequestFinished);
} else
#endif
if (mUi->authUsernameRadioButton->isChecked()) {
cli.setCredentials(fullUsername(), mUi->passwordEdit->password());
}
if (mUi->userAgentGroupBox->isChecked()) { if (mUi->userAgentGroupBox->isChecked()) {
cli.setUserAgent(mUi->userAgentEdit->text()); cli.setUserAgent(mUi->userAgentEdit->text());
} }
...@@ -334,12 +352,15 @@ void EwsConfigDialog::dialogAccepted() ...@@ -334,12 +352,15 @@ void EwsConfigDialog::dialogAccepted()
connect(mTryConnectJob, &EwsGetFolderRequest::result, this, &EwsConfigDialog::tryConnectFinished); connect(mTryConnectJob, &EwsGetFolderRequest::result, this, &EwsConfigDialog::tryConnectFinished);
mProgressDialog = new EwsProgressDialog(this, EwsProgressDialog::TryConnect); mProgressDialog = new EwsProgressDialog(this, EwsProgressDialog::TryConnect);
connect(mProgressDialog, &QDialog::rejected, this, &EwsConfigDialog::tryConnectCancelled); connect(mProgressDialog, &QDialog::rejected, this, &EwsConfigDialog::tryConnectCancelled);
mTryConnectJob->setParentWindow(mProgressDialog);
mTryConnectJob->start(); mTryConnectJob->start();
if (!mProgressDialog->exec()) { if (!execJob(mTryConnectJob)) {
if (KMessageBox::questionYesNo(this, if (!mTryConnectJobCancelled) {
i18n("Connecting to Exchange failed. This can be caused by incorrect parameters. Do you still want to save your settings?"), if (KMessageBox::questionYesNo(this,
i18n("Exchange server connection")) == KMessageBox::Yes) { i18n("Connecting to Exchange failed. This can be caused by incorrect parameters. Do you still want to save your settings?"),
accept(); i18n("Exchange server connection")) == KMessageBox::Yes) {
accept();
}
} }
return; return;
} else { } else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment