Allow to call deleteAccount before authorization. ConfirmPhone support.

GitOrigin-RevId: 36829ee37780ee82b1eb25cea594a673aa490dda
This commit is contained in:
levlam 2018-06-27 21:26:52 +03:00
parent 48740add28
commit a3571b676e
11 changed files with 101 additions and 31 deletions

View File

@ -3043,7 +3043,7 @@ setAccountTtl ttl:accountTtl = Ok;
//@description Returns the period of inactivity after which the account of the current user will automatically be deleted
getAccountTtl = AccountTtl;
//@description Deletes the account of the current user, deleting all information associated with the user from the server. The phone number of the account can be used to create a new account @reason The reason why the account was deleted; optional
//@description Deletes the account of the current user, deleting all information associated with the user from the server. The phone number of the account can be used to create a new account. Can be called before authorization when the current authorization state is authorizationStateWaitPassword @reason The reason why the account was deleted; optional
deleteAccount reason:string = Ok;
@ -3133,6 +3133,17 @@ getPassportAuthorizationForm bot_user_id:int32 scope:string public_key:string pa
sendPassportAuthorizationForm autorization_form_id:int32 types:vector<PassportDataType> password:string = Ok;
//@description Sends phone number comfirmation code. Should be called when user presses "https://t.me/confirmphone?phone=*******&hash=**********" or "tg://confirmphone?phone=*******&hash=**********" link @hash "Hash" parameter from the link
//@phone_number "Phone" parameter from the link @allow_flash_call Pass true if the authentication code may be sent via flash call to the specified phone number @is_current_phone_number Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false
sendPhoneNumberConfirmationCode hash:string phone_number:string allow_flash_call:Bool is_current_phone_number:Bool = AuthenticationCodeInfo;
//@description Resends phone number comfirmation code
resendPhoneNumberConfirmationCode = AuthenticationCodeInfo;
//@description Checks phone number comfirmation code @code The phone number confirmation code
checkPhoneNumberConfirmationCode code:string = Ok;
//@description Informs the server about the number of pending bot updates if they haven't been processed for a long time; for bots only @pending_update_count The number of pending updates @error_message The last error message
setBotUpdatesStatus pending_update_count:int32 error_message:string = Ok;

Binary file not shown.

View File

