Add td_api::setLoginEmailAddress.

This commit is contained in:
levlam 2022-09-07 13:49:48 +03:00
parent cac1f4cd14
commit c373d14777
6 changed files with 38 additions and 0 deletions

View File

@ -4703,6 +4703,9 @@ getPasswordState = PasswordState;
//@old_password Previous 2-step verification password of the user @new_password New 2-step verification password of the user; may be empty to remove the password @new_hint New password hint; may be empty @set_recovery_email_address Pass true to change also the recovery email address @new_recovery_email_address New recovery email address; may be empty
setPassword old_password:string new_password:string new_hint:string set_recovery_email_address:Bool new_recovery_email_address:string = PasswordState;
//@description Changes the login email address of the user. The change will not be applied until the new login email address is confirmed with `checkLoginEmailAddressCode`. To use Apple ID/Google ID instead of a email address, call `checkLoginEmailAddressCode` directly @new_login_email_address New login email address
setLoginEmailAddress new_login_email_address:string = EmailAddressAuthenticationCodeInfo;
//@description Returns a 2-step verification recovery email address that was previously set up. This method can be used to verify a password provided by the user @password The 2-step verification password for the current user
getRecoveryEmailAddress password:string = RecoveryEmailAddress;

View File

@ -180,6 +180,20 @@ void PasswordManager::set_password(string current_password, string new_password,
update_password_settings(std::move(update_settings), std::move(promise));
}
void PasswordManager::set_login_email_address(string new_login_email_address, Promise<SentEmailCode> promise) {
last_verified_email_address_ = new_login_email_address;
auto query = G()->net_query_creator().create(telegram_api::account_sendVerifyEmailCode(
make_tl_object<telegram_api::emailVerifyPurposeLoginChange>(), std::move(new_login_email_address)));
send_with_promise(std::move(query),
PromiseCreator::lambda([promise = std::move(promise)](Result<NetQueryPtr> r_query) mutable {
auto r_result = fetch_result<telegram_api::account_sendVerifyEmailCode>(std::move(r_query));
if (r_result.is_error()) {
return promise.set_error(r_result.move_as_error());
}
return promise.set_value(SentEmailCode(r_result.move_as_ok()));
}));
}
void PasswordManager::set_recovery_email_address(string password, string new_recovery_email_address,
Promise<State> promise) {
UpdateSettings update_settings;

View File

@ -70,6 +70,7 @@ class PasswordManager final : public NetQueryCallback {
void get_state(Promise<State> promise);
void set_password(string current_password, string new_password, string new_hint, bool set_recovery_email_address,
string recovery_email_address, Promise<State> promise);
void set_login_email_address(string new_login_email_address, Promise<SentEmailCode> promise);
void set_recovery_email_address(string password, string new_recovery_email_address, Promise<State> promise);
void get_recovery_email_address(string password, Promise<tl_object_ptr<td_api::recoveryEmailAddress>> promise);
void check_recovery_email_address_code(string code, Promise<State> promise);
@ -155,6 +156,7 @@ class PasswordManager final : public NetQueryCallback {
TempPasswordState temp_password_state_;
Promise<TempState> create_temp_password_promise_;
string last_set_login_email_address_;
string last_verified_email_address_;
int32 last_code_length_ = 0;

View File

@ -4407,6 +4407,21 @@ void Td::on_request(uint64 id, td_api::setPassword &request) {
std::move(request.new_recovery_email_address_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setLoginEmailAddress &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.new_login_email_address_);
CREATE_REQUEST_PROMISE();
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<SentEmailCode> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
promise.set_value(result.ok().get_email_address_authentication_code_info_object());
}
});
send_closure(password_manager_, &PasswordManager::set_login_email_address,
std::move(request.new_login_email_address_), std::move(query_promise));
}
void Td::on_request(uint64 id, td_api::setRecoveryEmailAddress &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.password_);

View File

@ -434,6 +434,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::setPassword &request);
void on_request(uint64 id, td_api::setLoginEmailAddress &request);
void on_request(uint64 id, td_api::getRecoveryEmailAddress &request);
void on_request(uint64 id, td_api::setRecoveryEmailAddress &request);

View File

@ -1991,6 +1991,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::checkEmailAddressVerificationCode>(args));
} else if (op == "reavc" || op == "ResendEmailAddressVerificationCode") {
send_request(td_api::make_object<td_api::resendEmailAddressVerificationCode>());
} else if (op == "slea") {
send_request(td_api::make_object<td_api::setLoginEmailAddress>(args));
} else if (op == "srea" || op == "SetRecoveryEmailAddress") {
string password;
string recovery_email_address;