Handle PHONE_NUMBER_BANNED in ChangePhoneBox.

This commit is contained in:
John Preston 2019-06-05 20:43:21 +03:00
parent b9bd937aaa
commit 4379fa2297
6 changed files with 69 additions and 42 deletions

View File

@ -201,8 +201,16 @@ bool ChangePhoneBox::EnterPhone::sendPhoneFail(const QString &phoneNumber, const
return false;
} else if (error.type() == qstr("PHONE_NUMBER_INVALID")) {
errorText = lang(lng_bad_phone);
} else if (error.type() == qstr("PHONE_NUMBER_BANNED")) {
ShowPhoneBannedError(phoneNumber);
_requestId = 0;
return true;
} else if (error.type() == qstr("PHONE_NUMBER_OCCUPIED")) {
Ui::show(Box<InformBox>(lng_change_phone_occupied(lt_phone, App::formatPhone(phoneNumber)), lang(lng_box_ok)));
Ui::show(Box<InformBox>(
lng_change_phone_occupied(
lt_phone,
App::formatPhone(phoneNumber)),
lang(lng_box_ok)));
_requestId = 0;
return true;
}
@ -314,7 +322,8 @@ bool ChangePhoneBox::EnterCode::sendCodeFail(const RPCError &error) {
return false;
} else if (error.type() == qstr("PHONE_CODE_EMPTY") || error.type() == qstr("PHONE_CODE_INVALID")) {
errorText = lang(lng_bad_code);
} else if (error.type() == qstr("PHONE_CODE_EXPIRED")) {
} else if (error.type() == qstr("PHONE_CODE_EXPIRED")
|| error.type() == qstr("PHONE_NUMBER_BANNED")) {
closeBox(); // Go back to phone input.
_requestId = 0;
return true;

View File

@ -12,6 +12,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h"
#include "ui/widgets/input_fields.h"
#include "ui/widgets/labels.h"
#include "core/click_handler_types.h" // UrlClickHandler
#include "base/qthelp_url.h" // qthelp::url_encode
#include "platform/platform_info.h" // Platform::SystemVersionPretty
#include "mainwidget.h"
#include "lang/lang_keys.h"
@ -19,8 +22,50 @@ namespace {
object_ptr<ConfirmPhoneBox> CurrentConfirmPhoneBox = { nullptr };
void SendToBannedHelp(const QString &phone) {
const auto version = QString::fromLatin1(AppVersionStr)
+ (cAlphaVersion()
? qsl(" alpha %1").arg(cAlphaVersion())
: (AppBetaVersion ? " beta" : ""));
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: ") + Platform::SystemVersionPretty() + 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::Open(url);
}
} // namespace
void ShowPhoneBannedError(const QString &phone) {
const auto box = std::make_shared<QPointer<BoxContent>>();
const auto close = [=] {
if (*box) {
(*box)->closeBox();
}
};
*box = Ui::show(Box<ConfirmBox>(
lang(lng_signin_banned_text),
lang(lng_box_ok),
lang(lng_signin_banned_help),
close,
[=] { SendToBannedHelp(phone); close(); }));
}
SentCodeField::SentCodeField(
QWidget *parent,
const style::InputField &st,

View File

@ -16,6 +16,8 @@ class InputField;
class FlatLabel;
} // namespace Ui
void ShowPhoneBannedError(const QString &phone);
class SentCodeField : public Ui::InputField {
public:
SentCodeField(

View File

@ -231,7 +231,9 @@ bool CodeWidget::codeSubmitFail(const RPCError &error) {
stopCheck();
_sentRequest = 0;
auto &err = error.type();
if (err == qstr("PHONE_NUMBER_INVALID") || err == qstr("PHONE_CODE_EXPIRED")) { // show error
if (err == qstr("PHONE_NUMBER_INVALID")
|| err == qstr("PHONE_CODE_EXPIRED")
|| err == qstr("PHONE_NUMBER_BANNED")) { // show error
goBack();
return true;
} else if (err == qstr("PHONE_CODE_EMPTY") || err == qstr("PHONE_CODE_INVALID")) {

View File

@ -13,41 +13,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
#include "ui/wrap/fade_wrap.h"
#include "core/click_handler_types.h"
#include "boxes/confirm_phone_box.h"
#include "boxes/confirm_box.h"
#include "base/qthelp_url.h"
#include "platform/platform_info.h"
#include "core/application.h"
namespace Intro {
namespace {
void SendToBannedHelp(const QString &phone) {
const auto version = QString::fromLatin1(AppVersionStr)
+ (cAlphaVersion()
? qsl(" alpha %1").arg(cAlphaVersion())
: (AppBetaVersion ? " beta" : ""));
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: ") + Platform::SystemVersionPretty() + 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::Open(url);
}
bool AllowPhoneAttempt(const QString &phone) {
const auto digits = ranges::count_if(
phone,
@ -254,13 +226,7 @@ bool PhoneWidget::phoneSubmitFail(const RPCError &error) {
showPhoneError(langFactory(lng_bad_phone));
return true;
} 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(); }));
ShowPhoneBannedError(_sentPhone);
return true;
}
if (Logs::DebugEnabled()) { // internal server error

View File

@ -146,9 +146,12 @@ bool SignupWidget::nameSubmitFail(const RPCError &error) {
if (err == qstr("PHONE_NUMBER_FLOOD")) {
Ui::show(Box<InformBox>(lang(lng_error_phone_flood)));
return true;
} else if (err == qstr("PHONE_NUMBER_INVALID") || err == qstr("PHONE_CODE_EXPIRED") ||
err == qstr("PHONE_CODE_EMPTY") || err == qstr("PHONE_CODE_INVALID") ||
err == qstr("PHONE_NUMBER_OCCUPIED")) {
} else if (err == qstr("PHONE_NUMBER_INVALID")
|| err == qstr("PHONE_NUMBER_BANNED")
|| err == qstr("PHONE_CODE_EXPIRED")
|| err == qstr("PHONE_CODE_EMPTY")
|| err == qstr("PHONE_CODE_INVALID")
|| err == qstr("PHONE_NUMBER_OCCUPIED")) {
goBack();
return true;
} else if (err == "FIRSTNAME_INVALID") {