Add checkPasswordRecoveryCode.

This commit is contained in:
levlam 2021-06-28 23:47:54 +03:00
parent 709afe3f0c
commit 18caf96c54
6 changed files with 40 additions and 8 deletions

View File

@ -3925,6 +3925,9 @@ resendRecoveryEmailAddressCode = PasswordState;
//@description Requests to send a password recovery code to an email address that was previously set up
requestPasswordRecovery = EmailAddressAuthenticationCodeInfo;
//@description Checks whether a password recovery code sent to an email address is valid @recovery_code Recovery code to check
checkPasswordRecoveryCode recovery_code:string = Ok;
//@description Recovers the password using a recovery code sent to an email address that was previously set up
//@recovery_code Recovery code to check @new_password New password of the user; may be empty to remove the password @new_hint New password hint; may be empty
recoverPassword recovery_code:string new_password:string new_hint:string = PasswordState;

View File

@ -478,6 +478,21 @@ void PasswordManager::request_password_recovery(
}));
}
void PasswordManager::check_password_recovery_code(string code, Promise<Unit> promise) {
// is called only after authorization
send_with_promise(G()->net_query_creator().create(telegram_api::auth_checkRecoveryPassword(code)),
PromiseCreator::lambda([promise = std::move(promise)](Result<NetQueryPtr> r_query) mutable {
auto r_result = fetch_result<telegram_api::auth_checkRecoveryPassword>(std::move(r_query));
if (r_result.is_error()) {
return promise.set_error(r_result.move_as_error());
}
if (!r_result.ok()) {
return promise.set_error(Status::Error(400, "Invalid recovery code"));
}
return promise.set_value(Unit());
}));
}
void PasswordManager::recover_password(string code, string new_password, string new_hint, Promise<State> promise) {
// is called only after authorization
if (new_password.empty()) {

View File

@ -80,6 +80,7 @@ class PasswordManager : public NetQueryCallback {
void check_email_address_verification_code(string code, Promise<Unit> promise);
void request_password_recovery(Promise<td_api::object_ptr<td_api::emailAddressAuthenticationCodeInfo>> promise);
void check_password_recovery_code(string code, Promise<Unit> promise);
void recover_password(string code, string new_password, string new_hint, Promise<State> promise);
void get_secure_secret(string password, Promise<secure_storage::Secret> promise);

View File

@ -4930,6 +4930,14 @@ void Td::on_request(uint64 id, td_api::requestPasswordRecovery &request) {
send_closure(password_manager_, &PasswordManager::request_password_recovery, std::move(promise));
}
void Td::on_request(uint64 id, td_api::checkPasswordRecoveryCode &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.recovery_code_);
CREATE_OK_REQUEST_PROMISE();
send_closure(password_manager_, &PasswordManager::check_password_recovery_code, std::move(request.recovery_code_),
std::move(promise));
}
void Td::on_request(uint64 id, td_api::recoverPassword &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.recovery_code_);

View File

@ -436,6 +436,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::requestPasswordRecovery &request);
void on_request(uint64 id, td_api::checkPasswordRecoveryCode &request);
void on_request(uint64 id, td_api::recoverPassword &request);
void on_request(uint64 id, td_api::getTemporaryPasswordState &request);

View File

@ -1655,14 +1655,14 @@ class CliClient final : public Actor {
} else if (op == "rapr") {
send_request(td_api::make_object<td_api::requestAuthenticationPasswordRecovery>());
} else if (op == "caprc") {
string code = args;
send_request(td_api::make_object<td_api::checkAuthenticationPasswordRecoveryCode>(code));
string recovery_code = args;
send_request(td_api::make_object<td_api::checkAuthenticationPasswordRecoveryCode>(recovery_code));
} else if (op == "rap") {
string code;
string recovery_code;
string new_password;
string new_hint;
get_args(args, code, new_password, new_hint);
send_request(td_api::make_object<td_api::recoverAuthenticationPassword>(code, new_password, new_hint));
get_args(args, recovery_code, new_password, new_hint);
send_request(td_api::make_object<td_api::recoverAuthenticationPassword>(recovery_code, new_password, new_hint));
} else if (op == "lo" || op == "LogOut" || op == "logout") {
send_request(td_api::make_object<td_api::logOut>());
} else if (op == "destroy") {
@ -1783,12 +1783,15 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::resendPhoneNumberVerificationCode>());
} else if (op == "rpr" || op == "RequestPasswordRecovery") {
send_request(td_api::make_object<td_api::requestPasswordRecovery>());
} else if (op == "cprc") {
string recovery_code = args;
send_request(td_api::make_object<td_api::checkPasswordRecoveryCode>(recovery_code));
} else if (op == "rp" || op == "RecoverPassword") {
string code;
string recovery_code;
string new_password;
string new_hint;
get_args(args, code, new_password, new_hint);
send_request(td_api::make_object<td_api::recoverPassword>(code, new_password, new_hint));
get_args(args, recovery_code, new_password, new_hint);
send_request(td_api::make_object<td_api::recoverPassword>(recovery_code, new_password, new_hint));
} else if (op == "gtp" || op == "GetTemporaryPassword") {
send_request(td_api::make_object<td_api::getTemporaryPasswordState>());
} else if (op == "ctp" || op == "CreateTemporaryPassword") {