Add authorizationStateWaitEmailCode.next_phone_number_authorization_date.

This commit is contained in:
levlam 2022-09-06 18:15:43 +03:00
parent cba73d5bba
commit 8f16191182
4 changed files with 17 additions and 5 deletions

View File

@ -109,8 +109,10 @@ authorizationStateWaitPhoneNumber = AuthorizationState;
authorizationStateWaitEmailAddress allow_apple_id:Bool allow_google_id:Bool = AuthorizationState; authorizationStateWaitEmailAddress allow_apple_id:Bool allow_google_id:Bool = AuthorizationState;
//@description TDLib needs the user's authentication code sent to an email address to authorize. Call `checkAuthenticationEmailCode` to provide the code //@description TDLib needs the user's authentication code sent to an email address to authorize. Call `checkAuthenticationEmailCode` to provide the code
//@allow_apple_id True, if authorization through Apple ID is allowed @allow_google_id True, if authorization through Google ID is allowed @code_info Information about the sent authentication code //@allow_apple_id True, if authorization through Apple ID is allowed @allow_google_id True, if authorization through Google ID is allowed
authorizationStateWaitEmailCode allow_apple_id:Bool allow_google_id:Bool code_info:emailAddressAuthenticationCodeInfo = AuthorizationState; //@code_info Information about the sent authentication code
//@next_phone_number_authorization_date Point in time (Unix timestamp) when the user will be able to authorize with a code sent to the user's phone number; 0 if unknown
authorizationStateWaitEmailCode allow_apple_id:Bool allow_google_id:Bool code_info:emailAddressAuthenticationCodeInfo next_phone_number_authorization_date:int32 = AuthorizationState;
//@description TDLib needs the user's authentication code to authorize @code_info Information about the authorization code that was sent //@description TDLib needs the user's authentication code to authorize @code_info Information about the authorization code that was sent
authorizationStateWaitCode code_info:authenticationCodeInfo = AuthorizationState; authorizationStateWaitCode code_info:authenticationCodeInfo = AuthorizationState;

View File

