2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Confirm 2sv recovery email by code.

This commit is contained in:
John Preston
2018-11-07 13:39:31 +04:00
parent 93678a07a8
commit be3e43e6cb
15 changed files with 441 additions and 108 deletions

View File

@@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/self_destruction_box.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/wrap/fade_wrap.h"
#include "ui/widgets/shadow.h"
#include "ui/widgets/labels.h"
#include "calls/calls_instance.h"
@@ -30,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "auth_session.h"
#include "apiwrap.h"
#include "styles/style_settings.h"
#include "styles/style_boxes.h"
namespace Settings {
namespace {
@@ -242,12 +244,18 @@ void EditCloudPassword() {
current->notEmptyPassport,
current->hint,
current->newSecureSecret));
rpl::merge(
box->newPasswordSet() | rpl::map([] { return rpl::empty_value(); }),
box->passwordReloadNeeded()
) | rpl::start_with_next([=] {
Auth().api().reloadPasswordState();
}, box->lifetime());
box->clearUnconfirmedPassword(
) | rpl::start_with_next([=] {
Auth().api().clearUnconfirmedPassword();
}, box->lifetime());
}
void RemoveCloudPassword() {
@@ -266,6 +274,7 @@ void RemoveCloudPassword() {
current->hint,
current->newSecureSecret,
true));
rpl::merge(
box->newPasswordSet(
) | rpl::map([] { return rpl::empty_value(); }),
@@ -273,15 +282,21 @@ void RemoveCloudPassword() {
) | rpl::start_with_next([=] {
Auth().api().reloadPasswordState();
}, box->lifetime());
box->clearUnconfirmedPassword(
) | rpl::start_with_next([=] {
Auth().api().clearUnconfirmedPassword();
}, box->lifetime());
}
void SetupCloudPassword(not_null<Ui::VerticalLayout*> container) {
using namespace rpl::mappers;
using State = Core::CloudPasswordState;
AddDivider(container);
AddSkip(container);
AddSubsectionTitle(container, lng_settings_password_title);
using State = Core::CloudPasswordState;
auto has = rpl::single(
false
) | rpl::then(Auth().api().passwordState(
@@ -301,7 +316,7 @@ void SetupCloudPassword(not_null<Ui::VerticalLayout*> container) {
) | rpl::filter([](const QString &pattern) {
return !pattern.isEmpty();
}) | rpl::map([](const QString &pattern) {
return lng_cloud_password_waiting(lt_email, pattern);
return lng_cloud_password_waiting_code(lt_email, pattern);
}));
auto unconfirmed = rpl::single(
true
@@ -346,7 +361,7 @@ void SetupCloudPassword(not_null<Ui::VerticalLayout*> container) {
container,
std::move(text),
st::settingsButton)));
change->toggleOn(std::move(
change->toggleOn(rpl::duplicate(
unconfirmed
) | rpl::map([](bool unconfirmed) {
return !unconfirmed;
@@ -357,6 +372,40 @@ void SetupCloudPassword(not_null<Ui::VerticalLayout*> container) {
}
});
const auto confirm = container->add(
object_ptr<Ui::SlideWrap<Button>>(
container,
object_ptr<Button>(
container,
Lang::Viewer(lng_cloud_password_confirm),
st::settingsButton)));
confirm->toggleOn(rpl::duplicate(
unconfirmed
))->setDuration(0);
confirm->entity()->addClickHandler([] {
const auto state = Auth().api().passwordStateCurrent();
auto validation = ConfirmRecoveryEmail(state->unconfirmedPattern);
std::move(
validation.reloadRequests
) | rpl::start_with_next([] {
Auth().api().reloadPasswordState();
}, validation.box->lifetime());
std::move(
validation.cancelRequests
) | rpl::start_with_next([] {
Auth().api().clearUnconfirmedPassword();
}, validation.box->lifetime());
Ui::show(std::move(validation.box));
});
const auto remove = [] {
if (CheckEditCloudPassword()) {
RemoveCloudPassword();
}
};
const auto disable = container->add(
object_ptr<Ui::SlideWrap<Button>>(
container,
@@ -364,12 +413,24 @@ void SetupCloudPassword(not_null<Ui::VerticalLayout*> container) {
container,
Lang::Viewer(lng_settings_password_disable),
st::settingsButton)));
disable->toggleOn(base::duplicate(has));
disable->entity()->addClickHandler([] {
if (CheckEditCloudPassword()) {
RemoveCloudPassword();
}
});
disable->toggleOn(rpl::combine(
rpl::duplicate(has),
rpl::duplicate(unconfirmed),
_1 && !_2));
disable->entity()->addClickHandler(remove);
const auto abort = container->add(
object_ptr<Ui::SlideWrap<Button>>(
container,
object_ptr<Button>(
container,
Lang::Viewer(lng_settings_password_abort),
st::settingsAttentionButton)));
abort->toggleOn(rpl::combine(
rpl::duplicate(has),
rpl::duplicate(unconfirmed),
_1 && _2));
abort->entity()->addClickHandler(remove);
const auto reloadOnActivation = [=](Qt::ApplicationState state) {
if (label->toggled() && state == Qt::ApplicationActive) {