Improve email address reset API.
This commit is contained in:
parent
2f006bfdfe
commit
e47adeab37
@ -87,6 +87,15 @@ emailAddressAuthenticationAppleId token:string = EmailAddressAuthentication;
|
||||
emailAddressAuthenticationGoogleId token:string = EmailAddressAuthentication;
|
||||
|
||||
|
||||
//@class EmailAddressResetState @description Describes reset state of a email address
|
||||
|
||||
//@description Email address can be reset after the given period. Call resetAuthenticationEmailAddress to reset it and allow the user to authorize with a code sent to the user's phone number @wait_period Time required to wait before the email address can be reset; 0 if the user is subscribed to Telegram Premium
|
||||
emailAddressResetStateAvailable wait_period:int32 = EmailAddressResetState;
|
||||
|
||||
//@description Email address reset has already been requested. Call resetAuthenticationEmailAddress to try to reset it immediately @reset_in Left time before the email address will be reset, in seconds. updateAuthorizationState is not sent when this field changes
|
||||
emailAddressResetStatePending reset_in:int32 = EmailAddressResetState;
|
||||
|
||||
|
||||
//@description Represents a part of the text that needs to be formatted in some unusual way @offset Offset of the entity, in UTF-16 code units @length Length of the entity, in UTF-16 code units @type Type of the entity
|
||||
textEntity offset:int32 length:int32 type:TextEntityType = TextEntity;
|
||||
|
||||
@ -119,10 +128,8 @@ authorizationStateWaitEmailAddress allow_apple_id:Bool allow_google_id:Bool = Au
|
||||
//@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
|
||||
//@can_reset_email_address True, if the email address can be reset using resetAuthenticationEmailAddress and the user will be able to authorize with a code sent to the user's phone number
|
||||
//@reset_period Time required to wait before the email address can be reset using resetAuthenticationEmailAddress if applicable; 0 if the user is subscribed to Telegram Premium
|
||||
//@reset_in Left time before the email address can be reset, in seconds; 0 if email address reset wasn't requested. updateAuthorizationState is not sent when this field changes
|
||||
authorizationStateWaitEmailCode allow_apple_id:Bool allow_google_id:Bool code_info:emailAddressAuthenticationCodeInfo can_reset_email_address:Bool reset_period:int32 reset_in:int32 = AuthorizationState;
|
||||
//@email_address_reset_state Reset state of the email address; may be null if the email address can't be reset
|
||||
authorizationStateWaitEmailCode allow_apple_id:Bool allow_google_id:Bool code_info:emailAddressAuthenticationCodeInfo email_address_reset_state:EmailAddressResetState = AuthorizationState;
|
||||
|
||||
//@description TDLib needs the user's authentication code to authorize. Call checkAuthenticationCode to check the code @code_info Information about the authorization code that was sent
|
||||
authorizationStateWaitCode code_info:authenticationCodeInfo = AuthorizationState;
|
||||
|
@ -110,12 +110,16 @@ tl_object_ptr<td_api::AuthorizationState> AuthManager::get_authorization_state_o
|
||||
case State::WaitEmailAddress:
|
||||
return make_tl_object<td_api::authorizationStateWaitEmailAddress>(allow_apple_id_, allow_google_id_);
|
||||
case State::WaitEmailCode: {
|
||||
auto can_reset_email_address = reset_available_period_ >= 0;
|
||||
auto expires_in =
|
||||
reset_pending_date_ > 0 ? clamp(reset_pending_date_ - G()->unix_time(), 1, reset_available_period_) : 0;
|
||||
td_api::object_ptr<td_api::EmailAddressResetState> reset_state;
|
||||
if (reset_pending_date_ > 0) {
|
||||
reset_state =
|
||||
td_api::make_object<td_api::emailAddressResetStatePending>(max(reset_pending_date_ - G()->unix_time(), 0));
|
||||
} else if (reset_available_period_ >= 0) {
|
||||
reset_state = td_api::make_object<td_api::emailAddressResetStateAvailable>(reset_available_period_);
|
||||
}
|
||||
return make_tl_object<td_api::authorizationStateWaitEmailCode>(
|
||||
allow_apple_id_, allow_google_id_, email_code_info_.get_email_address_authentication_code_info_object(),
|
||||
can_reset_email_address, can_reset_email_address ? reset_available_period_ : 0, expires_in);
|
||||
std::move(reset_state));
|
||||
}
|
||||
case State::WaitCode:
|
||||
return send_code_helper_.get_authorization_state_wait_code();
|
||||
@ -275,7 +279,7 @@ void AuthManager::set_phone_number(uint64 query_id, string phone_number,
|
||||
email_address_ = {};
|
||||
email_code_info_ = {};
|
||||
reset_available_period_ = -1;
|
||||
reset_pending_date_ = 0;
|
||||
reset_pending_date_ = -1;
|
||||
code_ = string();
|
||||
email_code_ = {};
|
||||
|
||||
@ -597,14 +601,12 @@ void AuthManager::on_sent_code(telegram_api::object_ptr<telegram_api::auth_SentC
|
||||
allow_google_id_ = code_type->google_signin_allowed_;
|
||||
email_address_.clear();
|
||||
email_code_info_ = SentEmailCode(std::move(code_type->email_pattern_), code_type->length_);
|
||||
if ((code_type->flags_ & telegram_api::auth_sentCodeTypeEmailCode::RESET_AVAILABLE_PERIOD_MASK) != 0) {
|
||||
reset_available_period_ = -1;
|
||||
reset_pending_date_ = -1;
|
||||
if (code_type->reset_pending_date_ > 0) {
|
||||
reset_pending_date_ = code_type->reset_pending_date_;
|
||||
} else if ((code_type->flags_ & telegram_api::auth_sentCodeTypeEmailCode::RESET_AVAILABLE_PERIOD_MASK) != 0) {
|
||||
reset_available_period_ = max(code_type->reset_available_period_, 0);
|
||||
if (reset_available_period_ > 0) {
|
||||
reset_pending_date_ = code_type->reset_pending_date_;
|
||||
}
|
||||
} else {
|
||||
reset_available_period_ = -1;
|
||||
reset_pending_date_ = 0;
|
||||
}
|
||||
if (email_code_info_.is_empty()) {
|
||||
email_code_info_ = SentEmailCode("<unknown>", code_type->length_);
|
||||
@ -659,7 +661,7 @@ void AuthManager::on_verify_email_address_result(NetQueryPtr &result) {
|
||||
return on_query_error(Status::Error(500, "Receive invalid response"));
|
||||
}
|
||||
reset_available_period_ = -1;
|
||||
reset_pending_date_ = 0;
|
||||
reset_pending_date_ = -1;
|
||||
|
||||
auto verified_login = telegram_api::move_object_as<telegram_api::account_emailVerifiedLogin>(email_verified);
|
||||
on_sent_code(std::move(verified_login->sent_code_));
|
||||
|
@ -130,7 +130,7 @@ class AuthManager final : public NetActor {
|
||||
string email_address_;
|
||||
SentEmailCode email_code_info_;
|
||||
int32 reset_available_period_ = -1;
|
||||
int32 reset_pending_date_ = 0;
|
||||
int32 reset_pending_date_ = -1;
|
||||
|
||||
// WaitEmailAddress, WaitEmailCode, WaitCode and WaitRegistration
|
||||
SendCodeHelper send_code_helper_;
|
||||
@ -245,7 +245,7 @@ class AuthManager final : public NetActor {
|
||||
string email_address_;
|
||||
SentEmailCode email_code_info_;
|
||||
int32 reset_available_period_ = -1;
|
||||
int32 reset_pending_date_ = 0;
|
||||
int32 reset_pending_date_ = -1;
|
||||
EmailVerification email_code_;
|
||||
|
||||
// State::WaitCode
|
||||
|
Loading…
Reference in New Issue
Block a user