2015-03-02 12:34:16 +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-03-02 12:34:16 +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-03-02 12:34:16 +00:00
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/passcode_box.h"
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2018-03-27 12:16:00 +00:00
|
|
|
#include "base/bytes.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2021-07-30 11:32:49 +00:00
|
|
|
#include "base/unixtime.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2019-11-27 08:02:56 +00:00
|
|
|
#include "apiwrap.h"
|
2021-08-02 19:06:33 +00:00
|
|
|
#include "api/api_cloud_password.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "main/main_domain.h"
|
2020-06-08 15:56:52 +00:00
|
|
|
#include "core/application.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "storage/storage_domain.h"
|
2020-08-25 10:57:17 +00:00
|
|
|
#include "ui/layers/generic_box.h"
|
|
|
|
#include "ui/text/text_utilities.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"
|
2018-11-07 09:39:31 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/wrap/fade_wrap.h"
|
2022-09-16 20:23:27 +00:00
|
|
|
#include "ui/painter.h"
|
2018-04-17 15:19:24 +00:00
|
|
|
#include "passport/passport_encryption.h"
|
2018-11-07 09:39:31 +00:00
|
|
|
#include "passport/passport_panel_edit_contact.h"
|
2020-08-25 10:57:17 +00:00
|
|
|
#include "settings/settings_privacy_security.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2018-11-07 09:39:31 +00:00
|
|
|
#include "styles/style_passport.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2022-01-24 16:33:30 +00:00
|
|
|
#include "base/qt/qt_common_adapters.h"
|
2018-11-07 09:39:31 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-08-25 10:57:17 +00:00
|
|
|
enum class PasswordErrorType {
|
|
|
|
None,
|
|
|
|
NoPassword,
|
|
|
|
Later,
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetCloudPassword(
|
|
|
|
not_null<Ui::GenericBox*> box,
|
|
|
|
not_null<Main::Session*> session) {
|
2021-08-02 19:06:33 +00:00
|
|
|
session->api().cloudPassword().state(
|
2020-08-25 10:57:17 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
using namespace Settings;
|
|
|
|
const auto weak = Ui::MakeWeak(box);
|
|
|
|
if (CheckEditCloudPassword(session)) {
|
|
|
|
box->getDelegate()->show(
|
|
|
|
EditCloudPasswordBox(session));
|
|
|
|
} else {
|
|
|
|
box->getDelegate()->show(CloudPasswordAppOutdatedBox());
|
|
|
|
}
|
|
|
|
if (weak) {
|
|
|
|
weak->closeBox();
|
|
|
|
}
|
|
|
|
}, box->lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferPasswordError(
|
|
|
|
not_null<Ui::GenericBox*> box,
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
TextWithEntities &&about,
|
|
|
|
PasswordErrorType error) {
|
|
|
|
box->setTitle(tr::lng_rights_transfer_check());
|
|
|
|
box->setWidth(st::transferCheckWidth);
|
|
|
|
|
|
|
|
auto text = std::move(about).append('\n').append('\n').append(
|
|
|
|
tr::lng_rights_transfer_check_password(
|
|
|
|
tr::now,
|
|
|
|
Ui::Text::RichLangValue)
|
|
|
|
).append('\n').append('\n').append(
|
|
|
|
tr::lng_rights_transfer_check_session(
|
|
|
|
tr::now,
|
|
|
|
Ui::Text::RichLangValue)
|
|
|
|
);
|
|
|
|
if (error == PasswordErrorType::Later) {
|
|
|
|
text.append('\n').append('\n').append(
|
|
|
|
tr::lng_rights_transfer_check_later(
|
|
|
|
tr::now,
|
|
|
|
Ui::Text::RichLangValue));
|
|
|
|
}
|
|
|
|
box->addRow(object_ptr<Ui::FlatLabel>(
|
|
|
|
box,
|
|
|
|
rpl::single(text),
|
|
|
|
st::boxLabel));
|
|
|
|
if (error == PasswordErrorType::Later) {
|
|
|
|
box->addButton(tr::lng_box_ok(), [=] { box->closeBox(); });
|
|
|
|
} else {
|
|
|
|
box->addButton(tr::lng_rights_transfer_set_password(), [=] {
|
|
|
|
SetCloudPassword(box, session);
|
|
|
|
});
|
|
|
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-30 11:32:49 +00:00
|
|
|
void StartPendingReset(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
not_null<Ui::BoxContent*> context,
|
|
|
|
Fn<void()> close) {
|
|
|
|
const auto weak = Ui::MakeWeak(context.get());
|
2021-08-15 10:11:48 +00:00
|
|
|
auto lifetime = std::make_shared<rpl::lifetime>();
|
|
|
|
|
|
|
|
auto finish = [=](const QString &message) mutable {
|
2021-07-30 11:32:49 +00:00
|
|
|
if (const auto strong = weak.data()) {
|
2021-08-15 10:11:48 +00:00
|
|
|
if (!message.isEmpty()) {
|
2022-02-27 08:23:20 +00:00
|
|
|
strong->getDelegate()->show(Ui::MakeInformBox(message));
|
2021-08-15 10:11:48 +00:00
|
|
|
}
|
2021-07-30 11:32:49 +00:00
|
|
|
strong->closeBox();
|
|
|
|
}
|
|
|
|
close();
|
2021-08-15 10:11:48 +00:00
|
|
|
if (lifetime) {
|
|
|
|
base::take(lifetime)->destroy();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
session->api().cloudPassword().resetPassword(
|
|
|
|
) | rpl::start_with_next_error_done([=](
|
|
|
|
Api::CloudPassword::ResetRetryDate retryDate) {
|
|
|
|
constexpr auto kMinute = 60;
|
|
|
|
constexpr auto kHour = 3600;
|
|
|
|
constexpr auto kDay = 86400;
|
|
|
|
const auto left = std::max(
|
|
|
|
retryDate - base::unixtime::now(),
|
|
|
|
kMinute);
|
|
|
|
const auto days = (left / kDay);
|
|
|
|
const auto hours = (left / kHour);
|
|
|
|
const auto minutes = (left / kMinute);
|
|
|
|
const auto duration = days
|
2022-03-31 16:45:11 +00:00
|
|
|
? tr::lng_days(tr::now, lt_count, days)
|
2021-08-15 10:11:48 +00:00
|
|
|
: hours
|
2022-03-31 16:45:11 +00:00
|
|
|
? tr::lng_hours(tr::now, lt_count, hours)
|
|
|
|
: tr::lng_minutes(tr::now, lt_count, minutes);
|
2021-07-30 11:32:49 +00:00
|
|
|
if (const auto strong = weak.data()) {
|
2022-02-27 08:23:20 +00:00
|
|
|
strong->getDelegate()->show(Ui::MakeInformBox(
|
2021-08-15 10:11:48 +00:00
|
|
|
tr::lng_cloud_password_reset_later(
|
|
|
|
tr::now,
|
|
|
|
lt_duration,
|
|
|
|
duration)));
|
2021-07-30 11:32:49 +00:00
|
|
|
}
|
2021-08-15 10:11:48 +00:00
|
|
|
}, [=](const QString &error) mutable {
|
|
|
|
finish("Error: " + error);
|
|
|
|
}, [=]() mutable {
|
|
|
|
finish({});
|
|
|
|
}, *lifetime);
|
2021-07-30 11:32:49 +00:00
|
|
|
}
|
|
|
|
|
2018-11-07 09:39:31 +00:00
|
|
|
} // namespace
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2019-06-14 12:43:42 +00:00
|
|
|
PasscodeBox::CloudFields PasscodeBox::CloudFields::From(
|
|
|
|
const Core::CloudPasswordState ¤t) {
|
|
|
|
auto result = CloudFields();
|
2022-05-06 04:27:19 +00:00
|
|
|
result.hasPassword = current.hasPassword;
|
|
|
|
result.mtp.curRequest = current.mtp.request;
|
|
|
|
result.mtp.newAlgo = current.mtp.newPassword;
|
|
|
|
result.mtp.newSecureSecretAlgo = current.mtp.newSecureSecret;
|
2019-06-14 12:43:42 +00:00
|
|
|
result.hasRecovery = current.hasRecovery;
|
|
|
|
result.notEmptyPassport = current.notEmptyPassport;
|
|
|
|
result.hint = current.hint;
|
2021-07-30 11:32:49 +00:00
|
|
|
result.pendingResetDate = current.pendingResetDate;
|
2019-06-14 12:43:42 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
PasscodeBox::PasscodeBox(
|
|
|
|
QWidget*,
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
bool turningOff)
|
|
|
|
: _session(session)
|
2020-06-17 09:36:25 +00:00
|
|
|
, _api(&_session->mtp())
|
2019-07-24 14:00:30 +00:00
|
|
|
, _turningOff(turningOff)
|
2015-10-14 11:51:37 +00:00
|
|
|
, _about(st::boxWidth - st::boxPadding.left() * 1.5)
|
2019-06-18 14:07:45 +00:00
|
|
|
, _oldPasscode(this, st::defaultInputField, tr::lng_passcode_enter_old())
|
2021-05-25 20:38:01 +00:00
|
|
|
, _newPasscode(
|
|
|
|
this,
|
|
|
|
st::defaultInputField,
|
|
|
|
session->domain().local().hasLocalPasscode()
|
|
|
|
? tr::lng_passcode_enter_new()
|
|
|
|
: tr::lng_passcode_enter_first())
|
2019-06-18 14:07:45 +00:00
|
|
|
, _reenterPasscode(this, st::defaultInputField, tr::lng_passcode_confirm_new())
|
|
|
|
, _passwordHint(this, st::defaultInputField, tr::lng_cloud_password_hint())
|
|
|
|
, _recoverEmail(this, st::defaultInputField, tr::lng_cloud_password_email())
|
2019-06-19 15:09:03 +00:00
|
|
|
, _recover(this, tr::lng_signin_recover(tr::now)) {
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
PasscodeBox::PasscodeBox(
|
|
|
|
QWidget*,
|
2021-07-30 14:33:26 +00:00
|
|
|
not_null<MTP::Instance*> mtp,
|
|
|
|
Main::Session *session,
|
2019-07-24 14:00:30 +00:00
|
|
|
const CloudFields &fields)
|
|
|
|
: _session(session)
|
2021-07-30 14:33:26 +00:00
|
|
|
, _api(mtp)
|
2019-07-24 14:00:30 +00:00
|
|
|
, _turningOff(fields.turningOff)
|
2015-10-12 21:02:10 +00:00
|
|
|
, _cloudPwd(true)
|
2019-06-14 12:43:42 +00:00
|
|
|
, _cloudFields(fields)
|
2015-10-14 11:51:37 +00:00
|
|
|
, _about(st::boxWidth - st::boxPadding.left() * 1.5)
|
2019-06-18 14:07:45 +00:00
|
|
|
, _oldPasscode(this, st::defaultInputField, tr::lng_cloud_password_enter_old())
|
2021-07-30 14:33:26 +00:00
|
|
|
, _newPasscode(
|
|
|
|
this,
|
|
|
|
st::defaultInputField,
|
2022-05-06 04:27:19 +00:00
|
|
|
(fields.hasPassword
|
2021-07-30 14:33:26 +00:00
|
|
|
? tr::lng_cloud_password_enter_new()
|
|
|
|
: tr::lng_cloud_password_enter_first()))
|
2019-06-18 14:07:45 +00:00
|
|
|
, _reenterPasscode(this, st::defaultInputField, tr::lng_cloud_password_confirm_new())
|
2021-07-30 14:33:26 +00:00
|
|
|
, _passwordHint(
|
|
|
|
this,
|
|
|
|
st::defaultInputField,
|
2022-05-06 04:27:19 +00:00
|
|
|
(fields.hasPassword
|
2021-07-30 14:33:26 +00:00
|
|
|
? tr::lng_cloud_password_change_hint()
|
|
|
|
: tr::lng_cloud_password_hint()))
|
2019-06-18 14:07:45 +00:00
|
|
|
, _recoverEmail(this, st::defaultInputField, tr::lng_cloud_password_email())
|
2021-07-30 11:32:49 +00:00
|
|
|
, _recover(this, tr::lng_signin_recover(tr::now))
|
|
|
|
, _showRecoverLink(_cloudFields.hasRecovery || !_cloudFields.pendingResetDate) {
|
2021-07-30 14:33:26 +00:00
|
|
|
Expects(session != nullptr || !fields.fromRecoveryCode.isEmpty());
|
2022-05-06 04:27:19 +00:00
|
|
|
Expects(!_turningOff || _cloudFields.hasPassword);
|
2018-08-03 21:48:00 +00:00
|
|
|
|
2019-06-14 12:43:42 +00:00
|
|
|
if (!_cloudFields.hint.isEmpty()) {
|
|
|
|
_hintText.setText(
|
|
|
|
st::passcodeTextStyle,
|
2019-06-19 16:39:25 +00:00
|
|
|
tr::lng_signin_hint(tr::now, lt_password_hint, _cloudFields.hint));
|
2019-06-14 12:43:42 +00:00
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
PasscodeBox::PasscodeBox(
|
|
|
|
QWidget*,
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const CloudFields &fields)
|
|
|
|
: PasscodeBox(nullptr, &session->mtp(), session, fields) {
|
|
|
|
}
|
|
|
|
|
2018-07-10 16:41:11 +00:00
|
|
|
rpl::producer<QByteArray> PasscodeBox::newPasswordSet() const {
|
|
|
|
return _newPasswordSet.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> PasscodeBox::passwordReloadNeeded() const {
|
|
|
|
return _passwordReloadNeeded.events();
|
|
|
|
}
|
|
|
|
|
2018-11-07 09:39:31 +00:00
|
|
|
rpl::producer<> PasscodeBox::clearUnconfirmedPassword() const {
|
|
|
|
return _clearUnconfirmedPassword.events();
|
|
|
|
}
|
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
rpl::producer<MTPauth_Authorization> PasscodeBox::newAuthorization() const {
|
|
|
|
return _newAuthorization.events();
|
|
|
|
}
|
|
|
|
|
2018-08-03 21:48:00 +00:00
|
|
|
bool PasscodeBox::currentlyHave() const {
|
2021-05-25 20:38:01 +00:00
|
|
|
return _cloudPwd
|
2022-05-06 04:27:19 +00:00
|
|
|
? _cloudFields.hasPassword
|
2021-05-25 20:38:01 +00:00
|
|
|
: _session->domain().local().hasLocalPasscode();
|
2019-06-14 12:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PasscodeBox::onlyCheckCurrent() const {
|
2019-06-14 14:04:30 +00:00
|
|
|
return _turningOff || _cloudFields.customCheckCallback;
|
2018-08-03 21:48:00 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void PasscodeBox::prepare() {
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(
|
|
|
|
(_cloudFields.customSubmitButton
|
2019-06-19 11:22:25 +00:00
|
|
|
? std::move(_cloudFields.customSubmitButton)
|
2019-06-18 16:53:27 +00:00
|
|
|
: _turningOff
|
|
|
|
? tr::lng_passcode_remove_button()
|
|
|
|
: tr::lng_settings_save()),
|
|
|
|
[=] { save(); });
|
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
2015-10-12 21:02:10 +00:00
|
|
|
|
2019-06-14 12:43:42 +00:00
|
|
|
_about.setText(
|
|
|
|
st::passcodeTextStyle,
|
2019-06-19 15:09:03 +00:00
|
|
|
(_cloudFields.customDescription
|
|
|
|
? *_cloudFields.customDescription
|
|
|
|
: _cloudPwd
|
|
|
|
? tr::lng_cloud_password_about(tr::now)
|
|
|
|
: tr::lng_passcode_about(tr::now)));
|
2015-10-14 11:51:37 +00:00
|
|
|
_aboutHeight = _about.countHeight(st::boxWidth - st::boxPadding.left() * 1.5);
|
2019-06-14 12:43:42 +00:00
|
|
|
const auto onlyCheck = onlyCheckCurrent();
|
|
|
|
if (onlyCheck) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_oldPasscode->show();
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(_cloudFields.customTitle
|
2019-06-19 11:22:25 +00:00
|
|
|
? std::move(_cloudFields.customTitle)
|
2019-06-18 15:00:55 +00:00
|
|
|
: _cloudPwd
|
|
|
|
? tr::lng_cloud_password_remove()
|
|
|
|
: tr::lng_passcode_remove());
|
2021-07-30 11:32:49 +00:00
|
|
|
setDimensions(st::boxWidth, st::passcodePadding.top() + _oldPasscode->height() + st::passcodeTextLine + ((_showRecoverLink && !_hintText.isEmpty()) ? st::passcodeTextLine : 0) + st::passcodeAboutSkip + _aboutHeight + st::passcodePadding.bottom());
|
2015-03-02 12:34:16 +00:00
|
|
|
} else {
|
2018-08-03 21:48:00 +00:00
|
|
|
if (currentlyHave()) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_oldPasscode->show();
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(_cloudPwd
|
|
|
|
? tr::lng_cloud_password_change()
|
|
|
|
: tr::lng_passcode_change());
|
2021-07-30 11:32:49 +00:00
|
|
|
setDimensions(st::boxWidth, st::passcodePadding.top() + _oldPasscode->height() + st::passcodeTextLine + ((_showRecoverLink && !_hintText.isEmpty()) ? st::passcodeTextLine : 0) + _newPasscode->height() + st::passcodeLittleSkip + _reenterPasscode->height() + st::passcodeSkip + (_cloudPwd ? _passwordHint->height() + st::passcodeLittleSkip : 0) + st::passcodeAboutSkip + _aboutHeight + st::passcodePadding.bottom());
|
2015-03-02 12:34:16 +00:00
|
|
|
} else {
|
2016-11-11 13:46:04 +00:00
|
|
|
_oldPasscode->hide();
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(_cloudPwd
|
2021-07-30 14:33:26 +00:00
|
|
|
? (_cloudFields.fromRecoveryCode.isEmpty()
|
|
|
|
? tr::lng_cloud_password_create()
|
|
|
|
: tr::lng_cloud_password_change())
|
2019-06-18 15:00:55 +00:00
|
|
|
: tr::lng_passcode_create());
|
2021-07-30 14:33:26 +00:00
|
|
|
setDimensions(st::boxWidth, st::passcodePadding.top() + _newPasscode->height() + st::passcodeLittleSkip + _reenterPasscode->height() + st::passcodeSkip + (_cloudPwd ? _passwordHint->height() + st::passcodeLittleSkip : 0) + st::passcodeAboutSkip + _aboutHeight + ((_cloudPwd && _cloudFields.fromRecoveryCode.isEmpty()) ? (st::passcodeLittleSkip + _recoverEmail->height() + st::passcodeSkip) : st::passcodePadding.bottom()));
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
connect(_oldPasscode, &Ui::MaskedInputField::changed, [=] { oldChanged(); });
|
|
|
|
connect(_newPasscode, &Ui::MaskedInputField::changed, [=] { newChanged(); });
|
|
|
|
connect(_reenterPasscode, &Ui::MaskedInputField::changed, [=] { newChanged(); });
|
2023-08-31 11:21:24 +00:00
|
|
|
_passwordHint->changes(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
newChanged();
|
|
|
|
}, _passwordHint->lifetime());
|
|
|
|
_recoverEmail->changes(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
if (!_emailError.isEmpty()) {
|
|
|
|
_emailError = QString();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}, _recoverEmail->lifetime());
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
const auto fieldSubmit = [=] { submit(); };
|
|
|
|
connect(_oldPasscode, &Ui::MaskedInputField::submitted, fieldSubmit);
|
|
|
|
connect(_newPasscode, &Ui::MaskedInputField::submitted, fieldSubmit);
|
|
|
|
connect(_reenterPasscode, &Ui::MaskedInputField::submitted, fieldSubmit);
|
2023-08-31 11:21:24 +00:00
|
|
|
_passwordHint->submits(
|
|
|
|
) | rpl::start_with_next(fieldSubmit, _passwordHint->lifetime());
|
|
|
|
_recoverEmail->submits(
|
|
|
|
) | rpl::start_with_next(fieldSubmit, _recoverEmail->lifetime());
|
2015-10-12 21:02:10 +00:00
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
_recover->addClickHandler([=] { recoverByEmail(); });
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2018-08-03 21:48:00 +00:00
|
|
|
const auto has = currentlyHave();
|
2019-06-14 12:43:42 +00:00
|
|
|
_oldPasscode->setVisible(onlyCheck || has);
|
2021-07-30 11:32:49 +00:00
|
|
|
_recover->setVisible((onlyCheck || has)
|
|
|
|
&& _cloudPwd
|
|
|
|
&& _showRecoverLink);
|
2019-06-14 12:43:42 +00:00
|
|
|
_newPasscode->setVisible(!onlyCheck);
|
|
|
|
_reenterPasscode->setVisible(!onlyCheck);
|
|
|
|
_passwordHint->setVisible(!onlyCheck && _cloudPwd);
|
2021-07-30 14:33:26 +00:00
|
|
|
_recoverEmail->setVisible(!onlyCheck
|
|
|
|
&& _cloudPwd
|
|
|
|
&& !has
|
|
|
|
&& _cloudFields.fromRecoveryCode.isEmpty());
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void PasscodeBox::submit() {
|
2018-08-03 21:48:00 +00:00
|
|
|
const auto has = currentlyHave();
|
2016-11-11 13:46:04 +00:00
|
|
|
if (_oldPasscode->hasFocus()) {
|
2019-06-14 12:43:42 +00:00
|
|
|
if (onlyCheckCurrent()) {
|
2018-05-31 12:20:28 +00:00
|
|
|
save();
|
2015-10-12 21:02:10 +00:00
|
|
|
} else {
|
2016-11-11 13:46:04 +00:00
|
|
|
_newPasscode->setFocus();
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
2016-11-11 13:46:04 +00:00
|
|
|
} else if (_newPasscode->hasFocus()) {
|
|
|
|
_reenterPasscode->setFocus();
|
|
|
|
} else if (_reenterPasscode->hasFocus()) {
|
|
|
|
if (has && _oldPasscode->text().isEmpty()) {
|
|
|
|
_oldPasscode->setFocus();
|
|
|
|
_oldPasscode->showError();
|
|
|
|
} else if (_newPasscode->text().isEmpty()) {
|
|
|
|
_newPasscode->setFocus();
|
|
|
|
_newPasscode->showError();
|
|
|
|
} else if (_reenterPasscode->text().isEmpty()) {
|
|
|
|
_reenterPasscode->showError();
|
|
|
|
} else if (!_passwordHint->isHidden()) {
|
|
|
|
_passwordHint->setFocus();
|
2015-10-12 21:02:10 +00:00
|
|
|
} else {
|
2018-05-31 12:20:28 +00:00
|
|
|
save();
|
2015-10-12 21:02:10 +00:00
|
|
|
}
|
2016-11-11 13:46:04 +00:00
|
|
|
} else if (_passwordHint->hasFocus()) {
|
|
|
|
if (_recoverEmail->isHidden()) {
|
2018-05-31 12:20:28 +00:00
|
|
|
save();
|
2015-10-12 21:02:10 +00:00
|
|
|
} else {
|
2016-11-11 13:46:04 +00:00
|
|
|
_recoverEmail->setFocus();
|
2015-10-12 21:02:10 +00:00
|
|
|
}
|
2016-11-11 13:46:04 +00:00
|
|
|
} else if (_recoverEmail->hasFocus()) {
|
2018-05-31 12:20:28 +00:00
|
|
|
save();
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PasscodeBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2016-11-19 14:47:28 +00:00
|
|
|
Painter p(this);
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2015-10-14 11:51:37 +00:00
|
|
|
int32 w = st::boxWidth - st::boxPadding.left() * 1.5;
|
2021-07-30 11:32:49 +00:00
|
|
|
int32 abouty = (_passwordHint->isHidden() ? ((_reenterPasscode->isHidden() ? (_oldPasscode->y() + (_showRecoverLink && !_hintText.isEmpty() ? st::passcodeTextLine : 0)) : _reenterPasscode->y()) + st::passcodeSkip) : _passwordHint->y()) + _oldPasscode->height() + st::passcodeLittleSkip + st::passcodeAboutSkip;
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFg);
|
2015-10-14 11:51:37 +00:00
|
|
|
_about.drawLeft(p, st::boxPadding.left(), abouty, w, width());
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2015-10-12 21:02:10 +00:00
|
|
|
if (!_hintText.isEmpty() && _oldError.isEmpty()) {
|
2016-12-09 18:56:01 +00:00
|
|
|
_hintText.drawLeftElided(p, st::boxPadding.left(), _oldPasscode->y() + _oldPasscode->height() + ((st::passcodeTextLine - st::normalFont->height) / 2), w, width(), 1, style::al_topleft);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!_oldError.isEmpty()) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFgError);
|
2016-12-09 18:56:01 +00:00
|
|
|
p.drawText(QRect(st::boxPadding.left(), _oldPasscode->y() + _oldPasscode->height(), w, st::passcodeTextLine), _oldError, style::al_left);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
if (!_newError.isEmpty()) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFgError);
|
2016-12-09 18:56:01 +00:00
|
|
|
p.drawText(QRect(st::boxPadding.left(), _reenterPasscode->y() + _reenterPasscode->height(), w, st::passcodeTextLine), _newError, style::al_left);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
if (!_emailError.isEmpty()) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFgError);
|
2016-12-09 18:56:01 +00:00
|
|
|
p.drawText(QRect(st::boxPadding.left(), _recoverEmail->y() + _recoverEmail->height(), w, st::passcodeTextLine), _emailError, style::al_left);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PasscodeBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
2018-08-03 21:48:00 +00:00
|
|
|
const auto has = currentlyHave();
|
2015-10-14 11:51:37 +00:00
|
|
|
int32 w = st::boxWidth - st::boxPadding.left() - st::boxPadding.right();
|
2016-11-11 13:46:04 +00:00
|
|
|
_oldPasscode->resize(w, _oldPasscode->height());
|
2016-12-13 17:07:56 +00:00
|
|
|
_oldPasscode->moveToLeft(st::boxPadding.left(), st::passcodePadding.top());
|
2016-11-11 13:46:04 +00:00
|
|
|
_newPasscode->resize(w, _newPasscode->height());
|
2021-07-30 11:32:49 +00:00
|
|
|
_newPasscode->moveToLeft(st::boxPadding.left(), _oldPasscode->y() + ((_turningOff || has) ? (_oldPasscode->height() + st::passcodeTextLine + ((_showRecoverLink && !_hintText.isEmpty()) ? st::passcodeTextLine : 0)) : 0));
|
2016-11-11 13:46:04 +00:00
|
|
|
_reenterPasscode->resize(w, _reenterPasscode->height());
|
2016-12-13 17:07:56 +00:00
|
|
|
_reenterPasscode->moveToLeft(st::boxPadding.left(), _newPasscode->y() + _newPasscode->height() + st::passcodeLittleSkip);
|
2016-11-11 13:46:04 +00:00
|
|
|
_passwordHint->resize(w, _passwordHint->height());
|
|
|
|
_passwordHint->moveToLeft(st::boxPadding.left(), _reenterPasscode->y() + _reenterPasscode->height() + st::passcodeSkip);
|
|
|
|
_recoverEmail->resize(w, _passwordHint->height());
|
2016-12-13 17:07:56 +00:00
|
|
|
_recoverEmail->moveToLeft(st::boxPadding.left(), _passwordHint->y() + _passwordHint->height() + st::passcodeLittleSkip + _aboutHeight + st::passcodeLittleSkip);
|
2016-11-11 13:46:04 +00:00
|
|
|
|
|
|
|
if (!_recover->isHidden()) {
|
2016-12-09 18:56:01 +00:00
|
|
|
_recover->moveToLeft(st::boxPadding.left(), _oldPasscode->y() + _oldPasscode->height() + (_hintText.isEmpty() ? ((st::passcodeTextLine - _recover->height()) / 2) : st::passcodeTextLine));
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void PasscodeBox::setInnerFocus() {
|
2016-11-11 13:46:04 +00:00
|
|
|
if (_skipEmailWarning && !_recoverEmail->isHidden()) {
|
2016-12-20 13:03:51 +00:00
|
|
|
_recoverEmail->setFocusFast();
|
2016-11-11 13:46:04 +00:00
|
|
|
} else if (_oldPasscode->isHidden()) {
|
2016-12-20 13:03:51 +00:00
|
|
|
_newPasscode->setFocusFast();
|
2015-03-02 12:34:16 +00:00
|
|
|
} else {
|
2016-12-20 13:03:51 +00:00
|
|
|
_oldPasscode->setFocusFast();
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
void PasscodeBox::recoverPasswordDone(
|
|
|
|
const QByteArray &newPasswordBytes,
|
|
|
|
const MTPauth_Authorization &result) {
|
2019-06-14 12:01:35 +00:00
|
|
|
if (_replacedBy) {
|
|
|
|
_replacedBy->closeBox();
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
_setRequest = 0;
|
2021-07-30 14:33:26 +00:00
|
|
|
const auto weak = Ui::MakeWeak(this);
|
|
|
|
_newAuthorization.fire_copy(result);
|
|
|
|
if (weak) {
|
2021-08-17 12:37:17 +00:00
|
|
|
_newPasswordSet.fire_copy(newPasswordBytes);
|
2021-07-30 14:33:26 +00:00
|
|
|
if (weak) {
|
2022-02-27 08:23:20 +00:00
|
|
|
getDelegate()->show(Ui::MakeInformBox(
|
|
|
|
tr::lng_cloud_password_updated()));
|
2021-08-17 12:37:17 +00:00
|
|
|
if (weak) {
|
|
|
|
closeBox();
|
|
|
|
}
|
2021-07-30 14:33:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PasscodeBox::setPasswordDone(const QByteArray &newPasswordBytes) {
|
|
|
|
if (_replacedBy) {
|
|
|
|
_replacedBy->closeBox();
|
|
|
|
}
|
|
|
|
_setRequest = 0;
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto weak = Ui::MakeWeak(this);
|
2021-07-30 14:33:26 +00:00
|
|
|
_newPasswordSet.fire_copy(newPasswordBytes);
|
2019-06-14 12:01:35 +00:00
|
|
|
if (weak) {
|
2022-02-27 08:23:20 +00:00
|
|
|
auto text = _reenterPasscode->isHidden()
|
|
|
|
? tr::lng_cloud_password_removed()
|
2021-07-30 14:33:26 +00:00
|
|
|
: _oldPasscode->isHidden()
|
2022-02-27 08:23:20 +00:00
|
|
|
? tr::lng_cloud_password_was_set()
|
|
|
|
: tr::lng_cloud_password_updated();
|
|
|
|
getDelegate()->show(Ui::MakeInformBox(std::move(text)));
|
2021-07-30 14:33:26 +00:00
|
|
|
if (weak) {
|
|
|
|
closeBox();
|
|
|
|
}
|
2019-06-14 12:01:35 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PasscodeBox::closeReplacedBy() {
|
|
|
|
if (isHidden()) {
|
|
|
|
if (_replacedBy && !_replacedBy->isHidden()) {
|
|
|
|
_replacedBy->closeBox();
|
|
|
|
}
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 17:15:49 +00:00
|
|
|
void PasscodeBox::setPasswordFail(const QString &type) {
|
|
|
|
if (MTP::IsFloodError(type)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
closeReplacedBy();
|
2016-04-08 10:44:35 +00:00
|
|
|
_setRequest = 0;
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
_oldPasscode->selectAll();
|
|
|
|
_oldPasscode->setFocus();
|
|
|
|
_oldPasscode->showError();
|
2019-06-19 15:09:03 +00:00
|
|
|
_oldError = tr::lng_flood_error(tr::now);
|
2021-07-30 11:32:49 +00:00
|
|
|
if (_showRecoverLink && _hintText.isEmpty()) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_recover->hide();
|
2016-04-08 10:44:35 +00:00
|
|
|
}
|
|
|
|
update();
|
2018-08-10 19:19:46 +00:00
|
|
|
return;
|
2016-04-08 10:44:35 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
closeReplacedBy();
|
2015-04-02 10:33:19 +00:00
|
|
|
_setRequest = 0;
|
2022-11-26 21:20:17 +00:00
|
|
|
if (type == u"PASSWORD_HASH_INVALID"_q
|
|
|
|
|| type == u"SRP_PASSWORD_CHANGED"_q) {
|
2016-11-11 13:46:04 +00:00
|
|
|
if (_oldPasscode->isHidden()) {
|
2018-07-10 16:41:11 +00:00
|
|
|
_passwordReloadNeeded.fire({});
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
2018-05-31 12:20:28 +00:00
|
|
|
badOldPasscode();
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
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();
|
2022-11-26 21:20:17 +00:00
|
|
|
//} else if (type == u"NEW_PASSWORD_BAD"_q) {
|
|
|
|
//} else if (type == u"NEW_SALT_INVALID"_q) {
|
|
|
|
} else if (type == u"EMAIL_INVALID"_q) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_emailError = tr::lng_cloud_password_bad_email(tr::now);
|
2016-11-11 13:46:04 +00:00
|
|
|
_recoverEmail->setFocus();
|
|
|
|
_recoverEmail->showError();
|
2015-04-02 10:33:19 +00:00
|
|
|
update();
|
2018-07-10 16:41:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 19:19:46 +00:00
|
|
|
void PasscodeBox::setPasswordFail(
|
2018-07-10 16:41:11 +00:00
|
|
|
const QByteArray &newPasswordBytes,
|
2018-11-07 09:39:31 +00:00
|
|
|
const QString &email,
|
2021-03-12 12:48:00 +00:00
|
|
|
const MTP::Error &error) {
|
2022-11-26 21:20:17 +00:00
|
|
|
const auto prefix = u"EMAIL_UNCONFIRMED_"_q;
|
2018-11-07 09:39:31 +00:00
|
|
|
if (error.type().startsWith(prefix)) {
|
2021-10-19 13:00:21 +00:00
|
|
|
const auto codeLength = base::StringViewMid(error.type(), prefix.size()).toInt();
|
2018-11-07 09:39:31 +00:00
|
|
|
|
2018-07-10 16:41:11 +00:00
|
|
|
closeReplacedBy();
|
|
|
|
_setRequest = 0;
|
|
|
|
|
2018-11-07 09:39:31 +00:00
|
|
|
validateEmail(email, codeLength, newPasswordBytes);
|
2018-07-10 16:41:11 +00:00
|
|
|
} else {
|
2021-11-26 20:46:53 +00:00
|
|
|
setPasswordFail(error.type());
|
2018-08-10 19:19:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-07 09:39:31 +00:00
|
|
|
void PasscodeBox::validateEmail(
|
|
|
|
const QString &email,
|
|
|
|
int codeLength,
|
|
|
|
const QByteArray &newPasswordBytes) {
|
|
|
|
const auto errors = std::make_shared<rpl::event_stream<QString>>();
|
|
|
|
const auto resent = std::make_shared<rpl::event_stream<QString>>();
|
|
|
|
const auto set = std::make_shared<bool>(false);
|
2019-06-24 07:55:10 +00:00
|
|
|
const auto submit = crl::guard(this, [=](QString code) {
|
2018-11-07 09:39:31 +00:00
|
|
|
if (_setRequest) {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-27 08:02:56 +00:00
|
|
|
_setRequest = _api.request(MTPaccount_ConfirmPasswordEmail(
|
2018-11-07 09:39:31 +00:00
|
|
|
MTP_string(code)
|
2021-11-26 20:54:46 +00:00
|
|
|
)).done([=] {
|
2018-11-07 09:39:31 +00:00
|
|
|
*set = true;
|
|
|
|
setPasswordDone(newPasswordBytes);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2018-11-07 09:39:31 +00:00
|
|
|
_setRequest = 0;
|
2021-03-12 12:48:00 +00:00
|
|
|
if (MTP::IsFloodError(error)) {
|
2019-06-19 15:09:03 +00:00
|
|
|
errors->fire(tr::lng_flood_error(tr::now));
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (error.type() == u"CODE_INVALID"_q) {
|
2019-06-19 15:09:03 +00:00
|
|
|
errors->fire(tr::lng_signin_wrong_code(tr::now));
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (error.type() == u"EMAIL_HASH_EXPIRED"_q) {
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto weak = Ui::MakeWeak(this);
|
2018-11-07 09:39:31 +00:00
|
|
|
_clearUnconfirmedPassword.fire({});
|
|
|
|
if (weak) {
|
2022-02-27 08:23:20 +00:00
|
|
|
auto box = Ui::MakeInformBox({
|
|
|
|
Lang::Hard::EmailConfirmationExpired()
|
|
|
|
});
|
2018-11-07 09:39:31 +00:00
|
|
|
weak->getDelegate()->show(
|
|
|
|
std::move(box),
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::LayerOption::CloseOther);
|
2018-11-07 09:39:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errors->fire(Lang::Hard::ServerError());
|
|
|
|
}
|
|
|
|
}).handleFloodErrors().send();
|
2019-06-24 07:55:10 +00:00
|
|
|
});
|
|
|
|
const auto resend = crl::guard(this, [=] {
|
2018-11-07 09:39:31 +00:00
|
|
|
if (_setRequest) {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-27 08:02:56 +00:00
|
|
|
_setRequest = _api.request(MTPaccount_ResendPasswordEmail(
|
2021-11-26 20:54:46 +00:00
|
|
|
)).done([=] {
|
2018-11-07 09:39:31 +00:00
|
|
|
_setRequest = 0;
|
2019-06-19 15:09:03 +00:00
|
|
|
resent->fire(tr::lng_cloud_password_resent(tr::now));
|
2021-11-26 20:46:53 +00:00
|
|
|
}).fail([=] {
|
2018-11-07 09:39:31 +00:00
|
|
|
_setRequest = 0;
|
|
|
|
errors->fire(Lang::Hard::ServerError());
|
|
|
|
}).send();
|
2019-06-24 07:55:10 +00:00
|
|
|
});
|
|
|
|
const auto box = _replacedBy = getDelegate()->show(
|
2018-11-07 09:39:31 +00:00
|
|
|
Passport::VerifyEmailBox(
|
|
|
|
email,
|
|
|
|
codeLength,
|
|
|
|
submit,
|
|
|
|
resend,
|
|
|
|
errors->events(),
|
2019-06-14 12:01:35 +00:00
|
|
|
resent->events()));
|
2018-11-07 09:39:31 +00:00
|
|
|
|
|
|
|
box->setCloseByOutsideClick(false);
|
|
|
|
box->setCloseByEscape(false);
|
|
|
|
box->boxClosing(
|
|
|
|
) | rpl::filter([=] {
|
|
|
|
return !*set;
|
2019-09-13 12:22:54 +00:00
|
|
|
}) | start_with_next([=, weak = Ui::MakeWeak(this)] {
|
2018-11-07 09:39:31 +00:00
|
|
|
if (weak) {
|
|
|
|
weak->_clearUnconfirmedPassword.fire({});
|
|
|
|
}
|
|
|
|
if (weak) {
|
|
|
|
weak->closeBox();
|
|
|
|
}
|
|
|
|
}, box->lifetime());
|
|
|
|
}
|
|
|
|
|
2018-08-10 19:19:46 +00:00
|
|
|
void PasscodeBox::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:27:19 +00:00
|
|
|
_cloudFields.mtp.curRequest.id = 0;
|
2018-08-10 19:19:46 +00:00
|
|
|
_oldError = Lang::Hard::ServerError();
|
|
|
|
update();
|
|
|
|
} else {
|
|
|
|
_lastSrpIdInvalidTime = now;
|
|
|
|
requestPasswordData();
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void PasscodeBox::save(bool force) {
|
2015-04-02 10:33:19 +00:00
|
|
|
if (_setRequest) return;
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
QString old = _oldPasscode->text(), pwd = _newPasscode->text(), conf = _reenterPasscode->text();
|
2018-08-03 21:48:00 +00:00
|
|
|
const auto has = currentlyHave();
|
2015-04-02 10:33:19 +00:00
|
|
|
if (!_cloudPwd && (_turningOff || has)) {
|
2015-04-04 20:01:34 +00:00
|
|
|
if (!passcodeCanTry()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_oldError = tr::lng_flood_error(tr::now);
|
2016-11-11 13:46:04 +00:00
|
|
|
_oldPasscode->setFocus();
|
|
|
|
_oldPasscode->showError();
|
2015-04-04 20:01:34 +00:00
|
|
|
update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-25 20:38:01 +00:00
|
|
|
if (_session->domain().local().checkPasscode(old.toUtf8())) {
|
2015-04-04 20:01:34 +00:00
|
|
|
cSetPasscodeBadTries(0);
|
2015-03-02 12:34:16 +00:00
|
|
|
if (_turningOff) pwd = conf = QString();
|
|
|
|
} else {
|
2015-04-04 20:01:34 +00:00
|
|
|
cSetPasscodeBadTries(cPasscodeBadTries() + 1);
|
2019-02-19 06:57:53 +00:00
|
|
|
cSetPasscodeLastTry(crl::now());
|
2018-05-31 12:20:28 +00:00
|
|
|
badOldPasscode();
|
2015-03-02 12:34:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-06-14 12:43:42 +00:00
|
|
|
const auto onlyCheck = onlyCheckCurrent();
|
|
|
|
if (!onlyCheck && pwd.isEmpty()) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_newPasscode->setFocus();
|
|
|
|
_newPasscode->showError();
|
2016-12-13 17:07:56 +00:00
|
|
|
closeReplacedBy();
|
2015-03-02 12:34:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-06-14 12:43:42 +00:00
|
|
|
if (!onlyCheck && pwd != conf) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_reenterPasscode->selectAll();
|
|
|
|
_reenterPasscode->setFocus();
|
|
|
|
_reenterPasscode->showError();
|
2015-03-02 12:34:16 +00:00
|
|
|
if (!conf.isEmpty()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_newError = _cloudPwd
|
|
|
|
? tr::lng_cloud_password_differ(tr::now)
|
|
|
|
: tr::lng_passcode_differ(tr::now);
|
2015-03-02 12:34:16 +00:00
|
|
|
update();
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
closeReplacedBy();
|
2019-06-14 12:43:42 +00:00
|
|
|
} else if (!onlyCheck && has && old == pwd) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_newPasscode->setFocus();
|
|
|
|
_newPasscode->showError();
|
2019-06-19 15:09:03 +00:00
|
|
|
_newError = _cloudPwd
|
|
|
|
? tr::lng_cloud_password_is_same(tr::now)
|
|
|
|
: tr::lng_passcode_is_same(tr::now);
|
2015-03-02 12:34:16 +00:00
|
|
|
update();
|
2016-12-13 17:07:56 +00:00
|
|
|
closeReplacedBy();
|
2015-04-02 10:33:19 +00:00
|
|
|
} else if (_cloudPwd) {
|
2016-11-11 13:46:04 +00:00
|
|
|
QString hint = _passwordHint->getLastText(), email = _recoverEmail->getLastText().trimmed();
|
2019-06-14 12:43:42 +00:00
|
|
|
if (!onlyCheck
|
|
|
|
&& !_passwordHint->isHidden()
|
|
|
|
&& !_newPasscode->isHidden()
|
|
|
|
&& pwd == hint) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_newPasscode->setFocus();
|
|
|
|
_newPasscode->showError();
|
2019-06-19 15:09:03 +00:00
|
|
|
_newError = tr::lng_cloud_password_bad(tr::now);
|
2015-04-04 20:01:34 +00:00
|
|
|
update();
|
2016-12-13 17:07:56 +00:00
|
|
|
closeReplacedBy();
|
2015-04-04 20:01:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-06-14 12:43:42 +00:00
|
|
|
if (!onlyCheck && !_recoverEmail->isHidden() && email.isEmpty() && !force) {
|
2015-10-03 10:09:09 +00:00
|
|
|
_skipEmailWarning = true;
|
2022-02-27 08:23:20 +00:00
|
|
|
_replacedBy = getDelegate()->show(Ui::MakeConfirmBox({
|
|
|
|
.text = { tr::lng_cloud_password_about_recover() },
|
|
|
|
.confirmed = crl::guard(this, [this] { save(true); }),
|
|
|
|
.confirmText = tr::lng_cloud_password_skip_email(),
|
|
|
|
.confirmStyle = &st::attentionBoxButton,
|
|
|
|
}));
|
2019-06-14 12:43:42 +00:00
|
|
|
} else if (onlyCheck) {
|
|
|
|
submitOnlyCheckCloudPassword(old);
|
2018-04-17 15:19:24 +00:00
|
|
|
} else if (_oldPasscode->isHidden()) {
|
|
|
|
setNewCloudPassword(pwd);
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
2018-04-17 15:19:24 +00:00
|
|
|
changeCloudPassword(old, pwd);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2015-03-02 12:34:16 +00:00
|
|
|
} else {
|
2019-06-14 12:01:35 +00:00
|
|
|
closeReplacedBy();
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto weak = Ui::MakeWeak(this);
|
2015-04-04 20:01:34 +00:00
|
|
|
cSetPasscodeBadTries(0);
|
2021-05-25 20:38:01 +00:00
|
|
|
_session->domain().local().setPasscode(pwd.toUtf8());
|
2020-06-08 15:56:52 +00:00
|
|
|
Core::App().localPasscodeChanged();
|
2019-03-04 18:40:21 +00:00
|
|
|
if (weak) {
|
|
|
|
closeBox();
|
|
|
|
}
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-14 12:43:42 +00:00
|
|
|
void PasscodeBox::submitOnlyCheckCloudPassword(const QString &oldPassword) {
|
2018-04-17 15:19:24 +00:00
|
|
|
Expects(!_oldPasscode->isHidden());
|
|
|
|
|
2018-04-20 16:42:51 +00:00
|
|
|
const auto send = [=] {
|
2019-06-14 12:43:42 +00:00
|
|
|
sendOnlyCheckCloudPassword(oldPassword);
|
2018-04-20 16:42:51 +00:00
|
|
|
};
|
2019-06-14 12:43:42 +00:00
|
|
|
if (_cloudFields.turningOff && _cloudFields.notEmptyPassport) {
|
2019-06-14 14:04:30 +00:00
|
|
|
Assert(!_cloudFields.customCheckCallback);
|
2019-06-14 12:43:42 +00:00
|
|
|
|
2022-02-27 08:23:20 +00:00
|
|
|
getDelegate()->show(Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_cloud_password_passport_losing(),
|
|
|
|
.confirmed = [=](Fn<void()> &&close) { send(); close(); },
|
|
|
|
.confirmText = tr::lng_continue(),
|
|
|
|
}));
|
2018-04-20 16:42:51 +00:00
|
|
|
} else {
|
|
|
|
send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-14 12:43:42 +00:00
|
|
|
void PasscodeBox::sendOnlyCheckCloudPassword(const QString &oldPassword) {
|
2018-08-10 19:19:46 +00:00
|
|
|
checkPassword(oldPassword, [=](const Core::CloudPasswordResult &check) {
|
2019-06-14 14:04:30 +00:00
|
|
|
if (const auto onstack = _cloudFields.customCheckCallback) {
|
|
|
|
onstack(check);
|
2019-06-14 12:43:42 +00:00
|
|
|
} else {
|
|
|
|
Assert(_cloudFields.turningOff);
|
|
|
|
sendClearCloudPassword(check);
|
|
|
|
}
|
2018-08-10 19:19:46 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void PasscodeBox::checkPassword(
|
|
|
|
const QString &oldPassword,
|
|
|
|
CheckPasswordCallback callback) {
|
2018-04-17 15:19:24 +00:00
|
|
|
const auto passwordUtf = oldPassword.toUtf8();
|
2018-08-10 19:19:46 +00:00
|
|
|
_checkPasswordHash = Core::ComputeCloudPasswordHash(
|
2022-05-06 04:27:19 +00:00
|
|
|
_cloudFields.mtp.curRequest.algo,
|
2018-08-03 21:48:00 +00:00
|
|
|
bytes::make_span(passwordUtf));
|
2018-08-10 19:19:46 +00:00
|
|
|
checkPasswordHash(std::move(callback));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PasscodeBox::checkPasswordHash(CheckPasswordCallback callback) {
|
|
|
|
_checkPasswordCallback = std::move(callback);
|
2022-05-06 04:27:19 +00:00
|
|
|
if (_cloudFields.mtp.curRequest.id) {
|
2018-08-10 19:19:46 +00:00
|
|
|
passwordChecked();
|
|
|
|
} else {
|
|
|
|
requestPasswordData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PasscodeBox::passwordChecked() {
|
2022-05-06 04:27:19 +00:00
|
|
|
if (!_cloudFields.mtp.curRequest || !_cloudFields.mtp.curRequest.id || !_checkPasswordCallback) {
|
2018-08-10 19:19:46 +00:00
|
|
|
return serverError();
|
|
|
|
}
|
|
|
|
const auto check = Core::ComputeCloudPasswordCheck(
|
2022-05-06 04:27:19 +00:00
|
|
|
_cloudFields.mtp.curRequest,
|
2018-08-10 19:19:46 +00:00
|
|
|
_checkPasswordHash);
|
|
|
|
if (!check) {
|
|
|
|
return serverError();
|
|
|
|
}
|
2022-05-06 04:27:19 +00:00
|
|
|
_cloudFields.mtp.curRequest.id = 0;
|
2018-08-10 19:19:46 +00:00
|
|
|
_checkPasswordCallback(check);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PasscodeBox::requestPasswordData() {
|
|
|
|
if (!_checkPasswordCallback) {
|
|
|
|
return serverError();
|
|
|
|
}
|
|
|
|
|
2019-11-27 08:02:56 +00:00
|
|
|
_api.request(base::take(_setRequest)).cancel();
|
|
|
|
_setRequest = _api.request(
|
2018-08-10 19:19:46 +00:00
|
|
|
MTPaccount_GetPassword()
|
|
|
|
).done([=](const MTPaccount_Password &result) {
|
|
|
|
_setRequest = 0;
|
|
|
|
result.match([&](const MTPDaccount_password &data) {
|
2022-05-06 04:27:19 +00:00
|
|
|
_cloudFields.mtp.curRequest = Core::ParseCloudPasswordCheckRequest(data);
|
2018-08-10 19:19:46 +00:00
|
|
|
passwordChecked();
|
|
|
|
});
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PasscodeBox::serverError() {
|
2022-02-27 08:23:20 +00:00
|
|
|
getDelegate()->show(Ui::MakeInformBox(Lang::Hard::ServerError()));
|
2018-08-10 19:19:46 +00:00
|
|
|
closeBox();
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
bool PasscodeBox::handleCustomCheckError(const MTP::Error &error) {
|
2021-03-31 17:15:49 +00:00
|
|
|
return handleCustomCheckError(error.type());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PasscodeBox::handleCustomCheckError(const QString &type) {
|
|
|
|
if (MTP::IsFloodError(type)
|
2022-11-26 21:20:17 +00:00
|
|
|
|| type == u"PASSWORD_HASH_INVALID"_q
|
|
|
|
|| type == u"SRP_PASSWORD_CHANGED"_q
|
|
|
|
|| type == u"SRP_ID_INVALID"_q) {
|
2021-03-31 17:15:49 +00:00
|
|
|
setPasswordFail(type);
|
2019-06-14 14:04:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-10 19:19:46 +00:00
|
|
|
void PasscodeBox::sendClearCloudPassword(
|
|
|
|
const Core::CloudPasswordResult &check) {
|
2018-04-17 15:19:24 +00:00
|
|
|
const auto hint = QString();
|
|
|
|
const auto email = QString();
|
2018-08-03 21:48:00 +00:00
|
|
|
const auto flags = MTPDaccount_passwordInputSettings::Flag::f_new_algo
|
2018-04-17 15:19:24 +00:00
|
|
|
| MTPDaccount_passwordInputSettings::Flag::f_new_password_hash
|
|
|
|
| MTPDaccount_passwordInputSettings::Flag::f_hint
|
|
|
|
| MTPDaccount_passwordInputSettings::Flag::f_email;
|
2019-11-27 08:02:56 +00:00
|
|
|
_setRequest = _api.request(MTPaccount_UpdatePasswordSettings(
|
2018-08-10 19:19:46 +00:00
|
|
|
check.result,
|
2018-04-17 15:19:24 +00:00
|
|
|
MTP_account_passwordInputSettings(
|
|
|
|
MTP_flags(flags),
|
2022-05-06 04:27:19 +00:00
|
|
|
Core::PrepareCloudPasswordAlgo(_cloudFields.mtp.newAlgo),
|
2019-07-05 13:38:38 +00:00
|
|
|
MTP_bytes(), // new_password_hash
|
2018-04-17 15:19:24 +00:00
|
|
|
MTP_string(hint),
|
|
|
|
MTP_string(email),
|
2018-08-03 21:48:00 +00:00
|
|
|
MTPSecureSecretSettings())
|
2021-11-26 20:54:46 +00:00
|
|
|
)).done([=] {
|
2018-07-10 16:41:11 +00:00
|
|
|
setPasswordDone({});
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) mutable {
|
2018-11-07 09:39:31 +00:00
|
|
|
setPasswordFail({}, QString(), error);
|
2019-06-24 13:14:07 +00:00
|
|
|
}).handleFloodErrors().send();
|
2018-04-17 15:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PasscodeBox::setNewCloudPassword(const QString &newPassword) {
|
2018-07-10 16:41:11 +00:00
|
|
|
const auto newPasswordBytes = newPassword.toUtf8();
|
2018-08-10 19:19:46 +00:00
|
|
|
const auto newPasswordHash = Core::ComputeCloudPasswordDigest(
|
2022-05-06 04:27:19 +00:00
|
|
|
_cloudFields.mtp.newAlgo,
|
2018-08-03 21:48:00 +00:00
|
|
|
bytes::make_span(newPasswordBytes));
|
2018-08-10 19:19:46 +00:00
|
|
|
if (newPasswordHash.modpow.empty()) {
|
|
|
|
return serverError();
|
|
|
|
}
|
2018-04-17 15:19:24 +00:00
|
|
|
const auto hint = _passwordHint->getLastText();
|
|
|
|
const auto email = _recoverEmail->getLastText().trimmed();
|
2021-07-30 14:33:26 +00:00
|
|
|
using Flag = MTPDaccount_passwordInputSettings::Flag;
|
|
|
|
const auto flags = Flag::f_new_algo
|
|
|
|
| Flag::f_new_password_hash
|
|
|
|
| Flag::f_hint
|
|
|
|
| (_cloudFields.fromRecoveryCode.isEmpty() ? Flag::f_email : Flag(0));
|
2018-08-10 19:19:46 +00:00
|
|
|
_checkPasswordCallback = nullptr;
|
2021-07-30 14:33:26 +00:00
|
|
|
|
|
|
|
const auto settings = MTP_account_passwordInputSettings(
|
|
|
|
MTP_flags(flags),
|
2022-05-06 04:27:19 +00:00
|
|
|
Core::PrepareCloudPasswordAlgo(_cloudFields.mtp.newAlgo),
|
2021-07-30 14:33:26 +00:00
|
|
|
MTP_bytes(newPasswordHash.modpow),
|
|
|
|
MTP_string(hint),
|
|
|
|
MTP_string(email),
|
|
|
|
MTPSecureSecretSettings());
|
|
|
|
if (_cloudFields.fromRecoveryCode.isEmpty()) {
|
|
|
|
_setRequest = _api.request(MTPaccount_UpdatePasswordSettings(
|
|
|
|
MTP_inputCheckPasswordEmpty(),
|
|
|
|
settings
|
2021-11-26 20:54:46 +00:00
|
|
|
)).done([=] {
|
2021-07-30 14:33:26 +00:00
|
|
|
setPasswordDone(newPasswordBytes);
|
|
|
|
}).fail([=](const MTP::Error &error) {
|
|
|
|
setPasswordFail(newPasswordBytes, email, error);
|
|
|
|
}).handleFloodErrors().send();
|
|
|
|
} else {
|
|
|
|
_setRequest = _api.request(MTPauth_RecoverPassword(
|
|
|
|
MTP_flags(MTPauth_RecoverPassword::Flag::f_new_settings),
|
|
|
|
MTP_string(_cloudFields.fromRecoveryCode),
|
|
|
|
settings
|
|
|
|
)).done([=](const MTPauth_Authorization &result) {
|
2021-08-17 10:52:21 +00:00
|
|
|
recoverPasswordDone(newPasswordBytes, result);
|
2021-07-30 14:33:26 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2021-08-17 10:52:21 +00:00
|
|
|
if (MTP::IsFloodError(error)) {
|
|
|
|
_newError = tr::lng_flood_error(tr::now);
|
|
|
|
update();
|
|
|
|
}
|
2021-07-30 14:33:26 +00:00
|
|
|
setPasswordFail(newPasswordBytes, email, error);
|
|
|
|
}).handleFloodErrors().send();
|
|
|
|
}
|
2018-04-17 15:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PasscodeBox::changeCloudPassword(
|
|
|
|
const QString &oldPassword,
|
|
|
|
const QString &newPassword) {
|
2018-08-10 19:19:46 +00:00
|
|
|
checkPassword(oldPassword, [=](const Core::CloudPasswordResult &check) {
|
|
|
|
changeCloudPassword(oldPassword, check, newPassword);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void PasscodeBox::changeCloudPassword(
|
|
|
|
const QString &oldPassword,
|
|
|
|
const Core::CloudPasswordResult &check,
|
|
|
|
const QString &newPassword) {
|
2019-11-27 08:02:56 +00:00
|
|
|
_setRequest = _api.request(MTPaccount_GetPasswordSettings(
|
2018-08-10 19:19:46 +00:00
|
|
|
check.result
|
2018-04-17 15:19:24 +00:00
|
|
|
)).done([=](const MTPaccount_PasswordSettings &result) {
|
|
|
|
_setRequest = 0;
|
|
|
|
|
|
|
|
Expects(result.type() == mtpc_account_passwordSettings);
|
|
|
|
const auto &data = result.c_account_passwordSettings();
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto wrapped = data.vsecure_settings();
|
|
|
|
if (!wrapped) {
|
2018-08-10 19:19:46 +00:00
|
|
|
checkPasswordHash([=](const Core::CloudPasswordResult &check) {
|
|
|
|
const auto empty = QByteArray();
|
|
|
|
sendChangeCloudPassword(check, newPassword, empty);
|
|
|
|
});
|
2018-04-17 15:19:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto &settings = wrapped->c_secureSecretSettings();
|
2018-08-10 19:19:46 +00:00
|
|
|
const auto passwordUtf = oldPassword.toUtf8();
|
2018-04-17 15:19:24 +00:00
|
|
|
const auto secret = Passport::DecryptSecureSecret(
|
2019-07-05 13:38:38 +00:00
|
|
|
bytes::make_span(settings.vsecure_secret().v),
|
2018-08-03 21:48:00 +00:00
|
|
|
Core::ComputeSecureSecretHash(
|
2019-07-05 13:38:38 +00:00
|
|
|
Core::ParseSecureSecretAlgo(settings.vsecure_algo()),
|
2018-07-10 16:41:11 +00:00
|
|
|
bytes::make_span(passwordUtf)));
|
2018-04-17 15:19:24 +00:00
|
|
|
if (secret.empty()) {
|
|
|
|
LOG(("API Error: Failed to decrypt secure secret."));
|
2018-08-10 19:19:46 +00:00
|
|
|
suggestSecretReset(newPassword);
|
2018-08-03 21:48:00 +00:00
|
|
|
} else if (Passport::CountSecureSecretId(secret)
|
2019-07-05 13:38:38 +00:00
|
|
|
!= settings.vsecure_secret_id().v) {
|
2018-04-17 15:19:24 +00:00
|
|
|
LOG(("API Error: Wrong secure secret id."));
|
2018-08-10 19:19:46 +00:00
|
|
|
suggestSecretReset(newPassword);
|
2018-04-17 15:19:24 +00:00
|
|
|
} else {
|
2018-08-10 19:19:46 +00:00
|
|
|
const auto secureSecret = QByteArray(
|
|
|
|
reinterpret_cast<const char*>(secret.data()),
|
|
|
|
secret.size());
|
|
|
|
checkPasswordHash([=](const Core::CloudPasswordResult &check) {
|
|
|
|
sendChangeCloudPassword(check, newPassword, secureSecret);
|
|
|
|
});
|
2018-04-17 15:19:24 +00:00
|
|
|
}
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2021-11-26 20:46:53 +00:00
|
|
|
setPasswordFail(error.type());
|
2020-06-11 16:09:46 +00:00
|
|
|
}).handleFloodErrors().send();
|
2018-04-17 15:19:24 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 19:19:46 +00:00
|
|
|
void PasscodeBox::suggestSecretReset(const QString &newPassword) {
|
2020-09-24 12:48:02 +00:00
|
|
|
auto resetSecretAndSave = [=](Fn<void()> &&close) {
|
|
|
|
checkPasswordHash([=, close = std::move(close)](
|
|
|
|
const Core::CloudPasswordResult &check) {
|
|
|
|
resetSecret(check, newPassword, std::move(close));
|
2018-08-10 19:19:46 +00:00
|
|
|
});
|
2018-04-17 15:19:24 +00:00
|
|
|
};
|
2022-02-27 08:23:20 +00:00
|
|
|
getDelegate()->show(Ui::MakeConfirmBox({
|
|
|
|
.text = { Lang::Hard::PassportCorruptedChange() },
|
|
|
|
.confirmed = std::move(resetSecretAndSave),
|
|
|
|
.confirmText = Lang::Hard::PassportCorruptedReset(),
|
|
|
|
}));
|
2018-04-17 15:19:24 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 19:19:46 +00:00
|
|
|
void PasscodeBox::resetSecret(
|
|
|
|
const Core::CloudPasswordResult &check,
|
|
|
|
const QString &newPassword,
|
|
|
|
Fn<void()> callback) {
|
|
|
|
using Flag = MTPDaccount_passwordInputSettings::Flag;
|
2019-11-27 08:02:56 +00:00
|
|
|
_setRequest = _api.request(MTPaccount_UpdatePasswordSettings(
|
2018-08-10 19:19:46 +00:00
|
|
|
check.result,
|
|
|
|
MTP_account_passwordInputSettings(
|
|
|
|
MTP_flags(Flag::f_new_secure_settings),
|
|
|
|
MTPPasswordKdfAlgo(), // new_algo
|
|
|
|
MTPbytes(), // new_password_hash
|
|
|
|
MTPstring(), // hint
|
|
|
|
MTPstring(), // email
|
|
|
|
MTP_secureSecretSettings(
|
|
|
|
MTP_securePasswordKdfAlgoUnknown(), // secure_algo
|
2019-07-05 13:38:38 +00:00
|
|
|
MTP_bytes(), // secure_secret
|
2018-08-10 19:19:46 +00:00
|
|
|
MTP_long(0))) // secure_secret_id
|
2021-11-26 20:54:46 +00:00
|
|
|
)).done([=] {
|
2018-08-10 19:19:46 +00:00
|
|
|
_setRequest = 0;
|
|
|
|
callback();
|
|
|
|
checkPasswordHash([=](const Core::CloudPasswordResult &check) {
|
|
|
|
const auto empty = QByteArray();
|
|
|
|
sendChangeCloudPassword(check, newPassword, empty);
|
|
|
|
});
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2018-08-10 19:19:46 +00:00
|
|
|
_setRequest = 0;
|
2022-11-26 21:20:17 +00:00
|
|
|
if (error.type() == u"SRP_ID_INVALID"_q) {
|
2018-08-10 19:19:46 +00:00
|
|
|
handleSrpIdInvalid();
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2018-04-17 15:19:24 +00:00
|
|
|
void PasscodeBox::sendChangeCloudPassword(
|
2018-08-10 19:19:46 +00:00
|
|
|
const Core::CloudPasswordResult &check,
|
2018-04-17 15:19:24 +00:00
|
|
|
const QString &newPassword,
|
|
|
|
const QByteArray &secureSecret) {
|
2018-07-10 16:41:11 +00:00
|
|
|
const auto newPasswordBytes = newPassword.toUtf8();
|
2018-08-10 19:19:46 +00:00
|
|
|
const auto newPasswordHash = Core::ComputeCloudPasswordDigest(
|
2022-05-06 04:27:19 +00:00
|
|
|
_cloudFields.mtp.newAlgo,
|
2018-08-03 21:48:00 +00:00
|
|
|
bytes::make_span(newPasswordBytes));
|
2018-08-10 19:19:46 +00:00
|
|
|
if (newPasswordHash.modpow.empty()) {
|
|
|
|
return serverError();
|
|
|
|
}
|
2018-04-17 15:19:24 +00:00
|
|
|
const auto hint = _passwordHint->getLastText();
|
2018-08-03 21:48:00 +00:00
|
|
|
auto flags = MTPDaccount_passwordInputSettings::Flag::f_new_algo
|
2018-04-17 15:19:24 +00:00
|
|
|
| MTPDaccount_passwordInputSettings::Flag::f_new_password_hash
|
|
|
|
| MTPDaccount_passwordInputSettings::Flag::f_hint;
|
|
|
|
auto newSecureSecret = bytes::vector();
|
|
|
|
auto newSecureSecretId = 0ULL;
|
|
|
|
if (!secureSecret.isEmpty()) {
|
2018-08-03 21:48:00 +00:00
|
|
|
flags |= MTPDaccount_passwordInputSettings::Flag::f_new_secure_settings;
|
2018-04-17 15:19:24 +00:00
|
|
|
newSecureSecretId = Passport::CountSecureSecretId(
|
|
|
|
bytes::make_span(secureSecret));
|
|
|
|
newSecureSecret = Passport::EncryptSecureSecret(
|
|
|
|
bytes::make_span(secureSecret),
|
2018-08-03 21:48:00 +00:00
|
|
|
Core::ComputeSecureSecretHash(
|
2022-05-06 04:27:19 +00:00
|
|
|
_cloudFields.mtp.newSecureSecretAlgo,
|
2018-07-10 16:41:11 +00:00
|
|
|
bytes::make_span(newPasswordBytes)));
|
2018-04-17 15:19:24 +00:00
|
|
|
}
|
2019-11-27 08:02:56 +00:00
|
|
|
_setRequest = _api.request(MTPaccount_UpdatePasswordSettings(
|
2018-08-10 19:19:46 +00:00
|
|
|
check.result,
|
2018-04-17 15:19:24 +00:00
|
|
|
MTP_account_passwordInputSettings(
|
|
|
|
MTP_flags(flags),
|
2022-05-06 04:27:19 +00:00
|
|
|
Core::PrepareCloudPasswordAlgo(_cloudFields.mtp.newAlgo),
|
2018-08-10 19:19:46 +00:00
|
|
|
MTP_bytes(newPasswordHash.modpow),
|
2018-04-17 15:19:24 +00:00
|
|
|
MTP_string(hint),
|
|
|
|
MTPstring(), // email is not changing
|
2018-08-03 21:48:00 +00:00
|
|
|
MTP_secureSecretSettings(
|
2022-05-06 04:27:19 +00:00
|
|
|
Core::PrepareSecureSecretAlgo(_cloudFields.mtp.newSecureSecretAlgo),
|
2018-08-03 21:48:00 +00:00
|
|
|
MTP_bytes(newSecureSecret),
|
|
|
|
MTP_long(newSecureSecretId)))
|
2021-11-26 20:54:46 +00:00
|
|
|
)).done([=] {
|
2018-07-10 16:41:11 +00:00
|
|
|
setPasswordDone(newPasswordBytes);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2018-11-07 09:39:31 +00:00
|
|
|
setPasswordFail(newPasswordBytes, QString(), error);
|
2020-06-11 16:09:46 +00:00
|
|
|
}).handleFloodErrors().send();
|
2018-04-17 15:19:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void PasscodeBox::badOldPasscode() {
|
2016-11-11 13:46:04 +00:00
|
|
|
_oldPasscode->selectAll();
|
|
|
|
_oldPasscode->setFocus();
|
|
|
|
_oldPasscode->showError();
|
2019-06-19 15:09:03 +00:00
|
|
|
_oldError = _cloudPwd
|
|
|
|
? tr::lng_cloud_password_wrong(tr::now)
|
|
|
|
: tr::lng_passcode_wrong(tr::now);
|
2021-07-30 11:32:49 +00:00
|
|
|
if (_showRecoverLink && _hintText.isEmpty()) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_recover->hide();
|
2015-10-12 21:02:10 +00:00
|
|
|
}
|
2015-03-02 12:34:16 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void PasscodeBox::oldChanged() {
|
2015-03-02 12:34:16 +00:00
|
|
|
if (!_oldError.isEmpty()) {
|
|
|
|
_oldError = QString();
|
2021-07-30 11:32:49 +00:00
|
|
|
if (_showRecoverLink && _hintText.isEmpty()) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_recover->show();
|
2015-10-12 21:02:10 +00:00
|
|
|
}
|
2015-03-02 12:34:16 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void PasscodeBox::newChanged() {
|
2015-03-02 12:34:16 +00:00
|
|
|
if (!_newError.isEmpty()) {
|
|
|
|
_newError = QString();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void PasscodeBox::recoverByEmail() {
|
2021-07-30 11:32:49 +00:00
|
|
|
if (!_cloudFields.hasRecovery) {
|
2021-07-30 14:33:26 +00:00
|
|
|
Assert(_session != nullptr);
|
2021-07-30 11:32:49 +00:00
|
|
|
const auto session = _session;
|
2022-02-27 08:23:20 +00:00
|
|
|
const auto reset = crl::guard(this, [=](Fn<void()> &&close) {
|
|
|
|
StartPendingReset(session, this, std::move(close));
|
2021-07-30 11:32:49 +00:00
|
|
|
});
|
2022-02-27 08:23:20 +00:00
|
|
|
getDelegate()->show(Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_cloud_password_reset_no_email(tr::now),
|
|
|
|
.confirmed = reset,
|
|
|
|
.confirmText = tr::lng_cloud_password_reset_ok(tr::now),
|
|
|
|
}));
|
2021-07-30 11:32:49 +00:00
|
|
|
} else if (_pattern.isEmpty()) {
|
2015-04-02 10:33:19 +00:00
|
|
|
_pattern = "-";
|
2019-11-27 08:02:56 +00:00
|
|
|
_api.request(MTPauth_RequestPasswordRecovery(
|
2018-04-17 15:19:24 +00:00
|
|
|
)).done([=](const MTPauth_PasswordRecovery &result) {
|
|
|
|
recoverStarted(result);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2018-04-17 15:19:24 +00:00
|
|
|
recoverStartFail(error);
|
|
|
|
}).send();
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
|
|
|
recover();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void PasscodeBox::recoverExpired() {
|
2015-04-02 10:33:19 +00:00
|
|
|
_pattern = QString();
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
void PasscodeBox::recover() {
|
2021-07-30 14:33:26 +00:00
|
|
|
if (_pattern == "-" || !_session) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2021-07-30 11:32:49 +00:00
|
|
|
const auto weak = Ui::MakeWeak(this);
|
2018-04-20 16:42:51 +00:00
|
|
|
const auto box = getDelegate()->show(Box<RecoverBox>(
|
2021-07-30 14:33:26 +00:00
|
|
|
&_api.instance(),
|
2020-06-11 16:09:46 +00:00
|
|
|
_session,
|
2018-04-20 16:42:51 +00:00
|
|
|
_pattern,
|
2021-07-30 14:33:26 +00:00
|
|
|
_cloudFields,
|
2021-07-30 11:32:49 +00:00
|
|
|
[weak] { if (weak) { weak->closeBox(); } }));
|
2018-07-10 16:41:11 +00:00
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
box->newPasswordSet(
|
2020-06-21 16:25:29 +00:00
|
|
|
) | rpl::start_to_stream(_newPasswordSet, lifetime());
|
2018-07-10 16:41:11 +00:00
|
|
|
|
|
|
|
box->recoveryExpired(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
recoverExpired();
|
|
|
|
}, lifetime());
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
_replacedBy = box;
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PasscodeBox::recoverStarted(const MTPauth_PasswordRecovery &result) {
|
2019-07-05 13:38:38 +00:00
|
|
|
_pattern = qs(result.c_auth_passwordRecovery().vemail_pattern());
|
2015-04-02 10:33:19 +00:00
|
|
|
recover();
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void PasscodeBox::recoverStartFail(const MTP::Error &error) {
|
2015-04-02 10:33:19 +00:00
|
|
|
_pattern = QString();
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 16:42:51 +00:00
|
|
|
RecoverBox::RecoverBox(
|
|
|
|
QWidget*,
|
2021-07-30 14:33:26 +00:00
|
|
|
not_null<MTP::Instance*> mtp,
|
|
|
|
Main::Session *session,
|
2018-04-20 16:42:51 +00:00
|
|
|
const QString &pattern,
|
2021-07-30 14:33:26 +00:00
|
|
|
const PasscodeBox::CloudFields &fields,
|
2021-07-30 11:32:49 +00:00
|
|
|
Fn<void()> closeParent)
|
2021-07-30 14:33:26 +00:00
|
|
|
: _session(session)
|
|
|
|
, _api(mtp)
|
2020-06-11 16:09:46 +00:00
|
|
|
, _pattern(st::normalFont->elided(tr::lng_signin_recover_hint(tr::now, lt_recover_email, pattern), st::boxWidth - st::boxPadding.left() * 1.5))
|
2021-07-30 14:33:26 +00:00
|
|
|
, _cloudFields(fields)
|
2021-07-30 11:32:49 +00:00
|
|
|
, _recoverCode(this, st::defaultInputField, tr::lng_signin_code())
|
|
|
|
, _noEmailAccess(this, tr::lng_signin_try_password(tr::now))
|
|
|
|
, _closeParent(std::move(closeParent)) {
|
2021-07-30 14:33:26 +00:00
|
|
|
if (_cloudFields.pendingResetDate != 0 || !session) {
|
2021-07-30 11:32:49 +00:00
|
|
|
_noEmailAccess.destroy();
|
|
|
|
} else {
|
|
|
|
_noEmailAccess->setClickedCallback([=] {
|
2022-02-27 08:23:20 +00:00
|
|
|
const auto reset = crl::guard(this, [=](Fn<void()> &&close) {
|
2021-07-30 11:32:49 +00:00
|
|
|
const auto closeParent = _closeParent;
|
2022-02-27 08:23:20 +00:00
|
|
|
StartPendingReset(session, this, [=, c = std::move(close)] {
|
2021-07-30 11:32:49 +00:00
|
|
|
if (closeParent) {
|
|
|
|
closeParent();
|
|
|
|
}
|
2022-02-27 08:23:20 +00:00
|
|
|
c();
|
2021-07-30 11:32:49 +00:00
|
|
|
});
|
|
|
|
});
|
2022-02-27 08:23:20 +00:00
|
|
|
getDelegate()->show(Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_cloud_password_reset_with_email(),
|
|
|
|
.confirmed = reset,
|
|
|
|
.confirmText = tr::lng_cloud_password_reset_ok(),
|
|
|
|
}));
|
2021-07-30 11:32:49 +00:00
|
|
|
});
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2015-10-12 21:02:10 +00:00
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
rpl::producer<QByteArray> RecoverBox::newPasswordSet() const {
|
|
|
|
return _newPasswordSet.events();
|
2018-07-10 16:41:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> RecoverBox::recoveryExpired() const {
|
|
|
|
return _recoveryExpired.events();
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void RecoverBox::prepare() {
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(tr::lng_signin_recover_title());
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_passcode_submit(), [=] { submit(); });
|
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2021-07-30 11:32:49 +00:00
|
|
|
setDimensions(
|
|
|
|
st::boxWidth,
|
|
|
|
(st::passcodePadding.top()
|
|
|
|
+ st::passcodePadding.bottom()
|
|
|
|
+ st::passcodeTextLine
|
|
|
|
+ _recoverCode->height()
|
|
|
|
+ st::passcodeTextLine));
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2023-08-31 11:21:24 +00:00
|
|
|
_recoverCode->changes(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
codeChanged();
|
|
|
|
}, _recoverCode->lifetime());
|
|
|
|
_recoverCode->submits(
|
|
|
|
) | rpl::start_with_next([=] { submit(); }, _recoverCode->lifetime());
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RecoverBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-11-19 14:47:28 +00:00
|
|
|
Painter p(this);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2015-10-12 21:02:10 +00:00
|
|
|
p.setFont(st::normalFont);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFg);
|
2015-10-14 11:51:37 +00:00
|
|
|
int32 w = st::boxWidth - st::boxPadding.left() * 1.5;
|
2016-12-09 18:56:01 +00:00
|
|
|
p.drawText(QRect(st::boxPadding.left(), _recoverCode->y() - st::passcodeTextLine - st::passcodePadding.top(), w, st::passcodePadding.top() + st::passcodeTextLine), _pattern, style::al_left);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
if (!_error.isEmpty()) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFgError);
|
2016-12-09 18:56:01 +00:00
|
|
|
p.drawText(QRect(st::boxPadding.left(), _recoverCode->y() + _recoverCode->height(), w, st::passcodeTextLine), _error, style::al_left);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecoverBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
2015-10-12 21:02:10 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
_recoverCode->resize(st::boxWidth - st::boxPadding.left() - st::boxPadding.right(), _recoverCode->height());
|
|
|
|
_recoverCode->moveToLeft(st::boxPadding.left(), st::passcodePadding.top() + st::passcodePadding.bottom() + st::passcodeTextLine);
|
2021-07-30 11:32:49 +00:00
|
|
|
if (_noEmailAccess) {
|
|
|
|
_noEmailAccess->moveToLeft(st::boxPadding.left(), _recoverCode->y() + _recoverCode->height() + (st::passcodeTextLine - _noEmailAccess->height()) / 2);
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void RecoverBox::setInnerFocus() {
|
2016-12-20 13:03:51 +00:00
|
|
|
_recoverCode->setFocusFast();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void RecoverBox::submit() {
|
2015-04-02 10:33:19 +00:00
|
|
|
if (_submitRequest) return;
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
QString code = _recoverCode->getLastText().trimmed();
|
2015-04-02 10:33:19 +00:00
|
|
|
if (code.isEmpty()) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_recoverCode->setFocus();
|
|
|
|
_recoverCode->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-08-17 10:52:21 +00:00
|
|
|
if (_cloudFields.turningOff) {
|
|
|
|
// From "Disable cloud password".
|
|
|
|
_submitRequest = _api.request(MTPauth_RecoverPassword(
|
|
|
|
MTP_flags(0),
|
|
|
|
MTP_string(code),
|
|
|
|
MTPaccount_PasswordInputSettings()
|
|
|
|
)).done([=](const MTPauth_Authorization &result) {
|
|
|
|
proceedToClear();
|
|
|
|
}).fail([=](const MTP::Error &error) {
|
|
|
|
checkSubmitFail(error);
|
|
|
|
}).handleFloodErrors().send();
|
|
|
|
} else {
|
|
|
|
// From "Change cloud password".
|
|
|
|
_submitRequest = _api.request(MTPauth_CheckRecoveryPassword(
|
|
|
|
MTP_string(code)
|
2021-11-26 20:54:46 +00:00
|
|
|
)).done([=] {
|
2021-08-17 10:52:21 +00:00
|
|
|
proceedToChange(code);
|
|
|
|
}).fail([=](const MTP::Error &error) {
|
|
|
|
checkSubmitFail(error);
|
|
|
|
}).handleFloodErrors().send();
|
|
|
|
}
|
2018-04-20 16:42:51 +00:00
|
|
|
});
|
2021-07-30 14:33:26 +00:00
|
|
|
if (_cloudFields.notEmptyPassport) {
|
2022-02-27 08:23:20 +00:00
|
|
|
getDelegate()->show(Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_cloud_password_passport_losing(),
|
|
|
|
.confirmed = [=](Fn<void()> &&close) { send(); close(); },
|
|
|
|
.confirmText = tr::lng_continue(),
|
|
|
|
}));
|
2018-04-20 16:42:51 +00:00
|
|
|
} else {
|
|
|
|
send();
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 11:32:49 +00:00
|
|
|
void RecoverBox::setError(const QString &error) {
|
|
|
|
_error = error;
|
|
|
|
if (_noEmailAccess) {
|
|
|
|
_noEmailAccess->setVisible(error.isEmpty());
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2021-07-30 11:32:49 +00:00
|
|
|
void RecoverBox::codeChanged() {
|
|
|
|
setError(QString());
|
|
|
|
}
|
|
|
|
|
2021-08-17 10:52:21 +00:00
|
|
|
void RecoverBox::proceedToClear() {
|
|
|
|
_submitRequest = 0;
|
|
|
|
_newPasswordSet.fire({});
|
|
|
|
getDelegate()->show(
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::MakeInformBox(tr::lng_cloud_password_removed()),
|
2021-08-17 10:52:21 +00:00
|
|
|
Ui::LayerOption::CloseOther);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecoverBox::proceedToChange(const QString &code) {
|
|
|
|
Expects(!_cloudFields.turningOff);
|
2015-04-02 10:33:19 +00:00
|
|
|
_submitRequest = 0;
|
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
auto fields = _cloudFields;
|
|
|
|
fields.fromRecoveryCode = code;
|
|
|
|
fields.hasRecovery = false;
|
|
|
|
// we could've been turning off, no need to force new password then
|
|
|
|
// like if (_cloudFields.turningOff) { just RecoverPassword else Check }
|
2022-05-06 04:27:19 +00:00
|
|
|
fields.mtp.curRequest = {};
|
|
|
|
fields.hasPassword = false;
|
2022-08-31 21:50:43 +00:00
|
|
|
fields.customCheckCallback = nullptr;
|
2021-07-30 14:33:26 +00:00
|
|
|
auto box = Box<PasscodeBox>(_session, fields);
|
|
|
|
|
|
|
|
box->boxClosing(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
const auto weak = Ui::MakeWeak(this);
|
|
|
|
if (const auto onstack = _closeParent) {
|
|
|
|
onstack();
|
|
|
|
}
|
|
|
|
if (weak) {
|
|
|
|
weak->closeBox();
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
box->newPasswordSet(
|
|
|
|
) | rpl::start_with_next([=](QByteArray &&password) {
|
|
|
|
_newPasswordSet.fire(std::move(password));
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
getDelegate()->show(std::move(box));
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
void RecoverBox::checkSubmitFail(const MTP::Error &error) {
|
2021-03-12 12:48:00 +00:00
|
|
|
if (MTP::IsFloodError(error)) {
|
2016-04-08 10:44:35 +00:00
|
|
|
_submitRequest = 0;
|
2021-07-30 11:32:49 +00:00
|
|
|
setError(tr::lng_flood_error(tr::now));
|
2016-11-11 13:46:04 +00:00
|
|
|
_recoverCode->showError();
|
2020-06-11 16:09:46 +00:00
|
|
|
return;
|
2016-04-08 10:44:35 +00:00
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
_submitRequest = 0;
|
|
|
|
|
|
|
|
const QString &err = error.type();
|
2022-11-26 21:20:17 +00:00
|
|
|
if (err == u"PASSWORD_EMPTY"_q) {
|
2021-07-30 14:33:26 +00:00
|
|
|
_newPasswordSet.fire(QByteArray());
|
2018-04-16 17:02:40 +00:00
|
|
|
getDelegate()->show(
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::MakeInformBox(tr::lng_cloud_password_removed()),
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::LayerOption::CloseOther);
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (err == u"PASSWORD_RECOVERY_NA"_q) {
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (err == u"PASSWORD_RECOVERY_EXPIRED"_q) {
|
2018-07-10 16:41:11 +00:00
|
|
|
_recoveryExpired.fire({});
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (err == u"CODE_INVALID"_q) {
|
2021-07-30 11:32:49 +00:00
|
|
|
setError(tr::lng_signin_wrong_code(tr::now));
|
2016-11-11 13:46:04 +00:00
|
|
|
_recoverCode->selectAll();
|
|
|
|
_recoverCode->setFocus();
|
|
|
|
_recoverCode->showError();
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
2021-07-30 11:32:49 +00:00
|
|
|
setError(Logs::DebugEnabled() // internal server error
|
|
|
|
? (err + ": " + error.description())
|
|
|
|
: Lang::Hard::ServerError());
|
2020-06-11 16:09:46 +00:00
|
|
|
_recoverCode->setFocus();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
2018-11-07 09:39:31 +00:00
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
RecoveryEmailValidation ConfirmRecoveryEmail(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const QString &pattern) {
|
2018-11-07 09:39:31 +00:00
|
|
|
const auto errors = std::make_shared<rpl::event_stream<QString>>();
|
|
|
|
const auto resent = std::make_shared<rpl::event_stream<QString>>();
|
|
|
|
const auto requestId = std::make_shared<mtpRequestId>(0);
|
2019-09-18 11:19:05 +00:00
|
|
|
const auto weak = std::make_shared<QPointer<Ui::BoxContent>>();
|
2018-11-07 09:39:31 +00:00
|
|
|
const auto reloads = std::make_shared<rpl::event_stream<>>();
|
|
|
|
const auto cancels = std::make_shared<rpl::event_stream<>>();
|
|
|
|
|
|
|
|
const auto submit = [=](QString code) {
|
|
|
|
if (*requestId) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-11 16:09:46 +00:00
|
|
|
*requestId = session->api().request(MTPaccount_ConfirmPasswordEmail(
|
|
|
|
MTP_string(code)
|
2021-11-26 20:54:46 +00:00
|
|
|
)).done([=] {
|
2018-11-07 09:39:31 +00:00
|
|
|
*requestId = 0;
|
|
|
|
reloads->fire({});
|
|
|
|
if (*weak) {
|
|
|
|
(*weak)->getDelegate()->show(
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::MakeInformBox(tr::lng_cloud_password_was_set()),
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::LayerOption::CloseOther);
|
2018-11-07 09:39:31 +00:00
|
|
|
}
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2018-11-07 09:39:31 +00:00
|
|
|
*requestId = 0;
|
2021-03-12 12:48:00 +00:00
|
|
|
if (MTP::IsFloodError(error)) {
|
2019-06-19 15:09:03 +00:00
|
|
|
errors->fire(tr::lng_flood_error(tr::now));
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (error.type() == u"CODE_INVALID"_q) {
|
2019-06-19 15:09:03 +00:00
|
|
|
errors->fire(tr::lng_signin_wrong_code(tr::now));
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (error.type() == u"EMAIL_HASH_EXPIRED"_q) {
|
2018-11-07 09:39:31 +00:00
|
|
|
cancels->fire({});
|
|
|
|
if (*weak) {
|
2022-02-27 08:23:20 +00:00
|
|
|
auto box = Ui::MakeInformBox(
|
2018-11-07 09:39:31 +00:00
|
|
|
Lang::Hard::EmailConfirmationExpired());
|
|
|
|
(*weak)->getDelegate()->show(
|
|
|
|
std::move(box),
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::LayerOption::CloseOther);
|
2018-11-07 09:39:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errors->fire(Lang::Hard::ServerError());
|
|
|
|
}
|
2020-06-11 16:09:46 +00:00
|
|
|
}).handleFloodErrors().send();
|
2018-11-07 09:39:31 +00:00
|
|
|
};
|
|
|
|
const auto resend = [=] {
|
|
|
|
if (*requestId) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-11 16:09:46 +00:00
|
|
|
*requestId = session->api().request(MTPaccount_ResendPasswordEmail(
|
2021-11-26 20:54:46 +00:00
|
|
|
)).done([=] {
|
2018-11-07 09:39:31 +00:00
|
|
|
*requestId = 0;
|
2019-06-19 15:09:03 +00:00
|
|
|
resent->fire(tr::lng_cloud_password_resent(tr::now));
|
2021-11-26 20:46:53 +00:00
|
|
|
}).fail([=] {
|
2018-11-07 09:39:31 +00:00
|
|
|
*requestId = 0;
|
|
|
|
errors->fire(Lang::Hard::ServerError());
|
2020-06-11 16:09:46 +00:00
|
|
|
}).send();
|
2018-11-07 09:39:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto box = Passport::VerifyEmailBox(
|
|
|
|
pattern,
|
|
|
|
0,
|
|
|
|
submit,
|
|
|
|
resend,
|
|
|
|
errors->events(),
|
|
|
|
resent->events());
|
|
|
|
|
|
|
|
*weak = box.data();
|
|
|
|
return { std::move(box), reloads->events(), cancels->events() };
|
|
|
|
}
|
2020-08-25 10:57:17 +00:00
|
|
|
|
|
|
|
[[nodiscard]] object_ptr<Ui::GenericBox> PrePasswordErrorBox(
|
2021-11-26 04:38:00 +00:00
|
|
|
const QString &error,
|
2020-08-25 10:57:17 +00:00
|
|
|
not_null<Main::Session*> session,
|
|
|
|
TextWithEntities &&about) {
|
|
|
|
const auto type = [&] {
|
2021-11-26 04:38:00 +00:00
|
|
|
if (error == u"PASSWORD_MISSING"_q) {
|
2020-08-25 10:57:17 +00:00
|
|
|
return PasswordErrorType::NoPassword;
|
2021-11-26 04:38:00 +00:00
|
|
|
} else if (error.startsWith(u"PASSWORD_TOO_FRESH_"_q)
|
|
|
|
|| error.startsWith(u"SESSION_TOO_FRESH_"_q)) {
|
2020-08-25 10:57:17 +00:00
|
|
|
return PasswordErrorType::Later;
|
|
|
|
}
|
|
|
|
return PasswordErrorType::None;
|
|
|
|
}();
|
|
|
|
if (type == PasswordErrorType::None) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Box(
|
|
|
|
TransferPasswordError,
|
|
|
|
session,
|
|
|
|
std::move(about),
|
|
|
|
type);
|
|
|
|
}
|