Allow restoring password by email in passport.

This commit is contained in:
John Preston 2018-04-18 12:42:15 +04:00
parent 6795ecea61
commit 5cb44834dc
6 changed files with 49 additions and 0 deletions

View File

@ -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<InformBox>(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<RecoverBox>(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<InformBox>(Lang::Hard::ServerError()
+ '\n'
+ error.type()));
}).send();
}
void FormController::reloadPassword() {
requestPassword();
}

View File

@ -233,6 +233,7 @@ public:
QString privacyPolicyUrl() const;
std::vector<not_null<const Value*>> submitGetErrors();
void submitPassword(const QString &password);
void recoverPassword();
rpl::producer<QString> 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<FileKey, std::unique_ptr<mtpFileLoader>> _fileLoaders;
rpl::event_stream<not_null<const EditFile*>> _scanUpdated;

View File

@ -400,6 +400,10 @@ void PanelController::submitPassword(const QString &password) {
_form->submitPassword(password);
}
void PanelController::recoverPassword() {
_form->recoverPassword();
}
rpl::producer<QString> PanelController::passwordError() const {
return _form->passwordError();
}

View File

@ -67,6 +67,7 @@ public:
QString privacyPolicyUrl() const;
void submitForm();
void submitPassword(const QString &password);
void recoverPassword();
rpl::producer<QString> passwordError() const;
QString passwordHint() const;
QString unconfirmedEmailPattern() const;

View File

@ -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();
}

View File

@ -38,6 +38,7 @@ private:
void updateControlsGeometry();
void showError(const QString &error);
void hideError();
void recover();
not_null<PanelController*> _controller;