2015-04-02 10:33:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2015-04-02 10:33:19 +00:00
|
|
|
*/
|
2019-11-27 09:45:23 +00:00
|
|
|
#include "intro/intro_password_check.h"
|
2016-03-16 11:54:37 +00:00
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
#include "intro/intro_widget.h"
|
2018-08-03 21:48:00 +00:00
|
|
|
#include "core/core_cloud_password.h"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2023-11-15 00:52:41 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
2021-07-30 14:33:26 +00:00
|
|
|
#include "boxes/passcode_box.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2019-11-27 09:45:23 +00:00
|
|
|
#include "intro/intro_signup.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2023-08-31 11:21:24 +00:00
|
|
|
#include "ui/widgets/fields/input_field.h"
|
|
|
|
#include "ui/widgets/fields/password_input.h"
|
2019-11-27 08:02:56 +00:00
|
|
|
#include "main/main_account.h"
|
2021-09-15 10:21:45 +00:00
|
|
|
#include "base/random.h"
|
2019-11-26 11:10:44 +00:00
|
|
|
#include "styles/style_intro.h"
|
|
|
|
#include "styles/style_boxes.h"
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
namespace Intro {
|
2019-11-26 11:10:44 +00:00
|
|
|
namespace details {
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
PasswordCheckWidget::PasswordCheckWidget(
|
2018-08-03 21:48:00 +00:00
|
|
|
QWidget *parent,
|
2019-07-24 08:46:23 +00:00
|
|
|
not_null<Main::Account*> account,
|
2019-11-26 11:10:44 +00:00
|
|
|
not_null<Data*> data)
|
2019-07-24 08:46:23 +00:00
|
|
|
: Step(parent, account, data)
|
2021-07-30 14:33:26 +00:00
|
|
|
, _passwordState(getData()->pwdState)
|
2019-06-18 14:07:45 +00:00
|
|
|
, _pwdField(this, st::introPassword, tr::lng_signin_password())
|
2016-12-23 13:21:01 +00:00
|
|
|
, _pwdHint(this, st::introPasswordHint)
|
2019-06-18 14:07:45 +00:00
|
|
|
, _codeField(this, st::introPassword, tr::lng_signin_code())
|
2019-06-19 15:09:03 +00:00
|
|
|
, _toRecover(this, tr::lng_signin_recover(tr::now))
|
2019-11-27 08:33:18 +00:00
|
|
|
, _toPassword(this, tr::lng_signin_try_password(tr::now)) {
|
2022-05-06 04:16:21 +00:00
|
|
|
Expects(_passwordState.hasPassword);
|
2018-08-03 21:48:00 +00:00
|
|
|
|
2020-09-30 09:11:44 +00:00
|
|
|
Lang::Updated(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
refreshLang();
|
|
|
|
}, lifetime());
|
2017-05-30 13:54:05 +00:00
|
|
|
|
2019-11-27 08:33:18 +00:00
|
|
|
_toRecover->addClickHandler([=] { toRecover(); });
|
|
|
|
_toPassword->addClickHandler([=] { toPassword(); });
|
|
|
|
connect(_pwdField, &Ui::PasswordInput::changed, [=] { hideError(); });
|
2023-08-31 11:21:24 +00:00
|
|
|
_codeField->changes(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
hideError();
|
|
|
|
}, _codeField->lifetime());
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
setTitleText(tr::lng_signin_title());
|
2016-11-24 19:28:23 +00:00
|
|
|
updateDescriptionText();
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
if (_passwordState.hint.isEmpty()) {
|
2016-11-24 19:28:23 +00:00
|
|
|
_pwdHint->hide();
|
|
|
|
} else {
|
2021-07-30 14:33:26 +00:00
|
|
|
_pwdHint->setText(tr::lng_signin_hint(
|
|
|
|
tr::now,
|
|
|
|
lt_password_hint,
|
|
|
|
_passwordState.hint));
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2016-11-04 19:50:35 +00:00
|
|
|
_codeField->hide();
|
|
|
|
_toPassword->hide();
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::refreshLang() {
|
2019-06-19 16:39:25 +00:00
|
|
|
if (_toRecover) {
|
|
|
|
_toRecover->setText(tr::lng_signin_recover(tr::now));
|
|
|
|
}
|
|
|
|
if (_toPassword) {
|
|
|
|
_toPassword->setText(
|
|
|
|
tr::lng_signin_try_password(tr::now));
|
|
|
|
}
|
2021-07-30 14:33:26 +00:00
|
|
|
if (!_passwordState.hint.isEmpty()) {
|
|
|
|
_pwdHint->setText(tr::lng_signin_hint(
|
|
|
|
tr::now,
|
|
|
|
lt_password_hint,
|
|
|
|
_passwordState.hint));
|
2017-05-30 17:58:25 +00:00
|
|
|
}
|
2017-05-30 13:54:05 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
int PasswordCheckWidget::errorTop() const {
|
2019-11-26 14:27:09 +00:00
|
|
|
return contentTop() + st::introErrorBelowLinkTop;
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::resizeEvent(QResizeEvent *e) {
|
2016-11-24 19:28:23 +00:00
|
|
|
Step::resizeEvent(e);
|
2017-05-30 13:54:05 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::updateControlsGeometry() {
|
2016-11-24 19:28:23 +00:00
|
|
|
_pwdField->moveToLeft(contentLeft(), contentTop() + st::introPasswordTop);
|
|
|
|
_pwdHint->moveToLeft(contentLeft() + st::buttonRadius, contentTop() + st::introPasswordHintTop);
|
|
|
|
_codeField->moveToLeft(contentLeft(), contentTop() + st::introStepFieldTop);
|
|
|
|
auto linkTop = _codeField->y() + _codeField->height() + st::introLinkTop;
|
|
|
|
_toRecover->moveToLeft(contentLeft() + st::buttonRadius, linkTop);
|
|
|
|
_toPassword->moveToLeft(contentLeft() + st::buttonRadius, linkTop);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::setInnerFocus() {
|
2016-11-04 19:50:35 +00:00
|
|
|
if (_pwdField->isHidden()) {
|
2016-12-23 13:21:01 +00:00
|
|
|
_codeField->setFocusFast();
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
2016-12-23 13:21:01 +00:00
|
|
|
_pwdField->setFocusFast();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::activate() {
|
2016-11-24 19:28:23 +00:00
|
|
|
if (_pwdField->isHidden() && _codeField->isHidden()) {
|
|
|
|
Step::activate();
|
|
|
|
_pwdField->show();
|
|
|
|
_pwdHint->show();
|
|
|
|
_toRecover->show();
|
2016-03-14 16:59:18 +00:00
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
setInnerFocus();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::cancelled() {
|
2020-06-17 09:36:25 +00:00
|
|
|
api().request(base::take(_sentRequest)).cancel();
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
2023-01-10 13:10:34 +00:00
|
|
|
void PasswordCheckWidget::pwdSubmitDone(
|
|
|
|
bool recover,
|
|
|
|
const MTPauth_Authorization &result) {
|
2016-11-04 19:50:35 +00:00
|
|
|
_sentRequest = 0;
|
2015-04-02 10:33:19 +00:00
|
|
|
if (recover) {
|
|
|
|
cSetPasswordRecovered(true);
|
|
|
|
}
|
2023-01-10 13:10:34 +00:00
|
|
|
finish(result);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void PasswordCheckWidget::pwdSubmitFail(const MTP::Error &error) {
|
|
|
|
if (MTP::IsFloodError(error)) {
|
2016-11-04 19:50:35 +00:00
|
|
|
_sentRequest = 0;
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(tr::lng_flood_error());
|
2016-11-24 19:28:23 +00:00
|
|
|
_pwdField->showError();
|
2018-08-10 19:19:46 +00:00
|
|
|
return;
|
2016-04-08 10:44:35 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 19:50:35 +00:00
|
|
|
_sentRequest = 0;
|
2018-11-20 10:59:47 +00:00
|
|
|
const auto &type = error.type();
|
2022-11-26 21:20:17 +00:00
|
|
|
if (type == u"PASSWORD_HASH_INVALID"_q
|
|
|
|
|| type == u"SRP_PASSWORD_CHANGED"_q) {
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(tr::lng_signin_bad_password());
|
2016-11-04 19:50:35 +00:00
|
|
|
_pwdField->selectAll();
|
2016-11-24 19:28:23 +00:00
|
|
|
_pwdField->showError();
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (type == u"PASSWORD_EMPTY"_q
|
|
|
|
|| type == u"AUTH_KEY_UNREGISTERED"_q) {
|
2016-11-24 19:28:23 +00:00
|
|
|
goBack();
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (type == u"SRP_ID_INVALID"_q) {
|
2018-08-10 19:19:46 +00:00
|
|
|
handleSrpIdInvalid();
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
2018-08-10 19:19:46 +00:00
|
|
|
if (Logs::DebugEnabled()) { // internal server error
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(rpl::single(type + ": " + error.description()));
|
2018-08-10 19:19:46 +00:00
|
|
|
} else {
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(rpl::single(Lang::Hard::ServerError()));
|
2018-08-10 19:19:46 +00:00
|
|
|
}
|
|
|
|
_pwdField->setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::handleSrpIdInvalid() {
|
2019-02-19 06:57:53 +00:00
|
|
|
const auto now = crl::now();
|
2018-08-10 19:19:46 +00:00
|
|
|
if (_lastSrpIdInvalidTime > 0
|
|
|
|
&& now - _lastSrpIdInvalidTime < Core::kHandleSrpIdInvalidTimeout) {
|
2022-05-06 04:16:21 +00:00
|
|
|
_passwordState.mtp.request.id = 0;
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(rpl::single(Lang::Hard::ServerError()));
|
2018-08-10 19:19:46 +00:00
|
|
|
} else {
|
|
|
|
_lastSrpIdInvalidTime = now;
|
|
|
|
requestPasswordData();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::checkPasswordHash() {
|
2022-05-06 04:16:21 +00:00
|
|
|
if (_passwordState.mtp.request.id) {
|
2018-08-10 19:19:46 +00:00
|
|
|
passwordChecked();
|
|
|
|
} else {
|
|
|
|
requestPasswordData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::requestPasswordData() {
|
2020-06-17 09:36:25 +00:00
|
|
|
api().request(base::take(_sentRequest)).cancel();
|
|
|
|
_sentRequest = api().request(
|
2018-08-10 19:19:46 +00:00
|
|
|
MTPaccount_GetPassword()
|
|
|
|
).done([=](const MTPaccount_Password &result) {
|
|
|
|
_sentRequest = 0;
|
|
|
|
result.match([&](const MTPDaccount_password &data) {
|
2021-09-15 10:21:45 +00:00
|
|
|
base::RandomAddSeed(bytes::make_span(data.vsecure_random().v));
|
2021-07-30 14:33:26 +00:00
|
|
|
_passwordState = Core::ParseCloudPasswordState(data);
|
2018-08-10 19:19:46 +00:00
|
|
|
passwordChecked();
|
|
|
|
});
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::passwordChecked() {
|
2018-08-10 19:19:46 +00:00
|
|
|
const auto check = Core::ComputeCloudPasswordCheck(
|
2022-05-06 04:16:21 +00:00
|
|
|
_passwordState.mtp.request,
|
2018-08-10 19:19:46 +00:00
|
|
|
_passwordHash);
|
|
|
|
if (!check) {
|
|
|
|
return serverError();
|
|
|
|
}
|
2022-05-06 04:16:21 +00:00
|
|
|
_passwordState.mtp.request.id = 0;
|
2020-06-17 09:36:25 +00:00
|
|
|
_sentRequest = api().request(
|
2018-08-10 19:19:46 +00:00
|
|
|
MTPauth_CheckPassword(check.result)
|
|
|
|
).done([=](const MTPauth_Authorization &result) {
|
|
|
|
pwdSubmitDone(false, result);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2018-08-10 19:19:46 +00:00
|
|
|
pwdSubmitFail(error);
|
2020-06-11 13:07:14 +00:00
|
|
|
}).handleFloodErrors().send();
|
2018-08-10 19:19:46 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::serverError() {
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(rpl::single(Lang::Hard::ServerError()));
|
2018-08-10 19:19:46 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
void PasswordCheckWidget::codeSubmitDone(
|
|
|
|
const QString &code,
|
|
|
|
const MTPBool &result) {
|
|
|
|
auto fields = PasscodeBox::CloudFields::From(_passwordState);
|
|
|
|
fields.fromRecoveryCode = code;
|
|
|
|
fields.hasRecovery = false;
|
2022-05-06 04:27:19 +00:00
|
|
|
fields.mtp.curRequest = {};
|
|
|
|
fields.hasPassword = false;
|
2021-07-30 14:33:26 +00:00
|
|
|
auto box = Box<PasscodeBox>(&api().instance(), nullptr, fields);
|
2021-08-17 10:52:21 +00:00
|
|
|
const auto boxShared = std::make_shared<QPointer<PasscodeBox>>();
|
2021-07-30 14:33:26 +00:00
|
|
|
|
|
|
|
box->newAuthorization(
|
|
|
|
) | rpl::start_with_next([=](const MTPauth_Authorization &result) {
|
2021-08-17 10:52:21 +00:00
|
|
|
if (boxShared) {
|
|
|
|
(*boxShared)->closeBox();
|
|
|
|
}
|
2021-07-30 14:33:26 +00:00
|
|
|
pwdSubmitDone(true, result);
|
|
|
|
}, lifetime());
|
|
|
|
|
2021-08-17 10:52:21 +00:00
|
|
|
*boxShared = Ui::show(std::move(box));
|
2021-07-30 14:33:26 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void PasswordCheckWidget::codeSubmitFail(const MTP::Error &error) {
|
|
|
|
if (MTP::IsFloodError(error)) {
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(tr::lng_flood_error());
|
2016-11-24 19:28:23 +00:00
|
|
|
_codeField->showError();
|
2018-08-10 19:19:46 +00:00
|
|
|
return;
|
2016-04-08 10:44:35 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 19:50:35 +00:00
|
|
|
_sentRequest = 0;
|
2018-11-20 10:59:47 +00:00
|
|
|
const auto &type = error.type();
|
2022-11-26 21:20:17 +00:00
|
|
|
if (type == u"PASSWORD_EMPTY"_q
|
|
|
|
|| type == u"AUTH_KEY_UNREGISTERED"_q) {
|
2016-11-24 19:28:23 +00:00
|
|
|
goBack();
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (type == u"PASSWORD_RECOVERY_NA"_q) {
|
2015-04-02 10:33:19 +00:00
|
|
|
recoverStartFail(error);
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (type == u"PASSWORD_RECOVERY_EXPIRED"_q) {
|
2015-04-02 10:33:19 +00:00
|
|
|
_emailPattern = QString();
|
2019-11-27 08:33:18 +00:00
|
|
|
toPassword();
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (type == u"CODE_INVALID"_q) {
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(tr::lng_signin_wrong_code());
|
2016-11-04 19:50:35 +00:00
|
|
|
_codeField->selectAll();
|
2016-11-24 19:28:23 +00:00
|
|
|
_codeField->showError();
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
2018-08-10 19:19:46 +00:00
|
|
|
if (Logs::DebugEnabled()) { // internal server error
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(rpl::single(type + ": " + error.description()));
|
2018-08-10 19:19:46 +00:00
|
|
|
} else {
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(rpl::single(Lang::Hard::ServerError()));
|
2018-08-10 19:19:46 +00:00
|
|
|
}
|
|
|
|
_codeField->setFocus();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::recoverStarted(const MTPauth_PasswordRecovery &result) {
|
2019-07-05 13:38:38 +00:00
|
|
|
_emailPattern = qs(result.c_auth_passwordRecovery().vemail_pattern());
|
2016-11-24 19:28:23 +00:00
|
|
|
updateDescriptionText();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void PasswordCheckWidget::recoverStartFail(const MTP::Error &error) {
|
2016-11-04 19:50:35 +00:00
|
|
|
_pwdField->show();
|
2016-11-24 19:28:23 +00:00
|
|
|
_pwdHint->show();
|
2016-11-04 19:50:35 +00:00
|
|
|
_codeField->hide();
|
|
|
|
_pwdField->setFocus();
|
2016-11-24 19:28:23 +00:00
|
|
|
updateDescriptionText();
|
2015-04-02 10:33:19 +00:00
|
|
|
update();
|
2016-11-24 19:28:23 +00:00
|
|
|
hideError();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::toRecover() {
|
2021-07-30 14:33:26 +00:00
|
|
|
if (_passwordState.hasRecovery) {
|
2016-11-04 19:50:35 +00:00
|
|
|
if (_sentRequest) {
|
2020-06-17 09:36:25 +00:00
|
|
|
api().request(base::take(_sentRequest)).cancel();
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
hideError();
|
2016-11-04 19:50:35 +00:00
|
|
|
_toRecover->hide();
|
|
|
|
_toPassword->show();
|
|
|
|
_pwdField->hide();
|
2016-11-24 19:28:23 +00:00
|
|
|
_pwdHint->hide();
|
2016-11-04 19:50:35 +00:00
|
|
|
_pwdField->setText(QString());
|
|
|
|
_codeField->show();
|
|
|
|
_codeField->setFocus();
|
2016-11-24 19:28:23 +00:00
|
|
|
updateDescriptionText();
|
2015-04-04 20:01:34 +00:00
|
|
|
if (_emailPattern.isEmpty()) {
|
2020-06-17 09:36:25 +00:00
|
|
|
api().request(
|
2018-08-10 19:19:46 +00:00
|
|
|
MTPauth_RequestPasswordRecovery()
|
|
|
|
).done([=](const MTPauth_PasswordRecovery &result) {
|
|
|
|
recoverStarted(result);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2018-08-10 19:19:46 +00:00
|
|
|
recoverStartFail(error);
|
|
|
|
}).send();
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-02-27 08:23:20 +00:00
|
|
|
const auto box = Ui::show(
|
|
|
|
Ui::MakeInformBox(tr::lng_signin_no_email_forgot()));
|
|
|
|
box->boxClosing(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
showReset();
|
|
|
|
}, box->lifetime());
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::toPassword() {
|
2022-02-27 08:23:20 +00:00
|
|
|
const auto box = Ui::show(
|
|
|
|
Ui::MakeInformBox(tr::lng_signin_cant_email_forgot()));
|
|
|
|
box->boxClosing(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
showReset();
|
|
|
|
}, box->lifetime());
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::showReset() {
|
2016-11-04 19:50:35 +00:00
|
|
|
if (_sentRequest) {
|
2020-06-17 09:36:25 +00:00
|
|
|
api().request(base::take(_sentRequest)).cancel();
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
2016-11-04 19:50:35 +00:00
|
|
|
_toRecover->show();
|
|
|
|
_toPassword->hide();
|
|
|
|
_pwdField->show();
|
2016-11-24 19:28:23 +00:00
|
|
|
_pwdHint->show();
|
2016-11-04 19:50:35 +00:00
|
|
|
_codeField->hide();
|
|
|
|
_codeField->setText(QString());
|
|
|
|
_pwdField->setFocus();
|
2016-11-24 19:28:23 +00:00
|
|
|
showResetButton();
|
|
|
|
updateDescriptionText();
|
2015-04-02 10:33:19 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::updateDescriptionText() {
|
2017-05-30 13:54:05 +00:00
|
|
|
auto pwdHidden = _pwdField->isHidden();
|
|
|
|
auto emailPattern = _emailPattern;
|
2019-06-18 16:53:27 +00:00
|
|
|
setDescriptionText(pwdHidden
|
|
|
|
? tr::lng_signin_recover_desc(lt_email, rpl::single(emailPattern))
|
|
|
|
: tr::lng_signin_desc());
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
void PasswordCheckWidget::submit() {
|
2019-11-27 08:33:18 +00:00
|
|
|
if (_sentRequest) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-04 19:50:35 +00:00
|
|
|
if (_pwdField->isHidden()) {
|
2016-11-24 19:28:23 +00:00
|
|
|
auto code = _codeField->getLastText().trimmed();
|
2015-04-02 10:33:19 +00:00
|
|
|
if (code.isEmpty()) {
|
2016-11-24 19:28:23 +00:00
|
|
|
_codeField->showError();
|
2015-04-02 10:33:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-06-04 15:35:11 +00:00
|
|
|
const auto send = crl::guard(this, [=] {
|
2021-07-30 14:33:26 +00:00
|
|
|
_sentRequest = api().request(MTPauth_CheckRecoveryPassword(
|
|
|
|
MTP_string(code)
|
|
|
|
)).done([=](const MTPBool &result) {
|
|
|
|
codeSubmitDone(code, result);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2018-08-10 19:19:46 +00:00
|
|
|
codeSubmitFail(error);
|
2020-06-11 13:07:14 +00:00
|
|
|
}).handleFloodErrors().send();
|
2018-04-20 16:42:51 +00:00
|
|
|
});
|
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
if (_passwordState.notEmptyPassport) {
|
2020-09-24 12:48:02 +00:00
|
|
|
const auto confirmed = [=](Fn<void()> &&close) {
|
2018-04-20 16:42:51 +00:00
|
|
|
send();
|
2020-09-24 12:48:02 +00:00
|
|
|
close();
|
2018-04-20 16:42:51 +00:00
|
|
|
};
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::show(Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_cloud_password_passport_losing(),
|
|
|
|
.confirmed = confirmed,
|
|
|
|
.confirmText = tr::lng_continue(),
|
|
|
|
}));
|
2018-04-20 16:42:51 +00:00
|
|
|
} else {
|
|
|
|
send();
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
2016-11-24 19:28:23 +00:00
|
|
|
hideError();
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2018-08-03 21:48:00 +00:00
|
|
|
const auto password = _pwdField->getLastText().toUtf8();
|
2018-08-10 19:19:46 +00:00
|
|
|
_passwordHash = Core::ComputeCloudPasswordHash(
|
2022-05-06 04:16:21 +00:00
|
|
|
_passwordState.mtp.request.algo,
|
2018-08-03 21:48:00 +00:00
|
|
|
bytes::make_span(password));
|
2018-08-10 19:19:46 +00:00
|
|
|
checkPasswordHash();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
rpl::producer<QString> PasswordCheckWidget::nextButtonText() const {
|
2019-06-18 16:53:27 +00:00
|
|
|
return tr::lng_intro_submit();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2019-11-26 11:10:44 +00:00
|
|
|
} // namespace details
|
2016-11-24 19:28:23 +00:00
|
|
|
} // namespace Intro
|