2014-05-30 08:53: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.
|
2014-05-30 08:53: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
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2019-11-27 09:45:23 +00:00
|
|
|
#include "intro/intro_code.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2019-11-27 09:45:23 +00:00
|
|
|
#include "intro/intro_signup.h"
|
|
|
|
#include "intro/intro_password_check.h"
|
2018-08-03 21:48:00 +00:00
|
|
|
#include "core/update_checker.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2019-06-12 20:11:41 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2018-08-03 21:48:00 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2020-06-11 13:07:14 +00:00
|
|
|
#include "main/main_account.h"
|
|
|
|
#include "mtproto/mtp_instance.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "app.h"
|
2016-10-28 12:44:28 +00:00
|
|
|
#include "styles/style_intro.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
namespace Intro {
|
2019-11-26 11:10:44 +00:00
|
|
|
namespace details {
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2018-11-19 12:15:59 +00:00
|
|
|
CodeInput::CodeInput(
|
|
|
|
QWidget *parent,
|
|
|
|
const style::InputField &st,
|
2019-06-18 14:07:45 +00:00
|
|
|
rpl::producer<QString> placeholder)
|
|
|
|
: Ui::MaskedInputField(parent, st, std::move(placeholder)) {
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CodeInput::setDigitsCountMax(int digitsCount) {
|
|
|
|
_digitsCountMax = digitsCount;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeInput::correctValue(const QString &was, int wasCursor, QString &now, int &nowCursor) {
|
2015-10-06 19:49:23 +00:00
|
|
|
QString newText;
|
2016-11-24 19:28:23 +00:00
|
|
|
int oldPos(nowCursor), newPos(-1), oldLen(now.length()), digitCount = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
for (int i = 0; i < oldLen; ++i) {
|
2015-10-06 19:49:23 +00:00
|
|
|
if (now[i].isDigit()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
++digitCount;
|
|
|
|
}
|
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
accumulate_min(digitCount, _digitsCountMax);
|
|
|
|
auto strict = (digitCount == _digitsCountMax);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
newText.reserve(oldLen);
|
|
|
|
for (int i = 0; i < oldLen; ++i) {
|
2015-10-06 19:49:23 +00:00
|
|
|
QChar ch(now[i]);
|
2014-05-30 08:53:19 +00:00
|
|
|
if (ch.isDigit()) {
|
|
|
|
if (!digitCount--) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
newText += ch;
|
|
|
|
if (strict && !digitCount) {
|
|
|
|
break;
|
|
|
|
}
|
2018-11-19 12:15:59 +00:00
|
|
|
} else if (ch == '-') {
|
|
|
|
newText += ch;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
if (i == oldPos) {
|
|
|
|
newPos = newText.length();
|
|
|
|
}
|
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
if (newPos < 0 || newPos > newText.size()) {
|
|
|
|
newPos = newText.size();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-10-06 19:49:23 +00:00
|
|
|
if (newText != now) {
|
|
|
|
now = newText;
|
|
|
|
setText(now);
|
2016-12-09 18:56:01 +00:00
|
|
|
startPlaceholderAnimation();
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
if (newPos != nowCursor) {
|
|
|
|
nowCursor = newPos;
|
|
|
|
setCursorPosition(nowCursor);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:46:23 +00:00
|
|
|
CodeWidget::CodeWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Main::Account*> account,
|
2019-11-26 11:10:44 +00:00
|
|
|
not_null<Data*> data)
|
2019-07-24 08:46:23 +00:00
|
|
|
: Step(parent, account, data)
|
2019-06-19 15:09:03 +00:00
|
|
|
, _noTelegramCode(this, tr::lng_code_no_telegram(tr::now), st::introLink)
|
2019-06-18 14:07:45 +00:00
|
|
|
, _code(this, st::introCode, tr::lng_code_ph())
|
2019-11-27 08:33:18 +00:00
|
|
|
, _callTimer([=] { sendCall(); })
|
2016-11-24 19:28:23 +00:00
|
|
|
, _callStatus(getData()->callStatus)
|
|
|
|
, _callTimeout(getData()->callTimeout)
|
2016-12-23 13:21:01 +00:00
|
|
|
, _callLabel(this, st::introDescription)
|
2019-11-27 08:33:18 +00:00
|
|
|
, _checkRequestTimer([=] { checkRequest(); }) {
|
2020-09-30 09:11:44 +00:00
|
|
|
Lang::Updated(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
refreshLang();
|
|
|
|
}, lifetime());
|
2017-05-30 13:54:05 +00:00
|
|
|
|
2019-11-27 08:33:18 +00:00
|
|
|
connect(_code, &CodeInput::changed, [=] { codeChanged(); });
|
|
|
|
_noTelegramCode->addClickHandler([=] { noTelegramCode(); });
|
2015-08-31 14:27:20 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
_code->setDigitsCountMax(getData()->codeLength);
|
2016-03-14 16:59:18 +00:00
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
setTitleText(rpl::single(App::formatPhone(getData()->phone)));
|
2017-05-30 13:54:05 +00:00
|
|
|
updateDescText();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::refreshLang() {
|
2019-11-27 08:33:18 +00:00
|
|
|
if (_noTelegramCode) {
|
|
|
|
_noTelegramCode->setText(tr::lng_code_no_telegram(tr::now));
|
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
updateDescText();
|
2017-05-30 13:54:05 +00:00
|
|
|
updateControlsGeometry();
|
2015-08-31 14:27:20 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 14:27:09 +00:00
|
|
|
int CodeWidget::errorTop() const {
|
|
|
|
return contentTop() + st::introErrorBelowLinkTop;
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeWidget::updateDescText() {
|
2019-06-12 20:11:41 +00:00
|
|
|
const auto byTelegram = getData()->codeByTelegram;
|
2019-06-18 16:53:27 +00:00
|
|
|
setDescriptionText(
|
|
|
|
(byTelegram ? tr::lng_code_from_telegram : tr::lng_code_desc)(
|
|
|
|
Ui::Text::RichLangValue));
|
2016-11-24 19:28:23 +00:00
|
|
|
if (getData()->codeByTelegram) {
|
2016-11-04 19:50:35 +00:00
|
|
|
_noTelegramCode->show();
|
2019-11-27 08:33:18 +00:00
|
|
|
_callTimer.cancel();
|
2015-08-31 14:27:20 +00:00
|
|
|
} else {
|
2016-11-04 19:50:35 +00:00
|
|
|
_noTelegramCode->hide();
|
2016-11-24 19:28:23 +00:00
|
|
|
_callStatus = getData()->callStatus;
|
|
|
|
_callTimeout = getData()->callTimeout;
|
2019-11-27 08:33:18 +00:00
|
|
|
if (_callStatus == CallStatus::Waiting && !_callTimer.isActive()) {
|
|
|
|
_callTimer.callEach(1000);
|
2015-08-31 14:27:20 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
updateCallText();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeWidget::updateCallText() {
|
|
|
|
auto text = ([this]() -> QString {
|
|
|
|
if (getData()->codeByTelegram) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
switch (_callStatus) {
|
2019-11-26 11:10:44 +00:00
|
|
|
case CallStatus::Waiting: {
|
2016-11-24 19:28:23 +00:00
|
|
|
if (_callTimeout >= 3600) {
|
2019-06-19 16:39:25 +00:00
|
|
|
return tr::lng_code_call(
|
|
|
|
tr::now,
|
|
|
|
lt_minutes,
|
|
|
|
qsl("%1:%2"
|
|
|
|
).arg(_callTimeout / 3600
|
|
|
|
).arg((_callTimeout / 60) % 60, 2, 10, QChar('0')),
|
|
|
|
lt_seconds,
|
|
|
|
qsl("%1").arg(_callTimeout % 60, 2, 10, QChar('0')));
|
2016-03-15 19:38:30 +00:00
|
|
|
} else {
|
2019-06-19 16:39:25 +00:00
|
|
|
return tr::lng_code_call(
|
|
|
|
tr::now,
|
|
|
|
lt_minutes,
|
|
|
|
QString::number(_callTimeout / 60),
|
|
|
|
lt_seconds,
|
|
|
|
qsl("%1").arg(_callTimeout % 60, 2, 10, QChar('0')));
|
2016-03-15 19:38:30 +00:00
|
|
|
}
|
|
|
|
} break;
|
2019-11-26 11:10:44 +00:00
|
|
|
case CallStatus::Calling:
|
2019-06-19 16:39:25 +00:00
|
|
|
return tr::lng_code_calling(tr::now);
|
2019-11-26 11:10:44 +00:00
|
|
|
case CallStatus::Called:
|
2019-06-19 16:39:25 +00:00
|
|
|
return tr::lng_code_called(tr::now);
|
2016-03-15 19:38:30 +00:00
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
return QString();
|
|
|
|
})();
|
|
|
|
_callLabel->setText(text);
|
|
|
|
_callLabel->setVisible(!text.isEmpty() && !animating());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeWidget::resizeEvent(QResizeEvent *e) {
|
|
|
|
Step::resizeEvent(e);
|
2017-05-30 13:54:05 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeWidget::updateControlsGeometry() {
|
2016-11-24 19:28:23 +00:00
|
|
|
_code->moveToLeft(contentLeft(), contentTop() + st::introStepFieldTop);
|
|
|
|
auto linkTop = _code->y() + _code->height() + st::introLinkTop;
|
|
|
|
_noTelegramCode->moveToLeft(contentLeft() + st::buttonRadius, linkTop);
|
|
|
|
_callLabel->moveToLeft(contentLeft() + st::buttonRadius, linkTop);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
void CodeWidget::showCodeError(rpl::producer<QString> text) {
|
|
|
|
_code->showError();
|
|
|
|
showError(std::move(text));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeWidget::setInnerFocus() {
|
2016-12-23 13:21:01 +00:00
|
|
|
_code->setFocusFast();
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeWidget::activate() {
|
|
|
|
Step::activate();
|
|
|
|
_code->show();
|
|
|
|
if (getData()->codeByTelegram) {
|
|
|
|
_noTelegramCode->show();
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2016-11-24 19:28:23 +00:00
|
|
|
_callLabel->show();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
setInnerFocus();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeWidget::finished() {
|
|
|
|
Step::finished();
|
2019-11-27 08:33:18 +00:00
|
|
|
_checkRequestTimer.cancel();
|
|
|
|
_callTimer.cancel();
|
2020-06-11 13:07:14 +00:00
|
|
|
apiClear();
|
2016-03-14 16:59:18 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
cancelled();
|
2016-11-04 19:50:35 +00:00
|
|
|
_sentCode.clear();
|
|
|
|
_code->setText(QString());
|
2016-03-14 16:59:18 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeWidget::cancelled() {
|
2020-06-17 09:36:25 +00:00
|
|
|
api().request(base::take(_sentRequest)).cancel();
|
|
|
|
api().request(base::take(_callRequestId)).cancel();
|
|
|
|
api().request(MTPauth_CancelCode(
|
2020-06-11 13:07:14 +00:00
|
|
|
MTP_string(getData()->phone),
|
|
|
|
MTP_bytes(getData()->phoneHash)
|
|
|
|
)).send();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeWidget::stopCheck() {
|
2019-11-27 08:33:18 +00:00
|
|
|
_checkRequestTimer.cancel();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 08:33:18 +00:00
|
|
|
void CodeWidget::checkRequest() {
|
2020-06-17 09:36:25 +00:00
|
|
|
auto status = api().instance().state(_sentRequest);
|
2014-05-30 08:53:19 +00:00
|
|
|
if (status < 0) {
|
2016-12-09 18:56:01 +00:00
|
|
|
auto leftms = -status;
|
2014-05-30 08:53:19 +00:00
|
|
|
if (leftms >= 1000) {
|
2016-11-04 19:50:35 +00:00
|
|
|
if (_sentRequest) {
|
2020-06-17 09:36:25 +00:00
|
|
|
api().request(base::take(_sentRequest)).cancel();
|
2016-11-04 19:50:35 +00:00
|
|
|
_sentCode.clear();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-04 19:50:35 +00:00
|
|
|
if (!_sentRequest && status == MTP::RequestSent) {
|
2014-05-30 08:53:19 +00:00
|
|
|
stopCheck();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeWidget::codeSubmitDone(const MTPauth_Authorization &result) {
|
2014-05-30 08:53:19 +00:00
|
|
|
stopCheck();
|
2016-11-04 19:50:35 +00:00
|
|
|
_sentRequest = 0;
|
2019-07-15 13:57:49 +00:00
|
|
|
result.match([&](const MTPDauth_authorization &data) {
|
|
|
|
if (data.vuser().type() != mtpc_user
|
|
|
|
|| !data.vuser().c_user().is_self()) {
|
2019-11-22 09:40:52 +00:00
|
|
|
showError(rpl::single(Lang::Hard::ServerError()));
|
2019-07-15 13:57:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
finish(data.vuser());
|
|
|
|
}, [&](const MTPDauth_authorizationSignUpRequired &data) {
|
|
|
|
if (const auto terms = data.vterms_of_service()) {
|
|
|
|
terms->match([&](const MTPDhelp_termsOfService &data) {
|
2020-06-08 08:03:45 +00:00
|
|
|
getData()->termsLock = Window::TermsLock::FromMTP(
|
|
|
|
nullptr,
|
|
|
|
data);
|
2019-07-15 13:57:49 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
getData()->termsLock = Window::TermsLock();
|
|
|
|
}
|
2020-06-23 14:55:08 +00:00
|
|
|
goReplace<SignupWidget>(Animate::Forward);
|
2019-07-15 13:57:49 +00:00
|
|
|
});
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void CodeWidget::codeSubmitFail(const MTP::Error &error) {
|
|
|
|
if (MTP::IsFloodError(error)) {
|
2016-04-08 10:44:35 +00:00
|
|
|
stopCheck();
|
2016-11-04 19:50:35 +00:00
|
|
|
_sentRequest = 0;
|
2019-06-18 16:53:27 +00:00
|
|
|
showCodeError(tr::lng_flood_error());
|
2020-06-11 13:07:14 +00:00
|
|
|
return;
|
2016-04-08 10:44:35 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
stopCheck();
|
2016-11-04 19:50:35 +00:00
|
|
|
_sentRequest = 0;
|
2016-12-09 18:56:01 +00:00
|
|
|
auto &err = error.type();
|
2019-06-05 17:43:21 +00:00
|
|
|
if (err == qstr("PHONE_NUMBER_INVALID")
|
|
|
|
|| err == qstr("PHONE_CODE_EXPIRED")
|
|
|
|
|| err == qstr("PHONE_NUMBER_BANNED")) { // show error
|
2016-11-24 19:28:23 +00:00
|
|
|
goBack();
|
2016-04-08 10:44:35 +00:00
|
|
|
} else if (err == qstr("PHONE_CODE_EMPTY") || err == qstr("PHONE_CODE_INVALID")) {
|
2019-06-18 16:53:27 +00:00
|
|
|
showCodeError(tr::lng_bad_code());
|
2016-04-08 10:44:35 +00:00
|
|
|
} else if (err == qstr("SESSION_PASSWORD_NEEDED")) {
|
2019-11-27 08:33:18 +00:00
|
|
|
_checkRequestTimer.callEach(1000);
|
2020-06-17 09:36:25 +00:00
|
|
|
_sentRequest = api().request(MTPaccount_GetPassword(
|
2020-06-11 13:07:14 +00:00
|
|
|
)).done([=](const MTPaccount_Password &result) {
|
|
|
|
gotPassword(result);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2020-06-11 13:07:14 +00:00
|
|
|
codeSubmitFail(error);
|
|
|
|
}).handleFloodErrors().send();
|
|
|
|
} else if (Logs::DebugEnabled()) { // internal server error
|
2019-06-18 16:53:27 +00:00
|
|
|
showCodeError(rpl::single(err + ": " + error.description()));
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2019-06-18 16:53:27 +00:00
|
|
|
showCodeError(rpl::single(Lang::Hard::ServerError()));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 08:33:18 +00:00
|
|
|
void CodeWidget::codeChanged() {
|
2016-11-24 19:28:23 +00:00
|
|
|
hideError();
|
2018-11-19 12:15:59 +00:00
|
|
|
submit();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 08:33:18 +00:00
|
|
|
void CodeWidget::sendCall() {
|
2019-11-26 11:10:44 +00:00
|
|
|
if (_callStatus == CallStatus::Waiting) {
|
2016-11-24 19:28:23 +00:00
|
|
|
if (--_callTimeout <= 0) {
|
2019-11-26 11:10:44 +00:00
|
|
|
_callStatus = CallStatus::Calling;
|
2019-11-27 08:33:18 +00:00
|
|
|
_callTimer.cancel();
|
2020-06-17 09:36:25 +00:00
|
|
|
_callRequestId = api().request(MTPauth_ResendCode(
|
2020-06-11 13:07:14 +00:00
|
|
|
MTP_string(getData()->phone),
|
|
|
|
MTP_bytes(getData()->phoneHash)
|
|
|
|
)).done([=](const MTPauth_SentCode &result) {
|
|
|
|
callDone(result);
|
|
|
|
}).send();
|
2016-03-15 19:38:30 +00:00
|
|
|
} else {
|
2016-11-24 19:28:23 +00:00
|
|
|
getData()->callStatus = _callStatus;
|
|
|
|
getData()->callTimeout = _callTimeout;
|
2016-03-15 19:38:30 +00:00
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
updateCallText();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeWidget::callDone(const MTPauth_SentCode &v) {
|
|
|
|
if (v.type() == mtpc_auth_sentCode) {
|
2018-06-01 07:00:18 +00:00
|
|
|
fillSentCodeData(v.c_auth_sentCode());
|
2016-11-24 19:28:23 +00:00
|
|
|
_code->setDigitsCountMax(getData()->codeLength);
|
|
|
|
}
|
2019-11-26 11:10:44 +00:00
|
|
|
if (_callStatus == CallStatus::Calling) {
|
|
|
|
_callStatus = CallStatus::Called;
|
2016-11-24 19:28:23 +00:00
|
|
|
getData()->callStatus = _callStatus;
|
|
|
|
getData()->callTimeout = _callTimeout;
|
|
|
|
updateCallText();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeWidget::gotPassword(const MTPaccount_Password &result) {
|
2018-08-03 21:48:00 +00:00
|
|
|
Expects(result.type() == mtpc_account_password);
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
stopCheck();
|
2016-11-04 19:50:35 +00:00
|
|
|
_sentRequest = 0;
|
2018-08-03 21:48:00 +00:00
|
|
|
const auto &d = result.c_account_password();
|
2018-08-10 19:19:46 +00:00
|
|
|
getData()->pwdRequest = Core::ParseCloudPasswordCheckRequest(d);
|
2019-07-05 13:38:38 +00:00
|
|
|
if (!d.vcurrent_algo() || !d.vsrp_id() || !d.vsrp_B()) {
|
2018-08-03 21:48:00 +00:00
|
|
|
LOG(("API Error: No current password received on login."));
|
2016-11-04 19:50:35 +00:00
|
|
|
_code->setFocus();
|
2018-08-03 21:48:00 +00:00
|
|
|
return;
|
2018-08-10 19:19:46 +00:00
|
|
|
} else if (!getData()->pwdRequest) {
|
2020-09-24 12:48:02 +00:00
|
|
|
const auto callback = [=](Fn<void()> &&close) {
|
2018-08-03 21:48:00 +00:00
|
|
|
Core::UpdateApplication();
|
2020-09-24 12:48:02 +00:00
|
|
|
close();
|
2018-08-03 21:48:00 +00:00
|
|
|
};
|
2020-09-24 12:48:02 +00:00
|
|
|
Ui::show(Box<ConfirmBox>(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_passport_app_out_of_date(tr::now),
|
|
|
|
tr::lng_menu_update(tr::now),
|
2018-08-03 21:48:00 +00:00
|
|
|
callback));
|
|
|
|
return;
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2018-08-03 21:48:00 +00:00
|
|
|
getData()->hasRecovery = d.is_has_recovery();
|
2019-07-05 13:38:38 +00:00
|
|
|
getData()->pwdHint = qs(d.vhint().value_or_empty());
|
2018-08-03 21:48:00 +00:00
|
|
|
getData()->pwdNotEmptyPassport = d.is_has_secure_values();
|
2020-06-23 14:55:08 +00:00
|
|
|
goReplace<PasswordCheckWidget>(Animate::Forward);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeWidget::submit() {
|
2018-11-19 12:15:59 +00:00
|
|
|
const auto text = QString(
|
|
|
|
_code->getLastText()
|
|
|
|
).remove(
|
|
|
|
QRegularExpression("[^\\d]")
|
|
|
|
).mid(0, getData()->codeLength);
|
|
|
|
|
|
|
|
if (_sentRequest
|
|
|
|
|| _sentCode == text
|
|
|
|
|| text.size() != getData()->codeLength) {
|
|
|
|
return;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
hideError();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2019-11-27 08:33:18 +00:00
|
|
|
_checkRequestTimer.callEach(1000);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-11-19 12:15:59 +00:00
|
|
|
_sentCode = text;
|
2018-08-10 19:19:46 +00:00
|
|
|
getData()->pwdRequest = Core::CloudPasswordCheckRequest();
|
2016-11-24 19:28:23 +00:00
|
|
|
getData()->hasRecovery = false;
|
|
|
|
getData()->pwdHint = QString();
|
2018-04-20 16:42:51 +00:00
|
|
|
getData()->pwdNotEmptyPassport = false;
|
2020-06-17 09:36:25 +00:00
|
|
|
_sentRequest = api().request(MTPauth_SignIn(
|
2020-06-11 13:07:14 +00:00
|
|
|
MTP_string(getData()->phone),
|
|
|
|
MTP_bytes(getData()->phoneHash),
|
|
|
|
MTP_string(_sentCode)
|
|
|
|
)).done([=](const MTPauth_Authorization &result) {
|
|
|
|
codeSubmitDone(result);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2020-06-11 13:07:14 +00:00
|
|
|
codeSubmitFail(error);
|
|
|
|
}).handleFloodErrors().send();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 08:33:18 +00:00
|
|
|
void CodeWidget::noTelegramCode() {
|
2021-04-13 13:51:42 +00:00
|
|
|
if (_noTelegramCodeRequestId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_noTelegramCodeRequestId = api().request(MTPauth_ResendCode(
|
|
|
|
MTP_string(getData()->phone),
|
|
|
|
MTP_bytes(getData()->phoneHash)
|
|
|
|
)).done([=](const MTPauth_SentCode &result) {
|
|
|
|
noTelegramCodeDone(result);
|
|
|
|
}).fail([=](const MTP::Error &error) {
|
|
|
|
noTelegramCodeFail(error);
|
|
|
|
}).handleFloodErrors().send();
|
2015-08-31 14:27:20 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void CodeWidget::noTelegramCodeDone(const MTPauth_SentCode &result) {
|
2019-06-05 15:50:42 +00:00
|
|
|
_noTelegramCodeRequestId = 0;
|
|
|
|
|
2016-03-15 19:38:30 +00:00
|
|
|
if (result.type() != mtpc_auth_sentCode) {
|
2019-06-18 16:53:27 +00:00
|
|
|
showCodeError(rpl::single(Lang::Hard::ServerError()));
|
2016-03-15 19:38:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-01 07:00:18 +00:00
|
|
|
const auto &d = result.c_auth_sentCode();
|
|
|
|
fillSentCodeData(d);
|
2016-11-24 19:28:23 +00:00
|
|
|
_code->setDigitsCountMax(getData()->codeLength);
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto next = d.vnext_type();
|
|
|
|
if (next && next->type() == mtpc_auth_codeTypeCall) {
|
2019-11-26 11:10:44 +00:00
|
|
|
getData()->callStatus = CallStatus::Waiting;
|
2019-07-05 13:38:38 +00:00
|
|
|
getData()->callTimeout = d.vtimeout().value_or(60);
|
2016-03-15 19:38:30 +00:00
|
|
|
} else {
|
2019-11-26 11:10:44 +00:00
|
|
|
getData()->callStatus = CallStatus::Disabled;
|
2016-11-24 19:28:23 +00:00
|
|
|
getData()->callTimeout = 0;
|
2016-03-15 19:38:30 +00:00
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
getData()->codeByTelegram = false;
|
2015-08-31 14:27:20 +00:00
|
|
|
updateDescText();
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void CodeWidget::noTelegramCodeFail(const MTP::Error &error) {
|
|
|
|
if (MTP::IsFloodError(error)) {
|
2019-06-05 15:50:42 +00:00
|
|
|
_noTelegramCodeRequestId = 0;
|
2019-06-18 16:53:27 +00:00
|
|
|
showCodeError(tr::lng_flood_error());
|
2020-06-11 13:07:14 +00:00
|
|
|
return;
|
2021-04-13 13:51:42 +00:00
|
|
|
} else if (error.type() == u"SEND_CODE_UNAVAILABLE"_q) {
|
|
|
|
_noTelegramCodeRequestId = 0;
|
|
|
|
return;
|
2019-06-05 15:50:42 +00:00
|
|
|
}
|
2016-04-08 10:44:35 +00:00
|
|
|
|
2019-06-05 15:50:42 +00:00
|
|
|
_noTelegramCodeRequestId = 0;
|
2018-06-05 13:32:26 +00:00
|
|
|
if (Logs::DebugEnabled()) { // internal server error
|
2019-06-18 16:53:27 +00:00
|
|
|
showCodeError(rpl::single(error.type() + ": " + error.description()));
|
2015-08-31 14:27:20 +00:00
|
|
|
} else {
|
2019-06-18 16:53:27 +00:00
|
|
|
showCodeError(rpl::single(Lang::Hard::ServerError()));
|
2015-08-31 14:27:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-26 11:10:44 +00:00
|
|
|
} // namespace details
|
2016-11-24 19:28:23 +00:00
|
|
|
} // namespace Intro
|