diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index c18a3dccb..b0025b3f2 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -6233,8 +6233,8 @@ 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. 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; +//@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 @password Password of the current user. If empty, account deletion can be canceled within one week +deleteAccount reason:string password:string = Ok; //@description Removes a chat action bar without any other action @chat_id Chat identifier diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index 394319b17..d5f37e452 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -394,14 +394,37 @@ void AuthManager::send_log_out_query() { start_net_query(NetQueryType::LogOut, std::move(query)); } -void AuthManager::delete_account(uint64 query_id, const string &reason) { +void AuthManager::delete_account(uint64 query_id, string reason, string password) { if (state_ != State::Ok && state_ != State::WaitPassword) { return on_query_error(query_id, Status::Error(400, "Need to log in first")); } + if (password.empty() || state_ != State::Ok) { + on_new_query(query_id); + LOG(INFO) << "Deleting account"; + start_net_query(NetQueryType::DeleteAccount, + G()->net_query_creator().create_unauth(telegram_api::account_deleteAccount(0, reason, nullptr))); + } else { + send_closure(G()->password_manager(), &PasswordManager::get_input_check_password_srp, password, + PromiseCreator::lambda( + [actor_id = actor_id(this), query_id, reason = std::move(reason)]( + Result> r_input_password) mutable { + send_closure(actor_id, &AuthManager::do_delete_account, query_id, std::move(reason), + std::move(r_input_password)); + })); + } +} + +void AuthManager::do_delete_account(uint64 query_id, string reason, + Result> r_input_password) { + if (r_input_password.is_error()) { + return on_query_error(query_id, r_input_password.move_as_error()); + } + on_new_query(query_id); - LOG(INFO) << "Deleting account"; - start_net_query(NetQueryType::DeleteAccount, - G()->net_query_creator().create_unauth(telegram_api::account_deleteAccount(0, reason, nullptr))); + LOG(INFO) << "Deleting account with password"; + int32 flags = telegram_api::account_deleteAccount::PASSWORD_MASK; + start_net_query(NetQueryType::DeleteAccount, G()->net_query_creator().create(telegram_api::account_deleteAccount( + flags, reason, r_input_password.move_as_ok()))); } void AuthManager::on_closing(bool destroy_flag) { diff --git a/td/telegram/AuthManager.h b/td/telegram/AuthManager.h index a9ce70a39..377925f8a 100644 --- a/td/telegram/AuthManager.h +++ b/td/telegram/AuthManager.h @@ -45,7 +45,7 @@ class AuthManager final : public NetActor { void check_password_recovery_code(uint64 query_id, string code); void recover_password(uint64 query_id, string code, string new_password, string new_hint); void log_out(uint64 query_id); - void delete_account(uint64 query_id, const string &reason); + void delete_account(uint64 query_id, string reason, string password); void on_update_login_token(); @@ -224,6 +224,9 @@ class AuthManager final : public NetActor { void send_export_login_token_query(); void set_login_token_expires_at(double login_token_expires_at); + void do_delete_account(uint64 query_id, string reason, + Result> r_input_password); + void send_log_out_query(); void destroy_auth_keys(); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index e92c07837..0ac46b802 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4639,7 +4639,7 @@ void Td::on_request(uint64 id, const td_api::setAccountTtl &request) { void Td::on_request(uint64 id, td_api::deleteAccount &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.reason_); - send_closure(auth_manager_actor_, &AuthManager::delete_account, id, request.reason_); + send_closure(auth_manager_actor_, &AuthManager::delete_account, id, request.reason_, request.password_); } void Td::on_request(uint64 id, td_api::changePhoneNumber &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 1719b55c5..879300bff 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1856,7 +1856,10 @@ class CliClient final : public Actor { // send_request(td_api::make_object()); // send_request(td_api::make_object()); } else if (op == "DeleteAccountYesIReallyWantToDeleteMyAccount") { - send_request(td_api::make_object(args)); + string password; + string reason; + get_args(args, password, reason); + send_request(td_api::make_object(reason, password)); } else if (op == "gps" || op == "GetPasswordState") { send_request(td_api::make_object()); } else if (op == "spass" || op == "SetPassword") {