From 5cb44834dcfb6740fe0744a1482dd99e0fb1b1c3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 18 Apr 2018 12:42:15 +0400 Subject: [PATCH] Allow restoring password by email in passport. --- .../passport/passport_form_controller.cpp | 33 +++++++++++++++++++ .../passport/passport_form_controller.h | 2 ++ .../passport/passport_panel_controller.cpp | 4 +++ .../passport/passport_panel_controller.h | 1 + .../passport/passport_panel_password.cpp | 8 +++++ .../passport/passport_panel_password.h | 1 + 6 files changed, 49 insertions(+) diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index 53da4d1a3a..fefa5a7b21 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "passport/passport_encryption.h" #include "passport/passport_panel_controller.h" #include "boxes/confirm_box.h" +#include "boxes/passcode_box.h" #include "lang/lang_keys.h" #include "lang/lang_hardcoded.h" #include "base/openssl_help.h" @@ -392,6 +393,38 @@ void FormController::submitPassword(const QString &password) { }).send(); } +void FormController::recoverPassword() { + if (!_password.hasRecovery) { + _view->show(Box(lang(lng_signin_no_email_forgot))); + return; + } else if (_recoverRequestId) { + return; + } + _recoverRequestId = request(MTPauth_RequestPasswordRecovery( + )).done([=](const MTPauth_PasswordRecovery &result) { + Expects(result.type() == mtpc_auth_passwordRecovery); + + _recoverRequestId = 0; + + const auto &data = result.c_auth_passwordRecovery(); + const auto pattern = qs(data.vemail_pattern); + const auto box = _view->show(Box(pattern)); + box->connect(box, &RecoverBox::reloadPassword, [=] { + reloadPassword(); + }); + box->connect(box, &RecoverBox::recoveryExpired, [=] { + if (box) { + box->closeBox(); + } + }); + }).fail([=](const RPCError &error) { + _recoverRequestId = 0; + _view->show(Box(Lang::Hard::ServerError() + + '\n' + + error.type())); + }).send(); +} + void FormController::reloadPassword() { requestPassword(); } diff --git a/Telegram/SourceFiles/passport/passport_form_controller.h b/Telegram/SourceFiles/passport/passport_form_controller.h index ef355bbbf5..d66eb503d7 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.h +++ b/Telegram/SourceFiles/passport/passport_form_controller.h @@ -233,6 +233,7 @@ public: QString privacyPolicyUrl() const; std::vector> submitGetErrors(); void submitPassword(const QString &password); + void recoverPassword(); rpl::producer passwordError() const; const PasswordSettings &passwordSettings() const; void reloadPassword(); @@ -391,6 +392,7 @@ private: PasswordSettings _password; Form _form; bool _cancelled = false; + mtpRequestId _recoverRequestId = 0; std::map> _fileLoaders; rpl::event_stream> _scanUpdated; diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.cpp b/Telegram/SourceFiles/passport/passport_panel_controller.cpp index f32011a72e..8c39edb215 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_controller.cpp @@ -400,6 +400,10 @@ void PanelController::submitPassword(const QString &password) { _form->submitPassword(password); } +void PanelController::recoverPassword() { + _form->recoverPassword(); +} + rpl::producer PanelController::passwordError() const { return _form->passwordError(); } diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.h b/Telegram/SourceFiles/passport/passport_panel_controller.h index f2bf6fa197..cd054edd63 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.h +++ b/Telegram/SourceFiles/passport/passport_panel_controller.h @@ -67,6 +67,7 @@ public: QString privacyPolicyUrl() const; void submitForm(); void submitPassword(const QString &password); + void recoverPassword(); rpl::producer passwordError() const; QString passwordHint() const; QString unconfirmedEmailPattern() const; diff --git a/Telegram/SourceFiles/passport/passport_panel_password.cpp b/Telegram/SourceFiles/passport/passport_panel_password.cpp index 5596c01ae4..9fc5fb7888 100644 --- a/Telegram/SourceFiles/passport/passport_panel_password.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_password.cpp @@ -65,6 +65,10 @@ PanelAskPassword::PanelAskPassword( showError(error); }, lifetime()); + _forgot->addClickHandler([=] { + recover(); + }); + _password->setFocusFast(); _userpic->setAttribute(Qt::WA_TransparentForMouseEvents); @@ -92,6 +96,10 @@ void PanelAskPassword::submit() { _controller->submitPassword(_password->getLastText()); } +void PanelAskPassword::recover() { + _controller->recoverPassword(); +} + void PanelAskPassword::resizeEvent(QResizeEvent *e) { updateControlsGeometry(); } diff --git a/Telegram/SourceFiles/passport/passport_panel_password.h b/Telegram/SourceFiles/passport/passport_panel_password.h index 14de59bfd3..17566181b7 100644 --- a/Telegram/SourceFiles/passport/passport_panel_password.h +++ b/Telegram/SourceFiles/passport/passport_panel_password.h @@ -38,6 +38,7 @@ private: void updateControlsGeometry(); void showError(const QString &error); void hideError(); + void recover(); not_null _controller;