Allow to specify password in deleteAccount.

This commit is contained in:
levlam 2022-07-01 21:25:34 +03:00
parent 54c052adce
commit 6817f3fc44
5 changed files with 38 additions and 9 deletions

View File

@ -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

View File

@ -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<tl_object_ptr<telegram_api::InputCheckPasswordSRP>> 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<tl_object_ptr<telegram_api::InputCheckPasswordSRP>> 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) {

View File

@ -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<tl_object_ptr<telegram_api::InputCheckPasswordSRP>> r_input_password);
void send_log_out_query();
void destroy_auth_keys();

View File

@ -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) {

View File

@ -1856,7 +1856,10 @@ class CliClient final : public Actor {
// send_request(td_api::make_object<td_api::getCurrentState>());
// send_request(td_api::make_object<td_api::close>());
} else if (op == "DeleteAccountYesIReallyWantToDeleteMyAccount") {
send_request(td_api::make_object<td_api::deleteAccount>(args));
string password;
string reason;
get_args(args, password, reason);
send_request(td_api::make_object<td_api::deleteAccount>(reason, password));
} else if (op == "gps" || op == "GetPasswordState") {
send_request(td_api::make_object<td_api::getPasswordState>());
} else if (op == "spass" || op == "SetPassword") {