Add td_api::resendLoginEmailAddressCode.

This commit is contained in:
levlam 2022-09-07 14:39:33 +03:00
parent c373d14777
commit cc8ef1a077
7 changed files with 34 additions and 6 deletions

View File

@ -4640,7 +4640,7 @@ setAuthenticationPhoneNumber phone_number:string settings:phoneNumberAuthenticat
//@description Sets the email address of the user and sends an authentication code to the email address. Works only when the current authorization state is authorizationStateWaitEmailAddress @email_address The email address of the user
setAuthenticationEmailAddress email_address:string = Ok;
//@description Re-sends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitCode, the next_code_type of the result is not null and the server-specified timeout has passed
//@description Resends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitCode, the next_code_type of the result is not null and the server-specified timeout has passed
resendAuthenticationCode = Ok;
//@description Checks the authentication of a email address. Works only when the current authorization state is authorizationStateWaitEmailCode @code Email address authentication to check
@ -4706,6 +4706,9 @@ setPassword old_password:string new_password:string new_hint:string set_recovery
//@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 Resends the login email address verification code
resendLoginEmailAddressCode = 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;
@ -6143,7 +6146,7 @@ setLocation location:location = Ok;
//@phone_number The new phone number of the user in international format @settings Settings for the authentication of the user's phone number; pass null to use default settings
changePhoneNumber phone_number:string settings:phoneNumberAuthenticationSettings = AuthenticationCodeInfo;
//@description Re-sends the authentication code sent to confirm a new phone number for the current user. Works only if the previously received authenticationCodeInfo next_code_type was not null and the server-specified timeout has passed
//@description Resends the authentication code sent to confirm a new phone number for the current user. Works only if the previously received authenticationCodeInfo next_code_type was not null and the server-specified timeout has passed
resendChangePhoneNumberCode = AuthenticationCodeInfo;
//@description Checks the authentication code sent to confirm a new phone number of the user @code Authentication code to check
@ -6473,7 +6476,7 @@ getPreferredCountryLanguage country_code:string = Text;
//@phone_number The phone number of the user, in international format @settings Settings for the authentication of the user's phone number; pass null to use default settings
sendPhoneNumberVerificationCode phone_number:string settings:phoneNumberAuthenticationSettings = AuthenticationCodeInfo;
//@description Re-sends the code to verify a phone number to be added to a user's Telegram Passport
//@description Resends the code to verify a phone number to be added to a user's Telegram Passport
resendPhoneNumberVerificationCode = AuthenticationCodeInfo;
//@description Checks the phone number verification code for Telegram Passport @code Verification code to check
@ -6483,7 +6486,7 @@ checkPhoneNumberVerificationCode code:string = Ok;
//@description Sends a code to verify an email address to be added to a user's Telegram Passport @email_address Email address
sendEmailAddressVerificationCode email_address:string = EmailAddressAuthenticationCodeInfo;
//@description Re-sends the code to verify an email address to be added to a user's Telegram Passport
//@description Resends the code to verify an email address to be added to a user's Telegram Passport
resendEmailAddressVerificationCode = EmailAddressAuthenticationCodeInfo;
//@description Checks the email address verification code for Telegram Passport @code Verification code to check

View File

@ -457,7 +457,7 @@ void AuthManager::log_out(uint64 query_id) {
}
void AuthManager::send_log_out_query() {
// we can lose authorization while logging out, but still may need to re-send the request,
// we can lose authorization while logging out, but still may need to resend the request,
// so we pretend that it doesn't require authorization
auto query = G()->net_query_creator().create_unauth(telegram_api::auth_logOut());
query->set_priority(1);

View File

@ -181,7 +181,7 @@ void PasswordManager::set_password(string current_password, string new_password,
}
void PasswordManager::set_login_email_address(string new_login_email_address, Promise<SentEmailCode> promise) {
last_verified_email_address_ = new_login_email_address;
last_set_login_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),
@ -194,6 +194,13 @@ void PasswordManager::set_login_email_address(string new_login_email_address, Pr
}));
}
void PasswordManager::resend_login_email_address_code(Promise<SentEmailCode> promise) {
if (last_set_login_email_address_.empty()) {
return promise.set_error(Status::Error(400, "No login email address code was sent"));
}
set_login_email_address(last_set_login_email_address_, std::move(promise));
}
void PasswordManager::set_recovery_email_address(string password, string new_recovery_email_address,
Promise<State> promise) {
UpdateSettings update_settings;

View File

@ -71,6 +71,7 @@ class PasswordManager final : public NetQueryCallback {
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 resend_login_email_address_code(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);

View File

@ -4422,6 +4422,19 @@ void Td::on_request(uint64 id, td_api::setLoginEmailAddress &request) {
std::move(request.new_login_email_address_), std::move(query_promise));
}
void Td::on_request(uint64 id, const td_api::resendLoginEmailAddressCode &request) {
CHECK_IS_USER();
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::resend_login_email_address_code, std::move(query_promise));
}
void Td::on_request(uint64 id, td_api::setRecoveryEmailAddress &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.password_);

View File

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

View File

@ -1993,6 +1993,8 @@ class CliClient final : public Actor {
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 == "rleac") {
send_request(td_api::make_object<td_api::resendLoginEmailAddressCode>());
} else if (op == "srea" || op == "SetRecoveryEmailAddress") {
string password;
string recovery_email_address;