@ -111,7 +111,8 @@ tl_object_ptr<td_api::AuthorizationState> AuthManager::get_authorization_state_o
return make_tl_object<td_api::authorizationStateWaitEmailAddress>(allow_apple_id_, allow_google_id_); return make_tl_object<td_api::authorizationStateWaitEmailAddress>(allow_apple_id_, allow_google_id_);
case State::WaitEmailCode: case State::WaitEmailCode:
return make_tl_object<td_api::authorizationStateWaitEmailCode>( return make_tl_object<td_api::authorizationStateWaitEmailCode>(
allow_apple_id_, allow_google_id_, email_code_info_.get_email_address_authentication_code_info_object()); allow_apple_id_, allow_google_id_, email_code_info_.get_email_address_authentication_code_info_object(),
next_phone_number_login_date_);
case State::WaitCode: case State::WaitCode:
return send_code_helper_.get_authorization_state_wait_code(); return send_code_helper_.get_authorization_state_wait_code();
case State::WaitQrCodeConfirmation: case State::WaitQrCodeConfirmation:
@ -268,6 +269,7 @@ void AuthManager::set_phone_number(uint64 query_id, string phone_number,
allow_google_id_ = false; allow_google_id_ = false;
email_address_ = {}; email_address_ = {};
email_code_info_ = {}; email_code_info_ = {};
next_phone_number_login_date_ = 0;
code_ = string(); code_ = string();
email_code_ = nullptr; email_code_ = nullptr;
@ -562,6 +564,7 @@ void AuthManager::on_sent_code(telegram_api::object_ptr<telegram_api::auth_sentC
allow_google_id_ = code_type->google_signin_allowed_; allow_google_id_ = code_type->google_signin_allowed_;
email_address_.clear(); email_address_.clear();
email_code_info_ = SentEmailCode(std::move(code_type->email_pattern_), code_type->length_); email_code_info_ = SentEmailCode(std::move(code_type->email_pattern_), code_type->length_);
next_phone_number_login_date_ = td::max(static_cast<int32>(0), code_type->next_phone_login_date_);
if (email_code_info_.is_empty()) { if (email_code_info_.is_empty()) {
email_code_info_ = SentEmailCode("<unknown>", code_type->length_); email_code_info_ = SentEmailCode("<unknown>", code_type->length_);
CHECK(!email_code_info_.is_empty()); CHECK(!email_code_info_.is_empty());
@ -598,6 +601,7 @@ void AuthManager::on_send_email_code_result(NetQueryPtr &result) {
if (email_code_info_.is_empty()) { if (email_code_info_.is_empty()) {
return on_query_error(Status::Error(500, "Receive invalid response")); return on_query_error(Status::Error(500, "Receive invalid response"));
} }
next_phone_number_login_date_ = 0;
update_state(State::WaitEmailCode, true); update_state(State::WaitEmailCode, true);
on_query_ok(); on_query_ok();
@ -1146,6 +1150,7 @@ bool AuthManager::load_state() {
allow_google_id_ = db_state.allow_google_id_; allow_google_id_ = db_state.allow_google_id_;
email_address_ = std::move(db_state.email_address_); email_address_ = std::move(db_state.email_address_);
email_code_info_ = std::move(db_state.email_code_info_); email_code_info_ = std::move(db_state.email_code_info_);
next_phone_number_login_date_ = db_state.next_phone_number_login_date_;
send_code_helper_ = std::move(db_state.send_code_helper_); send_code_helper_ = std::move(db_state.send_code_helper_);
} else if (db_state.state_ == State::WaitCode) { } else if (db_state.state_ == State::WaitCode) {
send_code_helper_ = std::move(db_state.send_code_helper_); send_code_helper_ = std::move(db_state.send_code_helper_);
@ -1179,7 +1184,7 @@ void AuthManager::save_state() {
return DbState::wait_email_address(api_id_, api_hash_, allow_apple_id_, allow_google_id_, send_code_helper_); return DbState::wait_email_address(api_id_, api_hash_, allow_apple_id_, allow_google_id_, send_code_helper_);
} else if (state_ == State::WaitEmailCode) { } else if (state_ == State::WaitEmailCode) {
return DbState::wait_email_code(api_id_, api_hash_, allow_apple_id_, allow_google_id_, email_address_, return DbState::wait_email_code(api_id_, api_hash_, allow_apple_id_, allow_google_id_, email_address_,
email_code_info_, send_code_helper_); email_code_info_, next_phone_number_login_date_, send_code_helper_);
} else if (state_ == State::WaitCode) { } else if (state_ == State::WaitCode) {
return DbState::wait_code(api_id_, api_hash_, send_code_helper_); return DbState::wait_code(api_id_, api_hash_, send_code_helper_);
} else if (state_ == State::WaitQrCodeConfirmation) { } else if (state_ == State::WaitQrCodeConfirmation) {

View File

@ -125,6 +125,7 @@ class AuthManager final : public NetActor {
// WaitEmailCode // WaitEmailCode
string email_address_; string email_address_;
SentEmailCode email_code_info_; SentEmailCode email_code_info_;
int32 next_phone_number_login_date_ = 0;
// WaitEmailAddress, WaitEmailCode, WaitCode and WaitRegistration // WaitEmailAddress, WaitEmailCode, WaitCode and WaitRegistration
SendCodeHelper send_code_helper_; SendCodeHelper send_code_helper_;
@ -153,13 +154,14 @@ class AuthManager final : public NetActor {
static DbState wait_email_code(int32 api_id, string api_hash, bool allow_apple_id, bool allow_google_id, static DbState wait_email_code(int32 api_id, string api_hash, bool allow_apple_id, bool allow_google_id,
string email_address, SentEmailCode email_code_info, string email_address, SentEmailCode email_code_info,
SendCodeHelper send_code_helper) { int32 next_phone_number_login_date, SendCodeHelper send_code_helper) {
DbState state(State::WaitEmailCode, api_id, std::move(api_hash)); DbState state(State::WaitEmailCode, api_id, std::move(api_hash));
state.send_code_helper_ = std::move(send_code_helper); state.send_code_helper_ = std::move(send_code_helper);
state.allow_apple_id_ = allow_apple_id; state.allow_apple_id_ = allow_apple_id;
state.allow_google_id_ = allow_google_id; state.allow_google_id_ = allow_google_id;
state.email_address_ = std::move(email_address); state.email_address_ = std::move(email_address);
state.email_code_info_ = std::move(email_code_info); state.email_code_info_ = std::move(email_code_info);
state.next_phone_number_login_date_ = next_phone_number_login_date;
return state; return state;
} }
@ -220,6 +222,7 @@ class AuthManager final : public NetActor {
// State::WaitEmailCode // State::WaitEmailCode
string email_address_; string email_address_;
SentEmailCode email_code_info_; SentEmailCode email_code_info_;
int32 next_phone_number_login_date_ = 0;
td_api::object_ptr<td_api::EmailAddressAuthentication> email_code_; td_api::object_ptr<td_api::EmailAddressAuthentication> email_code_;
// State::WaitCode // State::WaitCode

View File

@ -80,6 +80,7 @@ void AuthManager::DbState::store(StorerT &storer) const {
store(send_code_helper_, storer); store(send_code_helper_, storer);
store(email_address_, storer); store(email_address_, storer);
store(email_code_info_, storer); store(email_code_info_, storer);
store(next_phone_number_login_date_, storer);
} else if (state_ == State::WaitCode) { } else if (state_ == State::WaitCode) {
store(send_code_helper_, storer); store(send_code_helper_, storer);
} else if (state_ == State::WaitQrCodeConfirmation) { } else if (state_ == State::WaitQrCodeConfirmation) {
@ -139,6 +140,7 @@ void AuthManager::DbState::parse(ParserT &parser) {
parse(send_code_helper_, parser); parse(send_code_helper_, parser);
parse(email_address_, parser); parse(email_address_, parser);
parse(email_code_info_, parser); parse(email_code_info_, parser);
parse(next_phone_number_login_date_, parser);
} else if (state_ == State::WaitCode) { } else if (state_ == State::WaitCode) {
parse(send_code_helper_, parser); parse(send_code_helper_, parser);
} else if (state_ == State::WaitQrCodeConfirmation) { } else if (state_ == State::WaitQrCodeConfirmation) {