@ -91,7 +91,8 @@ Result<telegram_api::account_sendChangePhoneCode> SendCodeHelper::send_change_ph
return telegram_api::account_sendChangePhoneCode(flags, false /*ignored*/, phone_number_, is_current_phone_number);
}
Result<telegram_api::account_sendVerifyPhoneCode> SendCodeHelper::send_verify_phone_code(Slice phone_number,
Result<telegram_api::account_sendVerifyPhoneCode> SendCodeHelper::send_verify_phone_code(const string &hash,
Slice phone_number,
bool allow_flash_call,
bool is_current_phone_number) {
phone_number_ = phone_number.str();
@ -99,7 +100,7 @@ Result<telegram_api::account_sendVerifyPhoneCode> SendCodeHelper::send_verify_ph
if (allow_flash_call) {
flags |= AUTH_SEND_CODE_FLAG_ALLOW_FLASH_CALL;
}
return telegram_api::account_sendVerifyPhoneCode(flags, false /*ignored*/, phone_number_, is_current_phone_number);
return telegram_api::account_sendVerifyPhoneCode(flags, false /*ignored*/, hash, is_current_phone_number);
}
Result<telegram_api::account_sendConfirmPhoneCode> SendCodeHelper::send_confirm_phone_code(
@ -216,12 +217,30 @@ void PhoneNumberManager::set_phone_number(uint64 query_id, string phone_number,
case Type::ChangePhone:
return process_send_code_result(
query_id, send_code_helper_.send_change_phone_code(phone_number, allow_flash_call, is_current_phone_number));
case Type::VerifyPhone:
return process_send_code_result(
query_id, send_code_helper_.send_verify_phone_code(phone_number, allow_flash_call, is_current_phone_number));
case Type::ConfirmPhone:
return process_send_code_result(
query_id, send_code_helper_.send_confirm_phone_code(phone_number, allow_flash_call, is_current_phone_number));
case Type::VerifyPhone:
default:
UNREACHABLE();
}
}
void PhoneNumberManager::set_phone_number_and_hash(uint64 query_id, string hash, string phone_number,
bool allow_flash_call, bool is_current_phone_number) {
if (phone_number.empty()) {
return on_query_error(query_id, Status::Error(8, "Phone number can't be empty"));
}
if (hash.empty()) {
return on_query_error(query_id, Status::Error(8, "Hash can't be empty"));
}
switch (type_) {
case Type::VerifyPhone:
return process_send_code_result(query_id, send_code_helper_.send_verify_phone_code(
hash, phone_number, allow_flash_call, is_current_phone_number));
case Type::ChangePhone:
case Type::ConfirmPhone:
default:
UNREACHABLE();
}
@ -649,14 +668,14 @@ void AuthManager::logout(uint64 query_id) {
}
void AuthManager::delete_account(uint64 query_id, const string &reason) {
if (state_ != State::Ok) {
if (state_ != State::Ok && state_ != State::WaitPassword) {
return on_query_error(query_id, Status::Error(8, "Need to log in first"));
}
on_new_query(query_id);
LOG(INFO) << "Deleting account";
update_state(State::LoggingOut);
start_net_query(NetQueryType::DeleteAccount,
G()->net_query_creator().create(create_storer(telegram_api::account_deleteAccount(reason))));
G()->net_query_creator().create(create_storer(telegram_api::account_deleteAccount(reason)),
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
}
void AuthManager::on_closing() {
@ -807,13 +826,13 @@ void AuthManager::on_delete_account_result(NetQueryPtr &result) {
status = std::move(result->error());
}
if (status.is_error() && status.error().message() != "USER_DEACTIVATED") {
update_state(State::Ok);
LOG(WARNING) << "account.deleteAccount failed: " << status;
// TODO handle some errors
if (query_id_ != 0) {
on_query_error(std::move(status));
}
} else {
update_state(State::LoggingOut);
send_closure_later(G()->td(), &Td::destroy);
if (query_id_ != 0) {
on_query_ok();

View File

@ -34,7 +34,8 @@ class SendCodeHelper {
Result<telegram_api::account_sendChangePhoneCode> send_change_phone_code(Slice phone_number, bool allow_flash_call,
bool is_current_phone_number);
Result<telegram_api::account_sendVerifyPhoneCode> send_verify_phone_code(Slice phone_number, bool allow_flash_call,
Result<telegram_api::account_sendVerifyPhoneCode> send_verify_phone_code(const string &hash, Slice phone_number,
bool allow_flash_call,
bool is_current_phone_number);
Result<telegram_api::account_sendConfirmPhoneCode> send_confirm_phone_code(Slice phone_number, bool allow_flash_call,
@ -103,6 +104,8 @@ class PhoneNumberManager : public NetActor {
void get_state(uint64 query_id);
void set_phone_number(uint64 query_id, string phone_number, bool allow_flash_call, bool is_current_phone_number);
void set_phone_number_and_hash(uint64 query_id, string hash, string phone_number, bool allow_flash_call,
bool is_current_phone_number);
void resend_authentication_code(uint64 query_id);
void check_code(uint64 query_id, string code);

View File

@ -23,6 +23,7 @@
#include "td/utils/Time.h"
namespace td {
StorageManager::StorageManager(ActorShared<> parent, int32 scheduler_id)
: parent_(std::move(parent)), scheduler_id_(scheduler_id) {
}

View File

@ -21,6 +21,7 @@ class FileGcWorker;
} // namespace td
namespace td {
class StorageManager : public Actor {
public:
StorageManager(ActorShared<> parent, int32 scheduler_id);
@ -79,4 +80,5 @@ class StorageManager : public Actor {
void timeout_expired() override;
};
} // namespace td

View File

@ -3974,6 +3974,7 @@ bool Td::is_authentication_request(int32 id) {
case td_api::checkAuthenticationPassword::ID:
case td_api::requestAuthenticationPasswordRecovery::ID:
case td_api::recoverAuthenticationPassword::ID:
case td_api::deleteAccount::ID:
case td_api::logOut::ID:
case td_api::close::ID:
case td_api::destroy::ID:
@ -4502,14 +4503,14 @@ void Td::clear() {
LOG(DEBUG) << "Requests was answered " << timer;
// close all pure actors
change_phone_number_manager_.reset();
LOG(DEBUG) << "ChangePhoneNumberManager was cleared " << timer;
verify_phone_number_manager_.reset();
LOG(DEBUG) << "ChangePhoneNumberManager was cleared " << timer;
call_manager_.reset();
LOG(DEBUG) << "CallManager was cleared " << timer;
change_phone_number_manager_.reset();
LOG(DEBUG) << "ChangePhoneNumberManager was cleared " << timer;
config_manager_.reset();
LOG(DEBUG) << "ConfigManager was cleared " << timer;
confirm_phone_number_manager_.reset();
LOG(DEBUG) << "ConfirmPhoneNumberManager was cleared " << timer;
device_token_manager_.reset();
LOG(DEBUG) << "DeviceTokenManager was cleared " << timer;
hashtag_hints_.reset();
@ -4528,6 +4529,8 @@ void Td::clear() {
LOG(DEBUG) << "StorageManager was cleared " << timer;
top_dialog_manager_.reset();
LOG(DEBUG) << "TopDialogManager was cleared " << timer;
verify_phone_number_manager_.reset();
LOG(DEBUG) << "VerifyPhoneNumberManager was cleared " << timer;
G()->set_connection_creator(ActorOwn<ConnectionCreator>());
LOG(DEBUG) << "ConnectionCreator was cleared " << timer;
@ -4811,25 +4814,27 @@ Status Td::init(DbKey key) {
web_pages_manager_actor_ = register_actor("WebPagesManager", web_pages_manager_.get());
G()->set_web_pages_manager(web_pages_manager_actor_.get());
change_phone_number_manager_ = create_actor<PhoneNumberManager>(
"ChangePhoneNumberManager", PhoneNumberManager::Type::ChangePhone, create_reference());
verify_phone_number_manager_ = create_actor<PhoneNumberManager>(
"VerifyPhoneNumberManager", PhoneNumberManager::Type::VerifyPhone, create_reference());
call_manager_ = create_actor<CallManager>("CallManager", create_reference());
G()->set_call_manager(call_manager_.get());
change_phone_number_manager_ = create_actor<PhoneNumberManager>(
"ChangePhoneNumberManager", PhoneNumberManager::Type::ChangePhone, create_reference());
confirm_phone_number_manager_ = create_actor<PhoneNumberManager>(
"ConfirmPhoneNumberManager", PhoneNumberManager::Type::ConfirmPhone, create_reference());
device_token_manager_ = create_actor<DeviceTokenManager>("DeviceTokenManager", create_reference());
hashtag_hints_ = create_actor<HashtagHints>("HashtagHints", "text", create_reference());
password_manager_ = create_actor<PasswordManager>("PasswordManager", create_reference());
G()->set_password_manager(password_manager_.get());
privacy_manager_ = create_actor<PrivacyManager>("PrivacyManager", create_reference());
secure_manager_ = create_actor<SecureManager>("SecureManager", create_reference());
secret_chats_manager_ = create_actor<SecretChatsManager>("SecretChatsManager", create_reference());
G()->set_secret_chats_manager(secret_chats_manager_.get());
secure_manager_ = create_actor<SecureManager>("SecureManager", create_reference());
storage_manager_ = create_actor<StorageManager>("StorageManager", create_reference(),
min(current_scheduler_id + 2, scheduler_count - 1));
G()->set_storage_manager(storage_manager_.get());
top_dialog_manager_ = create_actor<TopDialogManager>("TopDialogManager", create_reference());
G()->set_top_dialog_manager(top_dialog_manager_.get());
verify_phone_number_manager_ = create_actor<PhoneNumberManager>(
"VerifyPhoneNumberManager", PhoneNumberManager::Type::VerifyPhone, create_reference());
VLOG(td_init) << "Send binlog events";
for (auto &event : events.user_events) {
@ -6987,6 +6992,26 @@ void Td::on_request(uint64 id, td_api::sendPassportAuthorizationForm &request) {
request.autorization_form_id_, get_secure_value_types_td_api(request.types_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::sendPhoneNumberConfirmationCode &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.phone_number_);
CLEAN_INPUT_STRING(request.hash_);
send_closure(confirm_phone_number_manager_, &PhoneNumberManager::set_phone_number_and_hash, id,
std::move(request.hash_), std::move(request.phone_number_), request.allow_flash_call_,
request.is_current_phone_number_);
}
void Td::on_request(uint64 id, const td_api::resendPhoneNumberConfirmationCode &request) {
CHECK_IS_USER();
send_closure(confirm_phone_number_manager_, &PhoneNumberManager::resend_authentication_code, id);
}
void Td::on_request(uint64 id, td_api::checkPhoneNumberConfirmationCode &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.code_);
send_closure(confirm_phone_number_manager_, &PhoneNumberManager::check_code, id, std::move(request.code_));
}
void Td::on_request(uint64 id, const td_api::getSupportUser &request) {
CHECK_IS_USER();
CREATE_NO_ARGS_REQUEST(GetSupportUserRequest);

View File

@ -145,10 +145,10 @@ class Td final : public NetQueryCallback {
std::unique_ptr<WebPagesManager> web_pages_manager_;
ActorOwn<WebPagesManager> web_pages_manager_actor_;
ActorOwn<PhoneNumberManager> change_phone_number_manager_;
ActorOwn<PhoneNumberManager> verify_phone_number_manager_;
ActorOwn<CallManager> call_manager_;
ActorOwn<PhoneNumberManager> change_phone_number_manager_;
ActorOwn<ConfigManager> config_manager_;
ActorOwn<PhoneNumberManager> confirm_phone_number_manager_;
ActorOwn<DeviceTokenManager> device_token_manager_;
ActorOwn<HashtagHints> hashtag_hints_;
ActorOwn<NetStatsManager> net_stats_manager_;
@ -159,6 +159,7 @@ class Td final : public NetQueryCallback {
ActorOwn<StateManager> state_manager_;
ActorOwn<StorageManager> storage_manager_;
ActorOwn<TopDialogManager> top_dialog_manager_;
ActorOwn<PhoneNumberManager> verify_phone_number_manager_;
class ResultHandler : public std::enable_shared_from_this<ResultHandler> {
public:
@ -799,6 +800,12 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::sendPassportAuthorizationForm &request);
void on_request(uint64 id, td_api::sendPhoneNumberConfirmationCode &request);
void on_request(uint64 id, const td_api::resendPhoneNumberConfirmationCode &request);
void on_request(uint64 id, td_api::checkPhoneNumberConfirmationCode &request);
void on_request(uint64 id, const td_api::getSupportUser &request);
void on_request(uint64 id, const td_api::getWallpapers &request);

View File

@ -515,7 +515,7 @@ void TopDialogManager::on_first_sync() {
}
void TopDialogManager::loop() {
if (!is_active_) {
if (!is_active_ || G()->close_flag()) {
return;
}

View File

@ -1266,6 +1266,12 @@ class CliClient final : public Actor {
string recovery_email_address;
std::tie(password, recovery_email_address) = split(args);
send_request(make_tl_object<td_api::setRecoveryEmailAddress>(password, recovery_email_address));
} else if (op == "spncc") {
send_request(make_tl_object<td_api::sendPhoneNumberVerificationCode>(args, false, false));
} else if (op == "cpncc") {
send_request(make_tl_object<td_api::checkPhoneNumberVerificationCode>(args));
} else if (op == "rpncc") {
send_request(make_tl_object<td_api::resendPhoneNumberVerificationCode>());
} else if (op == "rpr" || op == "RequestPasswordRecovery") {
send_request(make_tl_object<td_api::requestPasswordRecovery>());
} else if (op == "rp" || op == "RecoverPassword") {

View File

@ -27,14 +27,10 @@ void NetQueryDelayer::delay(NetQueryPtr query) {
// skip
} else if (code == 420) {
auto msg = query->error().message();
auto prefix = Slice("FLOOD_WAIT_");
if (msg.substr(0, prefix.size()) == prefix) {
timeout = to_integer<int>(msg.substr(prefix.size()));
if (timeout < 0) {
timeout = 0;
}
if (timeout > 24 * 60 * 60) {
timeout = 24 * 60 * 60;
for (auto prefix : {Slice("FLOOD_WAIT_"), Slice("2FA_CONFIRM_WAIT_"), Slice("TAKEOUT_INIT_DELAY_")}) {
if (begins_with(msg, prefix)) {
timeout = clamp(to_integer<int>(msg.substr(prefix.size())), 0, 14 * 24 * 60 * 60);
break;
}
}
} else {