mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 23:24:01 +02:00
Moved out mtp fields from CloudPasswordState to nested struct.
This commit is contained in:
parent
77d50d9177
commit
627170520a
8 changed files with 65 additions and 30 deletions
|
@ -154,9 +154,9 @@ void StartPendingReset(
|
||||||
PasscodeBox::CloudFields PasscodeBox::CloudFields::From(
|
PasscodeBox::CloudFields PasscodeBox::CloudFields::From(
|
||||||
const Core::CloudPasswordState ¤t) {
|
const Core::CloudPasswordState ¤t) {
|
||||||
auto result = CloudFields();
|
auto result = CloudFields();
|
||||||
result.curRequest = current.request;
|
result.curRequest = current.mtp.request;
|
||||||
result.newAlgo = current.newPassword;
|
result.newAlgo = current.mtp.newPassword;
|
||||||
result.newSecureSecretAlgo = current.newSecureSecret;
|
result.newSecureSecretAlgo = current.mtp.newSecureSecret;
|
||||||
result.hasRecovery = current.hasRecovery;
|
result.hasRecovery = current.hasRecovery;
|
||||||
result.notEmptyPassport = current.notEmptyPassport;
|
result.notEmptyPassport = current.notEmptyPassport;
|
||||||
result.hint = current.hint;
|
result.hint = current.hint;
|
||||||
|
|
|
@ -303,18 +303,53 @@ bytes::vector ComputeSecureSecretHash(
|
||||||
CloudPasswordState ParseCloudPasswordState(
|
CloudPasswordState ParseCloudPasswordState(
|
||||||
const MTPDaccount_password &data) {
|
const MTPDaccount_password &data) {
|
||||||
auto result = CloudPasswordState();
|
auto result = CloudPasswordState();
|
||||||
result.request = ParseCloudPasswordCheckRequest(data);
|
result.mtp.request = ParseCloudPasswordCheckRequest(data);
|
||||||
result.unknownAlgorithm = data.vcurrent_algo() && !result.request;
|
result.hasPassword = (!!result.mtp.request);
|
||||||
|
result.mtp.unknownAlgorithm = data.vcurrent_algo() && !result.hasPassword;
|
||||||
result.hasRecovery = data.is_has_recovery();
|
result.hasRecovery = data.is_has_recovery();
|
||||||
result.notEmptyPassport = data.is_has_secure_values();
|
result.notEmptyPassport = data.is_has_secure_values();
|
||||||
result.hint = qs(data.vhint().value_or_empty());
|
result.hint = qs(data.vhint().value_or_empty());
|
||||||
result.newPassword = ValidateNewCloudPasswordAlgo(
|
result.mtp.newPassword = ValidateNewCloudPasswordAlgo(
|
||||||
ParseCloudPasswordAlgo(data.vnew_algo()));
|
ParseCloudPasswordAlgo(data.vnew_algo()));
|
||||||
result.newSecureSecret = ValidateNewSecureSecretAlgo(
|
result.mtp.newSecureSecret = ValidateNewSecureSecretAlgo(
|
||||||
ParseSecureSecretAlgo(data.vnew_secure_algo()));
|
ParseSecureSecretAlgo(data.vnew_secure_algo()));
|
||||||
result.unconfirmedPattern =
|
result.unconfirmedPattern =
|
||||||
qs(data.vemail_unconfirmed_pattern().value_or_empty());
|
qs(data.vemail_unconfirmed_pattern().value_or_empty());
|
||||||
result.pendingResetDate = data.vpending_reset_date().value_or_empty();
|
result.pendingResetDate = data.vpending_reset_date().value_or_empty();
|
||||||
|
|
||||||
|
result.outdatedClient = [&] {
|
||||||
|
const auto badSecureAlgo = data.vnew_secure_algo().match([](
|
||||||
|
const MTPDsecurePasswordKdfAlgoUnknown &) {
|
||||||
|
return true;
|
||||||
|
}, [](const auto &) {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
if (badSecureAlgo) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (data.vcurrent_algo()) {
|
||||||
|
const auto badCurrentAlgo = data.vcurrent_algo()->match([](
|
||||||
|
const MTPDpasswordKdfAlgoUnknown &) {
|
||||||
|
return true;
|
||||||
|
}, [](const auto &) {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
if (badCurrentAlgo) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const auto badNewAlgo = data.vnew_algo().match([](
|
||||||
|
const MTPDpasswordKdfAlgoUnknown &) {
|
||||||
|
return true;
|
||||||
|
}, [](const auto &) {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
if (badNewAlgo) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,13 +122,18 @@ bytes::vector ComputeSecureSecretHash(
|
||||||
bytes::const_span password);
|
bytes::const_span password);
|
||||||
|
|
||||||
struct CloudPasswordState {
|
struct CloudPasswordState {
|
||||||
|
struct Mtp {
|
||||||
CloudPasswordCheckRequest request;
|
CloudPasswordCheckRequest request;
|
||||||
bool unknownAlgorithm = false;
|
bool unknownAlgorithm = false;
|
||||||
bool hasRecovery = false;
|
|
||||||
bool notEmptyPassport = false;
|
|
||||||
QString hint;
|
|
||||||
CloudPasswordAlgo newPassword;
|
CloudPasswordAlgo newPassword;
|
||||||
SecureSecretAlgo newSecureSecret;
|
SecureSecretAlgo newSecureSecret;
|
||||||
|
};
|
||||||
|
Mtp mtp;
|
||||||
|
bool hasPassword = false;
|
||||||
|
bool hasRecovery = false;
|
||||||
|
bool notEmptyPassport = false;
|
||||||
|
bool outdatedClient = false;
|
||||||
|
QString hint;
|
||||||
QString unconfirmedPattern;
|
QString unconfirmedPattern;
|
||||||
TimeId pendingResetDate = 0;
|
TimeId pendingResetDate = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -346,7 +346,7 @@ void CodeWidget::gotPassword(const MTPaccount_Password &result) {
|
||||||
LOG(("API Error: No current password received on login."));
|
LOG(("API Error: No current password received on login."));
|
||||||
_code->setFocus();
|
_code->setFocus();
|
||||||
return;
|
return;
|
||||||
} else if (!getData()->pwdState.request) {
|
} else if (!getData()->pwdState.hasPassword) {
|
||||||
const auto callback = [=](Fn<void()> &&close) {
|
const auto callback = [=](Fn<void()> &&close) {
|
||||||
Core::UpdateApplication();
|
Core::UpdateApplication();
|
||||||
close();
|
close();
|
||||||
|
|
|
@ -36,7 +36,7 @@ PasswordCheckWidget::PasswordCheckWidget(
|
||||||
, _codeField(this, st::introPassword, tr::lng_signin_code())
|
, _codeField(this, st::introPassword, tr::lng_signin_code())
|
||||||
, _toRecover(this, tr::lng_signin_recover(tr::now))
|
, _toRecover(this, tr::lng_signin_recover(tr::now))
|
||||||
, _toPassword(this, tr::lng_signin_try_password(tr::now)) {
|
, _toPassword(this, tr::lng_signin_try_password(tr::now)) {
|
||||||
Expects(!!_passwordState.request);
|
Expects(_passwordState.hasPassword);
|
||||||
|
|
||||||
Lang::Updated(
|
Lang::Updated(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
|
@ -169,7 +169,7 @@ void PasswordCheckWidget::handleSrpIdInvalid() {
|
||||||
const auto now = crl::now();
|
const auto now = crl::now();
|
||||||
if (_lastSrpIdInvalidTime > 0
|
if (_lastSrpIdInvalidTime > 0
|
||||||
&& now - _lastSrpIdInvalidTime < Core::kHandleSrpIdInvalidTimeout) {
|
&& now - _lastSrpIdInvalidTime < Core::kHandleSrpIdInvalidTimeout) {
|
||||||
_passwordState.request.id = 0;
|
_passwordState.mtp.request.id = 0;
|
||||||
showError(rpl::single(Lang::Hard::ServerError()));
|
showError(rpl::single(Lang::Hard::ServerError()));
|
||||||
} else {
|
} else {
|
||||||
_lastSrpIdInvalidTime = now;
|
_lastSrpIdInvalidTime = now;
|
||||||
|
@ -178,7 +178,7 @@ void PasswordCheckWidget::handleSrpIdInvalid() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PasswordCheckWidget::checkPasswordHash() {
|
void PasswordCheckWidget::checkPasswordHash() {
|
||||||
if (_passwordState.request.id) {
|
if (_passwordState.mtp.request.id) {
|
||||||
passwordChecked();
|
passwordChecked();
|
||||||
} else {
|
} else {
|
||||||
requestPasswordData();
|
requestPasswordData();
|
||||||
|
@ -201,12 +201,12 @@ void PasswordCheckWidget::requestPasswordData() {
|
||||||
|
|
||||||
void PasswordCheckWidget::passwordChecked() {
|
void PasswordCheckWidget::passwordChecked() {
|
||||||
const auto check = Core::ComputeCloudPasswordCheck(
|
const auto check = Core::ComputeCloudPasswordCheck(
|
||||||
_passwordState.request,
|
_passwordState.mtp.request,
|
||||||
_passwordHash);
|
_passwordHash);
|
||||||
if (!check) {
|
if (!check) {
|
||||||
return serverError();
|
return serverError();
|
||||||
}
|
}
|
||||||
_passwordState.request.id = 0;
|
_passwordState.mtp.request.id = 0;
|
||||||
_sentRequest = api().request(
|
_sentRequest = api().request(
|
||||||
MTPauth_CheckPassword(check.result)
|
MTPauth_CheckPassword(check.result)
|
||||||
).done([=](const MTPauth_Authorization &result) {
|
).done([=](const MTPauth_Authorization &result) {
|
||||||
|
@ -391,7 +391,7 @@ void PasswordCheckWidget::submit() {
|
||||||
|
|
||||||
const auto password = _pwdField->getLastText().toUtf8();
|
const auto password = _pwdField->getLastText().toUtf8();
|
||||||
_passwordHash = Core::ComputeCloudPasswordHash(
|
_passwordHash = Core::ComputeCloudPasswordHash(
|
||||||
_passwordState.request.algo,
|
_passwordState.mtp.request.algo,
|
||||||
bytes::make_span(password));
|
bytes::make_span(password));
|
||||||
checkPasswordHash();
|
checkPasswordHash();
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,7 +394,7 @@ void QrWidget::sendCheckPasswordRequest() {
|
||||||
LOG(("API Error: No current password received on login."));
|
LOG(("API Error: No current password received on login."));
|
||||||
goReplace<QrWidget>(Animate::Forward);
|
goReplace<QrWidget>(Animate::Forward);
|
||||||
return;
|
return;
|
||||||
} else if (!getData()->pwdState.request) {
|
} else if (!getData()->pwdState.hasPassword) {
|
||||||
const auto callback = [=](Fn<void()> &&close) {
|
const auto callback = [=](Fn<void()> &&close) {
|
||||||
Core::UpdateApplication();
|
Core::UpdateApplication();
|
||||||
close();
|
close();
|
||||||
|
|
|
@ -177,7 +177,7 @@ CheckoutProcess::CheckoutProcess(
|
||||||
if (mode == Mode::Payment) {
|
if (mode == Mode::Payment) {
|
||||||
_session->api().cloudPassword().state(
|
_session->api().cloudPassword().state(
|
||||||
) | rpl::start_with_next([=](const Core::CloudPasswordState &state) {
|
) | rpl::start_with_next([=](const Core::CloudPasswordState &state) {
|
||||||
_form->setHasPassword(!!state.request);
|
_form->setHasPassword(state.hasPassword);
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -624,7 +624,7 @@ void CheckoutProcess::requestPassword() {
|
||||||
|
|
||||||
void CheckoutProcess::panelSetPassword() {
|
void CheckoutProcess::panelSetPassword() {
|
||||||
getPasswordState([=](const Core::CloudPasswordState &state) {
|
getPasswordState([=](const Core::CloudPasswordState &state) {
|
||||||
if (state.request) {
|
if (state.hasPassword) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto owned = Box<PasscodeBox>(
|
auto owned = Box<PasscodeBox>(
|
||||||
|
|
|
@ -273,8 +273,8 @@ void SetupCloudPassword(
|
||||||
false
|
false
|
||||||
) | rpl::then(controller->session().api().cloudPassword().state(
|
) | rpl::then(controller->session().api().cloudPassword().state(
|
||||||
) | rpl::map([](const State &state) {
|
) | rpl::map([](const State &state) {
|
||||||
return state.request
|
return state.mtp.request
|
||||||
|| state.unknownAlgorithm
|
|| state.mtp.unknownAlgorithm
|
||||||
|| !state.unconfirmedPattern.isEmpty();
|
|| !state.unconfirmedPattern.isEmpty();
|
||||||
})) | rpl::distinct_until_changed();
|
})) | rpl::distinct_until_changed();
|
||||||
auto pattern = session->api().cloudPassword().state(
|
auto pattern = session->api().cloudPassword().state(
|
||||||
|
@ -802,12 +802,7 @@ bool CheckEditCloudPassword(not_null<::Main::Session*> session) {
|
||||||
const auto current = session->api().cloudPassword().stateCurrent();
|
const auto current = session->api().cloudPassword().stateCurrent();
|
||||||
Assert(current.has_value());
|
Assert(current.has_value());
|
||||||
|
|
||||||
if (!current->unknownAlgorithm
|
return !current->outdatedClient;
|
||||||
&& !v::is_null(current->newPassword)
|
|
||||||
&& !v::is_null(current->newSecureSecret)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object_ptr<Ui::BoxContent> EditCloudPasswordBox(not_null<Main::Session*> session) {
|
object_ptr<Ui::BoxContent> EditCloudPasswordBox(not_null<Main::Session*> session) {
|
||||||
|
@ -839,7 +834,7 @@ void RemoveCloudPassword(not_null<Window::SessionController*> controller) {
|
||||||
const auto current = session->api().cloudPassword().stateCurrent();
|
const auto current = session->api().cloudPassword().stateCurrent();
|
||||||
Assert(current.has_value());
|
Assert(current.has_value());
|
||||||
|
|
||||||
if (!current->request) {
|
if (!current->hasPassword) {
|
||||||
session->api().cloudPassword().clearUnconfirmedPassword();
|
session->api().cloudPassword().clearUnconfirmedPassword();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue