mirror of https://github.com/procxx/kepka.git
Improve phone rules checking.
This commit is contained in:
parent
678d2a58c5
commit
257dfa6b3f
|
@ -148,6 +148,7 @@ void PhoneWidget::submit() {
|
||||||
_checkRequest->start(1000);
|
_checkRequest->start(1000);
|
||||||
|
|
||||||
_sentPhone = fullNumber();
|
_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_CheckPhone(MTP_string(_sentPhone)), rpcDone(&PhoneWidget::phoneCheckDone), rpcFail(&PhoneWidget::phoneSubmitFail));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,13 +33,16 @@ constexpr auto kUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
||||||
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36";
|
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36";
|
||||||
|
|
||||||
bool CheckPhoneByPrefixesRules(const QString &phone, const QString &rules) {
|
bool CheckPhoneByPrefixesRules(const QString &phone, const QString &rules) {
|
||||||
|
const auto check = QString(phone).replace(
|
||||||
|
QRegularExpression("[^0-9]"),
|
||||||
|
QString());
|
||||||
auto result = false;
|
auto result = false;
|
||||||
for (const auto &prefix : rules.split(',')) {
|
for (const auto &prefix : rules.split(',')) {
|
||||||
if (prefix.isEmpty()) {
|
if (prefix.isEmpty()) {
|
||||||
result = true;
|
result = true;
|
||||||
} else if (prefix[0] == '+' && phone.startsWith(prefix.mid(1))) {
|
} else if (prefix[0] == '+' && check.startsWith(prefix.mid(1))) {
|
||||||
result = true;
|
result = true;
|
||||||
} else if (prefix[0] == '-' && phone.startsWith(prefix.mid(1))) {
|
} else if (prefix[0] == '-' && check.startsWith(prefix.mid(1))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue