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
|
|
|
*/
|
2016-03-16 11:54:37 +00:00
|
|
|
#include "intro/intropwdcheck.h"
|
|
|
|
|
2016-10-28 12:44:28 +00:00
|
|
|
#include "styles/style_intro.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "core/file_utilities.h"
|
2018-08-03 21:48:00 +00:00
|
|
|
#include "core/core_cloud_password.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-03-16 11:54:37 +00:00
|
|
|
#include "intro/introsignup.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2018-08-03 21:48:00 +00:00
|
|
|
#include "base/openssl_help.h"
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
namespace Intro {
|
|
|
|
|
2018-08-03 21:48:00 +00:00
|
|
|
PwdCheckWidget::PwdCheckWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
Widget::Data *data)
|
|
|
|
: Step(parent, data)
|
2018-08-10 19:19:46 +00:00
|
|
|
, _request(getData()->pwdRequest)
|
2016-11-24 19:28:23 +00:00
|
|
|
, _hasRecovery(getData()->hasRecovery)
|
2018-04-20 16:42:51 +00:00
|
|
|
, _notEmptyPassport(getData()->pwdNotEmptyPassport)
|
2016-11-24 19:28:23 +00:00
|
|
|
, _hint(getData()->pwdHint)
|
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))
|
|
|
|
, _toPassword(this, tr::lng_signin_try_password(tr::now))
|
2016-11-04 19:50:35 +00:00
|
|
|
, _checkRequest(this) {
|
2018-08-10 19:19:46 +00:00
|
|
|
Expects(!!_request);
|
2018-08-03 21:48:00 +00:00
|
|
|
|
2017-05-30 13:54:05 +00:00
|
|
|
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
|
|
|
|
|
2016-11-04 19:50:35 +00:00
|
|
|
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
|
|
|
|
connect(_toRecover, SIGNAL(clicked()), this, SLOT(onToRecover()));
|
|
|
|
connect(_toPassword, SIGNAL(clicked()), this, SLOT(onToPassword()));
|
|
|
|
connect(_pwdField, SIGNAL(changed()), this, SLOT(onInputChange()));
|
|
|
|
connect(_codeField, SIGNAL(changed()), this, SLOT(onInputChange()));
|
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();
|
|
|
|
setErrorBelowLink(true);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
if (_hint.isEmpty()) {
|
|
|
|
_pwdHint->hide();
|
|
|
|
} else {
|
2019-06-19 16:39:25 +00:00
|
|
|
_pwdHint->setText(
|
|
|
|
tr::lng_signin_hint(tr::now, lt_password_hint, _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);
|
|
|
|
}
|
|
|
|
|
2017-05-30 13:54:05 +00:00
|
|
|
void PwdCheckWidget::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));
|
|
|
|
}
|
2017-05-30 17:58:25 +00:00
|
|
|
if (!_hint.isEmpty()) {
|
2019-06-19 16:39:25 +00:00
|
|
|
_pwdHint->setText(
|
|
|
|
tr::lng_signin_hint(tr::now, lt_password_hint, _hint));
|
2017-05-30 17:58:25 +00:00
|
|
|
}
|
2017-05-30 13:54:05 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PwdCheckWidget::resizeEvent(QResizeEvent *e) {
|
|
|
|
Step::resizeEvent(e);
|
2017-05-30 13:54:05 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PwdCheckWidget::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
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PwdCheckWidget::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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PwdCheckWidget::activate() {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PwdCheckWidget::cancelled() {
|
2018-08-10 19:19:46 +00:00
|
|
|
request(base::take(_sentRequest)).cancel();
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PwdCheckWidget::stopCheck() {
|
2016-11-04 19:50:35 +00:00
|
|
|
_checkRequest->stop();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PwdCheckWidget::onCheckRequest() {
|
2016-12-09 18:56:01 +00:00
|
|
|
auto status = MTP::state(_sentRequest);
|
2015-04-02 10:33:19 +00:00
|
|
|
if (status < 0) {
|
2016-12-09 18:56:01 +00:00
|
|
|
auto leftms = -status;
|
2015-04-02 10:33:19 +00:00
|
|
|
if (leftms >= 1000) {
|
2018-08-10 19:19:46 +00:00
|
|
|
request(base::take(_sentRequest)).cancel();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-04 19:50:35 +00:00
|
|
|
if (!_sentRequest && status == MTP::RequestSent) {
|
2015-04-02 10:33:19 +00:00
|
|
|
stopCheck();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PwdCheckWidget::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
|
|
|
stopCheck();
|
|
|
|
if (recover) {
|
|
|
|
cSetPasswordRecovered(true);
|
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
auto &d = result.c_auth_authorization();
|
2015-10-29 00:16:52 +00:00
|
|
|
if (d.vuser.type() != mtpc_user || !d.vuser.c_user().is_self()) { // wtf?
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(rpl::single(Lang::Hard::ServerError()));
|
2015-04-02 10:33:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
finish(d.vuser);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 19:19:46 +00:00
|
|
|
void PwdCheckWidget::pwdSubmitFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isFloodError(error)) {
|
2016-11-04 19:50:35 +00:00
|
|
|
_sentRequest = 0;
|
2016-04-08 10:44:35 +00:00
|
|
|
stopCheck();
|
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;
|
2015-04-02 10:33:19 +00:00
|
|
|
stopCheck();
|
2018-11-20 10:59:47 +00:00
|
|
|
const auto &type = error.type();
|
|
|
|
if (type == qstr("PASSWORD_HASH_INVALID")
|
|
|
|
|| type == qstr("SRP_PASSWORD_CHANGED")) {
|
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();
|
2018-11-20 10:59:47 +00:00
|
|
|
} else if (type == qstr("PASSWORD_EMPTY")
|
|
|
|
|| type == qstr("AUTH_KEY_UNREGISTERED")) {
|
2016-11-24 19:28:23 +00:00
|
|
|
goBack();
|
2018-11-20 10:59:47 +00:00
|
|
|
} else if (type == qstr("SRP_ID_INVALID")) {
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PwdCheckWidget::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) {
|
|
|
|
_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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 19:19:46 +00:00
|
|
|
void PwdCheckWidget::checkPasswordHash() {
|
|
|
|
if (_request.id) {
|
|
|
|
passwordChecked();
|
|
|
|
} else {
|
|
|
|
requestPasswordData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PwdCheckWidget::requestPasswordData() {
|
|
|
|
request(base::take(_sentRequest)).cancel();
|
|
|
|
_sentRequest = request(
|
|
|
|
MTPaccount_GetPassword()
|
|
|
|
).done([=](const MTPaccount_Password &result) {
|
|
|
|
_sentRequest = 0;
|
|
|
|
result.match([&](const MTPDaccount_password &data) {
|
|
|
|
_request = Core::ParseCloudPasswordCheckRequest(data);
|
|
|
|
passwordChecked();
|
|
|
|
});
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PwdCheckWidget::passwordChecked() {
|
|
|
|
if (!_request || !_request.id) {
|
|
|
|
return serverError();
|
|
|
|
}
|
|
|
|
const auto check = Core::ComputeCloudPasswordCheck(
|
|
|
|
_request,
|
|
|
|
_passwordHash);
|
|
|
|
if (!check) {
|
|
|
|
return serverError();
|
|
|
|
}
|
|
|
|
_request.id = 0;
|
|
|
|
_sentRequest = request(
|
|
|
|
MTPauth_CheckPassword(check.result)
|
|
|
|
).done([=](const MTPauth_Authorization &result) {
|
|
|
|
pwdSubmitDone(false, result);
|
|
|
|
}).handleFloodErrors().fail([=](const RPCError &error) {
|
|
|
|
pwdSubmitFail(error);
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PwdCheckWidget::serverError() {
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(rpl::single(Lang::Hard::ServerError()));
|
2018-08-10 19:19:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PwdCheckWidget::codeSubmitFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
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;
|
2015-04-02 10:33:19 +00:00
|
|
|
stopCheck();
|
2018-11-20 10:59:47 +00:00
|
|
|
const auto &type = error.type();
|
|
|
|
if (type == qstr("PASSWORD_EMPTY")
|
|
|
|
|| type == qstr("AUTH_KEY_UNREGISTERED")) {
|
2016-11-24 19:28:23 +00:00
|
|
|
goBack();
|
2018-11-20 10:59:47 +00:00
|
|
|
} else if (type == qstr("PASSWORD_RECOVERY_NA")) {
|
2015-04-02 10:33:19 +00:00
|
|
|
recoverStartFail(error);
|
2018-11-20 10:59:47 +00:00
|
|
|
} else if (type == qstr("PASSWORD_RECOVERY_EXPIRED")) {
|
2015-04-02 10:33:19 +00:00
|
|
|
_emailPattern = QString();
|
|
|
|
onToPassword();
|
2018-11-20 10:59:47 +00:00
|
|
|
} else if (type == qstr("CODE_INVALID")) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PwdCheckWidget::recoverStarted(const MTPauth_PasswordRecovery &result) {
|
|
|
|
_emailPattern = qs(result.c_auth_passwordRecovery().vemail_pattern);
|
|
|
|
updateDescriptionText();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 19:19:46 +00:00
|
|
|
void PwdCheckWidget::recoverStartFail(const RPCError &error) {
|
2015-04-02 10:33:19 +00:00
|
|
|
stopCheck();
|
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
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PwdCheckWidget::onToRecover() {
|
2015-04-04 20:01:34 +00:00
|
|
|
if (_hasRecovery) {
|
2016-11-04 19:50:35 +00:00
|
|
|
if (_sentRequest) {
|
2018-08-10 19:19:46 +00:00
|
|
|
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()) {
|
2018-08-10 19:19:46 +00:00
|
|
|
request(
|
|
|
|
MTPauth_RequestPasswordRecovery()
|
|
|
|
).done([=](const MTPauth_PasswordRecovery &result) {
|
|
|
|
recoverStarted(result);
|
|
|
|
}).fail([=](const RPCError &error) {
|
|
|
|
recoverStartFail(error);
|
|
|
|
}).send();
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::show(Box<InformBox>(tr::lng_signin_no_email_forgot(tr::now), [this] { showReset(); }));
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PwdCheckWidget::onToPassword() {
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::show(Box<InformBox>(tr::lng_signin_cant_email_forgot(tr::now), [this] { showReset(); }));
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void PwdCheckWidget::showReset() {
|
2016-11-04 19:50:35 +00:00
|
|
|
if (_sentRequest) {
|
2018-08-10 19:19:46 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PwdCheckWidget::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
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PwdCheckWidget::onInputChange() {
|
|
|
|
hideError();
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PwdCheckWidget::submit() {
|
2016-11-04 19:50:35 +00:00
|
|
|
if (_sentRequest) return;
|
|
|
|
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, [=] {
|
2018-08-10 19:19:46 +00:00
|
|
|
_sentRequest = request(
|
|
|
|
MTPauth_RecoverPassword(MTP_string(code))
|
|
|
|
).done([=](const MTPauth_Authorization &result) {
|
|
|
|
pwdSubmitDone(true, result);
|
|
|
|
}).handleFloodErrors().fail([=](const RPCError &error) {
|
|
|
|
codeSubmitFail(error);
|
|
|
|
}).send();
|
2018-04-20 16:42:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (_notEmptyPassport) {
|
|
|
|
const auto box = std::make_shared<QPointer<BoxContent>>();
|
|
|
|
const auto confirmed = [=] {
|
|
|
|
send();
|
|
|
|
if (*box) {
|
|
|
|
(*box)->closeBox();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
*box = Ui::show(Box<ConfirmBox>(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_cloud_password_passport_losing(tr::now),
|
|
|
|
tr::lng_continue(tr::now),
|
2018-04-20 16:42:51 +00:00
|
|
|
confirmed));
|
|
|
|
} 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(
|
|
|
|
_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-06-18 16:53:27 +00:00
|
|
|
rpl::producer<QString> PwdCheckWidget::nextButtonText() const {
|
|
|
|
return tr::lng_intro_submit();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
|
|
|
|
} // namespace Intro
|