Add td_api::checkLoginEmailAddressCode.

This commit is contained in:
levlam 2022-09-07 15:18:43 +03:00
parent cc8ef1a077
commit 1b7f24459f
6 changed files with 49 additions and 9 deletions

View File

@ -4709,6 +4709,9 @@ setLoginEmailAddress new_login_email_address:string = EmailAddressAuthentication
//@description Resends the login email address verification code //@description Resends the login email address verification code
resendLoginEmailAddressCode = EmailAddressAuthenticationCodeInfo; resendLoginEmailAddressCode = EmailAddressAuthenticationCodeInfo;
//@description Checks the login email address authentication @code Email address authentication to check
checkLoginEmailAddressCode code:EmailAddressAuthentication = Ok;
//@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 //@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; getRecoveryEmailAddress password:string = RecoveryEmailAddress;

View File

@ -201,6 +201,25 @@ void PasswordManager::resend_login_email_address_code(Promise<SentEmailCode> pro
set_login_email_address(last_set_login_email_address_, std::move(promise)); set_login_email_address(last_set_login_email_address_, std::move(promise));
} }
void PasswordManager::check_login_email_address_code(EmailVerification &&code, Promise<Unit> promise) {
if (last_set_login_email_address_.empty()) {
return promise.set_error(Status::Error(400, "No login email address code was sent"));
}
if (code.is_empty()) {
return promise.set_error(Status::Error(400, "Verification code must be non-empty"));
}
auto query = G()->net_query_creator().create(telegram_api::account_verifyEmail(
make_tl_object<telegram_api::emailVerifyPurposeLoginChange>(), code.get_input_email_verification()));
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_verifyEmail>(std::move(r_query));
if (r_result.is_error()) {
return promise.set_error(r_result.move_as_error());
}
return promise.set_value(Unit());
}));
}
void PasswordManager::set_recovery_email_address(string password, string new_recovery_email_address, void PasswordManager::set_recovery_email_address(string password, string new_recovery_email_address,
Promise<State> promise) { Promise<State> promise) {
UpdateSettings update_settings; UpdateSettings update_settings;

View File

@ -6,6 +6,7 @@
// //
#pragma once #pragma once
#include "td/telegram/EmailVerification.h"
#include "td/telegram/net/NetQuery.h" #include "td/telegram/net/NetQuery.h"
#include "td/telegram/NewPasswordState.h" #include "td/telegram/NewPasswordState.h"
#include "td/telegram/SecureStorage.h" #include "td/telegram/SecureStorage.h"
@ -70,8 +71,11 @@ class PasswordManager final : public NetQueryCallback {
void get_state(Promise<State> promise); void get_state(Promise<State> promise);
void set_password(string current_password, string new_password, string new_hint, bool set_recovery_email_address, void set_password(string current_password, string new_password, string new_hint, bool set_recovery_email_address,
string recovery_email_address, Promise<State> promise); string recovery_email_address, Promise<State> promise);
void set_login_email_address(string new_login_email_address, Promise<SentEmailCode> promise); void set_login_email_address(string new_login_email_address, Promise<SentEmailCode> promise);
void resend_login_email_address_code(Promise<SentEmailCode> promise); void resend_login_email_address_code(Promise<SentEmailCode> promise);
void check_login_email_address_code(EmailVerification &&code, Promise<Unit> promise);
void set_recovery_email_address(string password, string new_recovery_email_address, Promise<State> 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 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); void check_recovery_email_address_code(string code, Promise<State> promise);

View File

@ -4435,6 +4435,13 @@ void Td::on_request(uint64 id, const td_api::resendLoginEmailAddressCode &reques
send_closure(password_manager_, &PasswordManager::resend_login_email_address_code, std::move(query_promise)); send_closure(password_manager_, &PasswordManager::resend_login_email_address_code, std::move(query_promise));
} }
void Td::on_request(uint64 id, td_api::checkLoginEmailAddressCode &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
send_closure(password_manager_, &PasswordManager::check_login_email_address_code,
EmailVerification(std::move(request.code_)), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setRecoveryEmailAddress &request) { void Td::on_request(uint64 id, td_api::setRecoveryEmailAddress &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CLEAN_INPUT_STRING(request.password_); CLEAN_INPUT_STRING(request.password_);

View File

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

View File

@ -1591,6 +1591,17 @@ class CliClient final : public Actor {
return nullptr; return nullptr;
} }
static td_api::object_ptr<td_api::EmailAddressAuthentication> as_email_address_authentication(Slice arg) {
if (begins_with(arg, "a ")) {
return td_api::make_object<td_api::emailAddressAuthenticationAppleId>(arg.substr(2).str());
} else if (begins_with(arg, "g ")) {
return td_api::make_object<td_api::emailAddressAuthenticationGoogleId>(arg.substr(2).str());
} else if (!arg.empty()) {
return td_api::make_object<td_api::emailAddressAuthenticationCode>(arg.str());
}
return nullptr;
}
static td_api::object_ptr<td_api::PassportElementType> as_passport_element_type(Slice passport_element_type) { static td_api::object_ptr<td_api::PassportElementType> as_passport_element_type(Slice passport_element_type) {
if (passport_element_type == "address" || passport_element_type == "a") { if (passport_element_type == "address" || passport_element_type == "a") {
return td_api::make_object<td_api::passportElementTypeAddress>(); return td_api::make_object<td_api::passportElementTypeAddress>();
@ -1851,15 +1862,7 @@ class CliClient final : public Actor {
} else if (op == "sdek" || op == "SetDatabaseEncryptionKey") { } else if (op == "sdek" || op == "SetDatabaseEncryptionKey") {
send_request(td_api::make_object<td_api::setDatabaseEncryptionKey>(args)); send_request(td_api::make_object<td_api::setDatabaseEncryptionKey>(args));
} else if (op == "caec") { } else if (op == "caec") {
td_api::object_ptr<td_api::EmailAddressAuthentication> code; send_request(td_api::make_object<td_api::checkAuthenticationEmailCode>(as_email_address_authentication(args)));
if (begins_with(args, "a ")) {
code = td_api::make_object<td_api::emailAddressAuthenticationAppleId>(args.substr(2));
} else if (begins_with(args, "g ")) {
code = td_api::make_object<td_api::emailAddressAuthenticationGoogleId>(args.substr(2));
} else if (!args.empty()) {
code = td_api::make_object<td_api::emailAddressAuthenticationCode>(args);
}
send_request(td_api::make_object<td_api::checkAuthenticationEmailCode>(std::move(code)));
} else if (op == "cac") { } else if (op == "cac") {
send_request(td_api::make_object<td_api::checkAuthenticationCode>(args)); send_request(td_api::make_object<td_api::checkAuthenticationCode>(args));
} else if (op == "ru") { } else if (op == "ru") {
@ -1995,6 +1998,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::setLoginEmailAddress>(args)); send_request(td_api::make_object<td_api::setLoginEmailAddress>(args));
} else if (op == "rleac") { } else if (op == "rleac") {
send_request(td_api::make_object<td_api::resendLoginEmailAddressCode>()); send_request(td_api::make_object<td_api::resendLoginEmailAddressCode>());
} else if (op == "cleac") {
send_request(td_api::make_object<td_api::checkLoginEmailAddressCode>(as_email_address_authentication(args)));
} else if (op == "srea" || op == "SetRecoveryEmailAddress") { } else if (op == "srea" || op == "SetRecoveryEmailAddress") {
string password; string password;
string recovery_email_address; string recovery_email_address;