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
|
|
|
*/
|
2016-04-21 17:57:29 +00:00
|
|
|
#include "intro/introphone.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "application.h"
|
2016-03-14 16:59:18 +00:00
|
|
|
#include "intro/introcode.h"
|
2016-10-27 14:10:28 +00:00
|
|
|
#include "styles/style_intro.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "ui/wrap/fade_wrap.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
#include "core/click_handler_types.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2017-11-24 17:41:09 +00:00
|
|
|
#include "base/qthelp_url.h"
|
|
|
|
#include "platform/platform_specific.h"
|
2017-02-25 16:44:02 +00:00
|
|
|
#include "messenger.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
namespace Intro {
|
2017-11-24 17:41:09 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void SendToBannedHelp(const QString &phone) {
|
|
|
|
const auto version = QString::fromLatin1(AppVersionStr.c_str())
|
|
|
|
+ (cAlphaVersion() ? " alpha" : "")
|
|
|
|
+ (cBetaVersion() ? qsl(" beta %1").arg(cBetaVersion()) : QString());
|
|
|
|
|
|
|
|
const auto subject = qsl("Banned phone number: ") + phone;
|
|
|
|
|
|
|
|
const auto body = qsl("\
|
|
|
|
I'm trying to use my mobile phone number: ") + phone + qsl("\n\
|
|
|
|
But Telegram says it's banned. Please help.\n\
|
|
|
|
\n\
|
|
|
|
App version: ") + version + qsl("\n\
|
|
|
|
OS version: ") + cPlatformString() + qsl("\n\
|
|
|
|
Locale: ") + Platform::SystemLanguage();
|
|
|
|
|
|
|
|
const auto url = "mailto:?to="
|
|
|
|
+ qthelp::url_encode("login@stel.com")
|
|
|
|
+ "&subject="
|
|
|
|
+ qthelp::url_encode(subject)
|
|
|
|
+ "&body="
|
|
|
|
+ qthelp::url_encode(body);
|
|
|
|
|
|
|
|
UrlClickHandler::doOpen(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2016-11-24 19:28:23 +00:00
|
|
|
|
|
|
|
PhoneWidget::PhoneWidget(QWidget *parent, Widget::Data *data) : Step(parent, data)
|
2016-11-04 19:50:35 +00:00
|
|
|
, _country(this, st::introCountry)
|
2016-11-15 11:56:49 +00:00
|
|
|
, _code(this, st::introCountryCode)
|
2016-11-24 19:28:23 +00:00
|
|
|
, _phone(this, st::introPhone)
|
2016-11-04 19:50:35 +00:00
|
|
|
, _checkRequest(this) {
|
|
|
|
connect(_phone, SIGNAL(voidBackspace(QKeyEvent*)), _code, SLOT(startErasing(QKeyEvent*)));
|
|
|
|
connect(_country, SIGNAL(codeChanged(const QString &)), _code, SLOT(codeSelected(const QString &)));
|
|
|
|
connect(_code, SIGNAL(codeChanged(const QString &)), _country, SLOT(onChooseCode(const QString &)));
|
|
|
|
connect(_code, SIGNAL(codeChanged(const QString &)), _phone, SLOT(onChooseCode(const QString &)));
|
|
|
|
connect(_country, SIGNAL(codeChanged(const QString &)), _phone, SLOT(onChooseCode(const QString &)));
|
|
|
|
connect(_code, SIGNAL(addedToNumber(const QString &)), _phone, SLOT(addedToNumber(const QString &)));
|
|
|
|
connect(_phone, SIGNAL(changed()), this, SLOT(onInputChange()));
|
|
|
|
connect(_code, SIGNAL(changed()), this, SLOT(onInputChange()));
|
|
|
|
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
setTitleText(langFactory(lng_phone_title));
|
|
|
|
setDescriptionText(langFactory(lng_phone_desc));
|
2016-11-24 19:28:23 +00:00
|
|
|
subscribe(getData()->updated, [this] { countryChanged(); });
|
|
|
|
setErrorCentered(true);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
if (!_country->onChooseCountry(getData()->country)) {
|
2016-11-04 19:50:35 +00:00
|
|
|
_country->onChooseCountry(qsl("US"));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-11-04 19:50:35 +00:00
|
|
|
_changed = false;
|
2017-02-25 16:44:02 +00:00
|
|
|
|
|
|
|
Messenger::Instance().destroyStaleAuthorizationKeys();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PhoneWidget::resizeEvent(QResizeEvent *e) {
|
|
|
|
Step::resizeEvent(e);
|
|
|
|
_country->moveToLeft(contentLeft(), contentTop() + st::introStepFieldTop);
|
|
|
|
auto phoneTop = _country->y() + _country->height() + st::introPhoneTop;
|
|
|
|
_code->moveToLeft(contentLeft(), phoneTop);
|
|
|
|
_phone->moveToLeft(contentLeft() + _country->width() - st::introPhone.width, phoneTop);
|
|
|
|
updateSignupGeometry();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PhoneWidget::updateSignupGeometry() {
|
|
|
|
if (_signup) {
|
|
|
|
_signup->moveToLeft(contentLeft() + st::buttonRadius, contentTop() + st::introDescriptionTop);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 13:54:05 +00:00
|
|
|
void PhoneWidget::showPhoneError(base::lambda<QString()> textFactory) {
|
2016-11-24 19:28:23 +00:00
|
|
|
_phone->showError();
|
2017-05-30 13:54:05 +00:00
|
|
|
showError(std::move(textFactory));
|
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 PhoneWidget::hidePhoneError() {
|
|
|
|
hideError();
|
|
|
|
if (_signup) {
|
2017-09-30 19:20:40 +00:00
|
|
|
_signup->hide(anim::type::instant);
|
2016-11-24 19:28:23 +00:00
|
|
|
showDescription();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-09 17:48:29 +00:00
|
|
|
//void PhoneWidget::showSignup() {
|
|
|
|
// showPhoneError(langFactory(lng_bad_phone_noreg));
|
|
|
|
// if (!_signup) {
|
|
|
|
// auto signupText = lng_phone_notreg(lt_link_start, textcmdStartLink(1), lt_link_end, textcmdStopLink(), lt_signup_start, textcmdStartLink(2), lt_signup_end, textcmdStopLink());
|
|
|
|
// auto inner = object_ptr<Ui::FlatLabel>(this, signupText, Ui::FlatLabel::InitType::Rich, st::introDescription);
|
|
|
|
// _signup.create(this, std::move(inner));
|
|
|
|
// _signup->entity()->setLink(1, std::make_shared<UrlClickHandler>(qsl("https://telegram.org"), false));
|
|
|
|
// _signup->entity()->setLink(2, std::make_shared<LambdaClickHandler>([this] {
|
|
|
|
// toSignUp();
|
|
|
|
// }));
|
|
|
|
// _signup->hide(anim::type::instant);
|
|
|
|
// updateSignupGeometry();
|
|
|
|
// }
|
|
|
|
// _signup->show(anim::type::normal);
|
|
|
|
// hideDescription();
|
|
|
|
//}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PhoneWidget::countryChanged() {
|
2016-11-04 19:50:35 +00:00
|
|
|
if (!_changed) {
|
2016-11-24 19:28:23 +00:00
|
|
|
selectCountry(getData()->country);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PhoneWidget::onInputChange() {
|
2016-11-04 19:50:35 +00:00
|
|
|
_changed = true;
|
2016-11-24 19:28:23 +00:00
|
|
|
hidePhoneError();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PhoneWidget::submit() {
|
2016-11-04 19:50:35 +00:00
|
|
|
if (_sentRequest || isHidden()) return;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
if (!App::isValidPhone(fullNumber())) {
|
2017-05-30 15:21:05 +00:00
|
|
|
showPhoneError(langFactory(lng_bad_phone));
|
2016-11-04 19:50:35 +00:00
|
|
|
_phone->setFocus();
|
2014-05-30 08:53:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-01 07:00:18 +00:00
|
|
|
hidePhoneError();
|
2018-05-30 15:08:12 +00:00
|
|
|
|
2018-06-01 07:00:18 +00:00
|
|
|
_checkRequest->start(1000);
|
|
|
|
|
|
|
|
_sentPhone = fullNumber();
|
|
|
|
Messenger::Instance().mtp()->setUserPhone(_sentPhone);
|
|
|
|
//_sentRequest = MTP::send(MTPauth_CheckPhone(MTP_string(_sentPhone)), rpcDone(&PhoneWidget::phoneCheckDone), rpcFail(&PhoneWidget::phoneSubmitFail));
|
|
|
|
_sentRequest = MTP::send(
|
|
|
|
MTPauth_SendCode(
|
|
|
|
MTP_flags(0),
|
|
|
|
MTP_string(_sentPhone),
|
|
|
|
MTPBool(),
|
|
|
|
MTP_int(ApiId),
|
|
|
|
MTP_string(ApiHash)),
|
|
|
|
rpcDone(&PhoneWidget::phoneSubmitDone),
|
|
|
|
rpcFail(&PhoneWidget::phoneSubmitFail));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PhoneWidget::stopCheck() {
|
2016-11-04 19:50:35 +00:00
|
|
|
_checkRequest->stop();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PhoneWidget::onCheckRequest() {
|
2016-12-09 18:56:01 +00:00
|
|
|
auto status = MTP::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
|
|
|
MTP::cancel(base::take(_sentRequest));
|
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();
|
|
|
|
}
|
|
|
|
}
|
2018-04-09 17:48:29 +00:00
|
|
|
//
|
|
|
|
//void PhoneWidget::phoneCheckDone(const MTPauth_CheckedPhone &result) {
|
|
|
|
// stopCheck();
|
|
|
|
//
|
|
|
|
// auto &d = result.c_auth_checkedPhone();
|
|
|
|
// if (mtpIsTrue(d.vphone_registered)) {
|
|
|
|
// hidePhoneError();
|
|
|
|
//
|
|
|
|
// _checkRequest->start(1000);
|
|
|
|
//
|
|
|
|
// _sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(0), MTP_string(_sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&PhoneWidget::phoneSubmitDone), rpcFail(&PhoneWidget::phoneSubmitFail));
|
|
|
|
// } else {
|
|
|
|
// showSignup();
|
|
|
|
// _sentRequest = 0;
|
|
|
|
// }
|
|
|
|
//}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PhoneWidget::phoneSubmitDone(const MTPauth_SentCode &result) {
|
2014-05-30 08:53:19 +00:00
|
|
|
stopCheck();
|
2016-11-04 19:50:35 +00:00
|
|
|
_sentRequest = 0;
|
2016-03-14 16:59:18 +00:00
|
|
|
|
|
|
|
if (result.type() != mtpc_auth_sentCode) {
|
2017-09-28 20:11:10 +00:00
|
|
|
showPhoneError(&Lang::Hard::ServerError);
|
2016-03-14 16:59:18 +00:00
|
|
|
return;
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
2016-03-14 16:59:18 +00:00
|
|
|
|
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
|
|
|
getData()->phone = _sentPhone;
|
2017-03-10 19:46:28 +00:00
|
|
|
getData()->phoneHash = qba(d.vphone_code_hash);
|
2016-11-24 19:28:23 +00:00
|
|
|
getData()->phoneIsRegistered = d.is_phone_registered();
|
2016-03-15 19:38:30 +00:00
|
|
|
if (d.has_next_type() && d.vnext_type.type() == mtpc_auth_codeTypeCall) {
|
2016-11-24 19:28:23 +00:00
|
|
|
getData()->callStatus = Widget::Data::CallStatus::Waiting;
|
|
|
|
getData()->callTimeout = d.has_timeout() ? d.vtimeout.v : 60;
|
2016-03-15 19:38:30 +00:00
|
|
|
} else {
|
2016-11-24 19:28:23 +00:00
|
|
|
getData()->callStatus = Widget::Data::CallStatus::Disabled;
|
|
|
|
getData()->callTimeout = 0;
|
2016-03-14 16:59:18 +00:00
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
goNext(new Intro::CodeWidget(parentWidget(), getData()));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2018-04-09 17:48:29 +00:00
|
|
|
//void PhoneWidget::toSignUp() {
|
|
|
|
// hideError(); // Hide error, but leave the signup label visible.
|
|
|
|
//
|
|
|
|
// _checkRequest->start(1000);
|
|
|
|
//
|
|
|
|
// _sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(0), MTP_string(_sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&PhoneWidget::phoneSubmitDone), rpcFail(&PhoneWidget::phoneSubmitFail));
|
|
|
|
//}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
bool PhoneWidget::phoneSubmitFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isFloodError(error)) {
|
|
|
|
stopCheck();
|
2016-11-04 19:50:35 +00:00
|
|
|
_sentRequest = 0;
|
2017-05-30 15:21:05 +00:00
|
|
|
showPhoneError(langFactory(lng_flood_error));
|
2016-04-08 10:44:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
|
|
|
|
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();
|
2016-12-30 13:53:51 +00:00
|
|
|
if (err == qstr("PHONE_NUMBER_FLOOD")) {
|
|
|
|
Ui::show(Box<InformBox>(lang(lng_error_phone_flood)));
|
|
|
|
return true;
|
|
|
|
} else if (err == qstr("PHONE_NUMBER_INVALID")) { // show error
|
2017-05-30 15:21:05 +00:00
|
|
|
showPhoneError(langFactory(lng_bad_phone));
|
2014-05-30 08:53:19 +00:00
|
|
|
return true;
|
2017-11-24 17:41:09 +00:00
|
|
|
} else if (err == qstr("PHONE_NUMBER_BANNED")) {
|
|
|
|
const auto phone = _sentPhone;
|
|
|
|
Ui::show(Box<ConfirmBox>(
|
|
|
|
lang(lng_signin_banned_text),
|
|
|
|
lang(lng_box_ok),
|
|
|
|
lang(lng_signin_banned_help),
|
|
|
|
[] { Ui::hideLayer(); },
|
|
|
|
[phone] { SendToBannedHelp(phone); Ui::hideLayer(); }));
|
|
|
|
return true;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
if (cDebug()) { // internal server error
|
2017-05-30 13:54:05 +00:00
|
|
|
auto text = err + ": " + error.description();
|
|
|
|
showPhoneError([text] { return text; });
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2017-09-28 20:11:10 +00:00
|
|
|
showPhoneError(&Lang::Hard::ServerError);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
QString PhoneWidget::fullNumber() const {
|
|
|
|
return _code->getLastText() + _phone->getLastText();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PhoneWidget::selectCountry(const QString &c) {
|
2016-11-04 19:50:35 +00:00
|
|
|
_country->onChooseCountry(c);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PhoneWidget::setInnerFocus() {
|
2016-12-23 13:21:01 +00:00
|
|
|
_phone->setFocusFast();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PhoneWidget::activate() {
|
|
|
|
Step::activate();
|
|
|
|
_country->show();
|
|
|
|
_phone->show();
|
|
|
|
_code->show();
|
|
|
|
setInnerFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhoneWidget::finished() {
|
|
|
|
Step::finished();
|
2016-11-04 19:50:35 +00:00
|
|
|
_checkRequest->stop();
|
2017-04-06 19:02:40 +00:00
|
|
|
rpcInvalidate();
|
2016-03-14 16:59:18 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
cancelled();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void PhoneWidget::cancelled() {
|
|
|
|
MTP::cancel(base::take(_sentRequest));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
} // namespace Intro
|