Commit 66429f47 authored by Shashwat Jolly's avatar Shashwat Jolly
Browse files

Add account status check while logging in

login() will pass even if email if not confirmed, there are problems with billing etc.
So, we need to make a small fetch (collection lise with limit 1) to check if the account status is fine.
parent 338aa080
......@@ -97,14 +97,34 @@ bool EteSyncClientState::login(const QString &serverUrl, const QString &username
return true;
}
bool EteSyncClientState::accountStatus()
{
if (!mAccountXXX) {
qCDebug(ETESYNC_LOG) << "Could not fetch collection list with limit 1";
qCDebug(ETESYNC_LOG) << "Etebase account is null";
return false;
}
EtebaseCollectionManagerPtr collectionManager(etebase_account_get_collection_manager(mAccountXXX.get()));
EtebaseFetchOptionsPtr fetchOptions(etebase_fetch_options_new());
etebase_fetch_options_set_limit(fetchOptions.get(), 1);
EtebaseCollectionListResponsePtr collectionList(etebase_collection_manager_list(collectionManager.get(), fetchOptions.get()));
if (!collectionList) {
qCDebug(ETESYNC_LOG) << "Could not fetch collection list with limit 1";
qCDebug(ETESYNC_LOG) << "Etebase error" << etebase_error_get_message();
return false;
}
return true;
}
void EteSyncClientState::refreshToken()
{
qCDebug(ETESYNC_LOG) << "Refreshing token";
if (initToken(mServerUrl, mUsername, mPassword)) {
tokenRefreshed(true);
if (etebase_account_fetch_token(mAccountXXX.get())) {
tokenRefreshed(false);
return;
}
tokenRefreshed(false);
tokenRefreshed(true);
return;
}
......
......@@ -27,6 +27,7 @@ public:
void invalidateToken();
void refreshUserInfo();
bool login(const QString &serverUrl, const QString &username, const QString &password);
bool accountStatus();
EteSync *client() const
{
......
......@@ -43,4 +43,12 @@ void LoginJob::login()
const char *err = etebase_error_get_message();
setErrorText(QString::fromUtf8(err));
}
mAccountStatusResult = mClientState->accountStatus();
qCDebug(ETESYNC_LOG) << "Account status result" << mAccountStatusResult;
if (!mAccountStatusResult) {
qCDebug(ETESYNC_LOG) << "Returning error from LoginJob";
setError(etebase_error_get_code());
const char *err = etebase_error_get_message();
setErrorText(QString::fromUtf8(err));
}
}
......@@ -28,6 +28,11 @@ public:
return mLoginResult;
}
bool getAccountStatusResult() const
{
return mAccountStatusResult;
}
private:
void login();
......@@ -36,6 +41,7 @@ private:
QString mUsername;
QString mPassword;
bool mLoginResult;
bool mAccountStatusResult;
bool mUserInfoResult;
};
} // namespace EteSyncAPI
......
......@@ -47,6 +47,7 @@ void SetupWizard::manualNext()
connect(job, &LoginJob::finished, this, [this](KJob *job) {
qCDebug(ETESYNC_LOG) << "Login finished";
static_cast<LoginPage *>(page(W_LoginPage))->setLoginResult(static_cast<LoginJob *>(job)->getLoginResult());
static_cast<LoginPage *>(page(W_LoginPage))->setAccountStatusResult(static_cast<LoginJob *>(job)->getAccountStatusResult());
static_cast<LoginPage *>(page(W_LoginPage))->setErrorCode(job->error());
static_cast<LoginPage *>(page(W_LoginPage))->setErrorMessage(job->errorText());
static_cast<LoginPage *>(page(W_LoginPage))->hideProgressBar();
......@@ -129,6 +130,10 @@ bool LoginPage::validatePage()
}
return false;
}
if (!mAccountStatusResult) {
qCDebug(ETESYNC_LOG) << "accountStatus error" << mErrorCode;
mLoginLabel->setText(i18n(charArrFromQString(mErrorMessage)));
return false;
}
return true;
}
......@@ -60,6 +60,11 @@ public:
mLoginResult = loginResult;
}
void setAccountStatusResult(bool accountStatusResult)
{
mAccountStatusResult = accountStatusResult;
}
void setErrorCode(int errorCode)
{
mErrorCode = errorCode;
......@@ -79,6 +84,7 @@ private:
QProgressBar *mProgressBar;
bool mIsInitialized = false;
bool mLoginResult = false;
bool mAccountStatusResult = false;
int mErrorCode;
QString mErrorMessage;
};
......
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