Don't logout on some server-side problems.

This commit is contained in:
John Preston 2018-05-13 11:42:25 +03:00
parent 7d8ba15252
commit 8764da787b
3 changed files with 36 additions and 17 deletions

View file

@ -304,7 +304,10 @@ base::Observable<void> &AuthSession::downloaderTaskFinished() {
}
bool AuthSession::validateSelf(const MTPUser &user) {
if (user.type() != mtpc_user || !user.c_user().is_self() || user.c_user().vid.v != userId()) {
if (user.type() != mtpc_user || !user.c_user().is_self()) {
LOG(("API Error: bad self user received."));
return false;
} else if (user.c_user().vid.v != userId()) {
LOG(("Auth Error: wrong self user received."));
App::logOutDelayed();
return false;
@ -314,6 +317,7 @@ bool AuthSession::validateSelf(const MTPUser &user) {
void AuthSession::saveSettingsDelayed(TimeMs delay) {
Expects(this == &Auth());
_saveDataTimer.callOnce(delay);
}

View file

@ -3717,8 +3717,11 @@ void MainWidget::start(const MTPUser *self) {
if (!self) {
MTP::send(MTPusers_GetFullUser(MTP_inputUserSelf()), rpcDone(&MainWidget::startWithSelf));
return;
}
if (!Auth().validateSelf(*self)) {
} else if (!Auth().validateSelf(*self)) {
constexpr auto kRequestUserAgainTimeout = TimeMs(10000);
App::CallDelayed(kRequestUserAgainTimeout, this, [=] {
MTP::send(MTPusers_GetFullUser(MTP_inputUserSelf()), rpcDone(&MainWidget::startWithSelf));
});
return;
}

View file

@ -942,10 +942,13 @@ void Instance::Private::importDone(const MTPauth_Authorization &result, mtpReque
const auto shiftedDcId = queryRequestByDc(requestId);
if (!shiftedDcId) {
LOG(("MTP Error: auth import request not found in requestsByDC, requestId: %1").arg(requestId));
RPCError error(internal::rpcClientError("AUTH_IMPORT_FAIL", QString("did not find import request in requestsByDC, request %1").arg(requestId)));
if (_globalHandler.onFail && hasAuthorization()) {
(*_globalHandler.onFail)(requestId, error); // auth failed in main dc
}
//
// Don't log out on export/import problems, perhaps this is a server side error.
//
//RPCError error(internal::rpcClientError("AUTH_IMPORT_FAIL", QString("did not find import request in requestsByDC, request %1").arg(requestId)));
//if (_globalHandler.onFail && hasAuthorization()) {
// (*_globalHandler.onFail)(requestId, error); // auth failed in main dc
//}
return;
}
auto newdc = bareDcId(*shiftedDcId);
@ -980,9 +983,12 @@ void Instance::Private::importDone(const MTPauth_Authorization &result, mtpReque
bool Instance::Private::importFail(const RPCError &error, mtpRequestId requestId) {
if (isDefaultHandledError(error)) return false;
if (_globalHandler.onFail && hasAuthorization()) {
(*_globalHandler.onFail)(requestId, error); // auth import failed
}
//
// Don't log out on export/import problems, perhaps this is a server side error.
//
//if (_globalHandler.onFail && hasAuthorization()) {
// (*_globalHandler.onFail)(requestId, error); // auth import failed
//}
return true;
}
@ -990,10 +996,13 @@ void Instance::Private::exportDone(const MTPauth_ExportedAuthorization &result,
auto it = _authExportRequests.find(requestId);
if (it == _authExportRequests.cend()) {
LOG(("MTP Error: auth export request target dcWithShift not found, requestId: %1").arg(requestId));
RPCError error(internal::rpcClientError("AUTH_IMPORT_FAIL", QString("did not find target dcWithShift, request %1").arg(requestId)));
if (_globalHandler.onFail && hasAuthorization()) {
(*_globalHandler.onFail)(requestId, error); // auth failed in main dc
}
//
// Don't log out on export/import problems, perhaps this is a server side error.
//
//RPCError error(internal::rpcClientError("AUTH_IMPORT_FAIL", QString("did not find target dcWithShift, request %1").arg(requestId)));
//if (_globalHandler.onFail && hasAuthorization()) {
// (*_globalHandler.onFail)(requestId, error); // auth failed in main dc
//}
return;
}
@ -1013,9 +1022,12 @@ bool Instance::Private::exportFail(const RPCError &error, mtpRequestId requestId
if (it != _authExportRequests.cend()) {
_authWaiters[bareDcId(it->second)].clear();
}
if (_globalHandler.onFail && hasAuthorization()) {
(*_globalHandler.onFail)(requestId, error); // auth failed in main dc
}
//
// Don't log out on export/import problems, perhaps this is a server side error.
//
//if (_globalHandler.onFail && hasAuthorization()) {
// (*_globalHandler.onFail)(requestId, error); // auth failed in main dc
//}
return true;
}