From b1347c32262d78e28f893b104b493aa2315987d6 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 16 Jul 2019 22:08:34 +0300 Subject: [PATCH] Add separate authorizationStateWaitRegistration. GitOrigin-RevId: 1e41124d6174e956ce74266c9140ad346cf8a6f0 --- example/cpp/td_example.cpp | 22 +++-- example/csharp/TdExample.cs | 8 +- .../org/drinkless/tdlib/example/Example.java | 8 +- example/python/tdjson_example.py | 6 ++ example/swift/src/main.swift | 20 ++-- example/uwp/app/MainPage.xaml.cs | 2 +- td/generate/scheme/td_api.tl | 15 ++- td/generate/scheme/td_api.tlo | Bin 156044 -> 156136 bytes td/telegram/AuthManager.cpp | 86 +++++++++++------- td/telegram/AuthManager.h | 37 +++++--- td/telegram/AuthManager.hpp | 21 +++-- td/telegram/SendCodeHelper.cpp | 7 +- td/telegram/SendCodeHelper.h | 8 +- td/telegram/SendCodeHelper.hpp | 5 +- td/telegram/Td.cpp | 9 +- td/telegram/Td.h | 2 + td/telegram/cli.cpp | 6 +- test/tdclient.cpp | 5 +- 18 files changed, 166 insertions(+), 101 deletions(-) diff --git a/example/cpp/td_example.cpp b/example/cpp/td_example.cpp index 952e78727..8bb7aafa8 100644 --- a/example/cpp/td_example.cpp +++ b/example/cpp/td_example.cpp @@ -237,19 +237,21 @@ class TdExample { need_restart_ = true; std::cerr << "Terminated" << std::endl; }, - [this](td_api::authorizationStateWaitCode &wait_code) { - std::string first_name; - std::string last_name; - if (!wait_code.is_registered_) { - std::cerr << "Enter your first name: "; - std::cin >> first_name; - std::cerr << "Enter your last name: "; - std::cin >> last_name; - } + [this](td_api::authorizationStateWaitCode &) { std::cerr << "Enter authentication code: "; std::string code; std::cin >> code; - send_query(td_api::make_object(code, first_name, last_name), + send_query(td_api::make_object(code), + create_authentication_query_handler()); + }, + [this](td_api::authorizationStateWaitRegistration &) { + std::string first_name; + std::string last_name; + std::cerr << "Enter your first name: "; + std::cin >> first_name; + std::cerr << "Enter your last name: "; + std::cin >> last_name; + send_query(td_api::make_object(first_name, last_name), create_authentication_query_handler()); }, [this](td_api::authorizationStateWaitPassword &) { diff --git a/example/csharp/TdExample.cs b/example/csharp/TdExample.cs index 4c0852327..728208976 100644 --- a/example/csharp/TdExample.cs +++ b/example/csharp/TdExample.cs @@ -98,7 +98,13 @@ namespace TdExample else if (_authorizationState is TdApi.AuthorizationStateWaitCode) { string code = ReadLine("Please enter authentication code: "); - _client.Send(new TdApi.CheckAuthenticationCode(code, "", ""), new AuthorizationRequestHandler()); + _client.Send(new TdApi.CheckAuthenticationCode(code), new AuthorizationRequestHandler()); + } + else if (_authorizationState is TdApi.AuthorizationStateWaitRegistration) + { + string firstName = ReadLine("Please enter your first name: "); + string lastName = ReadLine("Please enter your last name: "); + _client.Send(new TdApi.RegisterUser(firstName, lastName), new AuthorizationRequestHandler()); } else if (_authorizationState is TdApi.AuthorizationStateWaitPassword) { diff --git a/example/java/org/drinkless/tdlib/example/Example.java b/example/java/org/drinkless/tdlib/example/Example.java index 97ac7c7cd..70602f3c0 100644 --- a/example/java/org/drinkless/tdlib/example/Example.java +++ b/example/java/org/drinkless/tdlib/example/Example.java @@ -117,7 +117,13 @@ public final class Example { } case TdApi.AuthorizationStateWaitCode.CONSTRUCTOR: { String code = promptString("Please enter authentication code: "); - client.send(new TdApi.CheckAuthenticationCode(code, "", ""), new AuthorizationRequestHandler()); + client.send(new TdApi.CheckAuthenticationCode(code), new AuthorizationRequestHandler()); + break; + } + case TdApi.AuthorizationStateWaitRegistration.CONSTRUCTOR: { + String firstName = promptString("Please enter your first name: "); + String lastName = promptString("Please enter your last name: "); + client.send(new TdApi.RegisterUser(firstName, lastName), new AuthorizationRequestHandler()); break; } case TdApi.AuthorizationStateWaitPassword.CONSTRUCTOR: { diff --git a/example/python/tdjson_example.py b/example/python/tdjson_example.py index 8530f5ced..1ff1035da 100644 --- a/example/python/tdjson_example.py +++ b/example/python/tdjson_example.py @@ -124,6 +124,12 @@ while True: code = input('Please enter the authentication code you received: ') td_send({'@type': 'checkAuthenticationCode', 'code': code}) + # wait for first and last name for new users + if auth_state['@type'] == 'authorizationStateWaitRegistration': + first_name = input('Please enter your first name: ') + last_name = input('Please enter your last name: ') + td_send({'@type': 'registerUser', 'first_name': first_name, 'last_name': last_name}) + # wait for password if present if auth_state['@type'] == 'authorizationStateWaitPassword': password = input('Please enter your password: ') diff --git a/example/swift/src/main.swift b/example/swift/src/main.swift index dc2274727..f66c01bac 100644 --- a/example/swift/src/main.swift +++ b/example/swift/src/main.swift @@ -132,19 +132,19 @@ func updateAuthorizationState(authorizationState: Dictionary) { client.queryAsync(query:["@type":"setAuthenticationPhoneNumber", "phone_number":phone], f:checkAuthenticationError) case "authorizationStateWaitCode": - var first_name: String = "" - var last_name: String = "" var code: String = "" - if let is_registered = authorizationState["is_registered"] as? Bool, is_registered { - } else { - print("Enter your first name: ") - first_name = myReadLine() - print("Enter your last name: ") - last_name = myReadLine() - } print("Enter (SMS) code: ") code = myReadLine() - client.queryAsync(query:["@type":"checkAuthenticationCode", "code":code, "first_name":first_name, "last_name":last_name], f:checkAuthenticationError) + client.queryAsync(query:["@type":"checkAuthenticationCode", "code":code], f:checkAuthenticationError) + + case "authorizationStateWaitRegistration": + var first_name: String = "" + var last_name: String = "" + print("Enter your first name: ") + first_name = myReadLine() + print("Enter your last name: ") + last_name = myReadLine() + client.queryAsync(query:["@type":"registerUser", "first_name":first_name, "last_name":last_name], f:checkAuthenticationError) case "authorizationStateWaitPassword": print("Enter password: ") diff --git a/example/uwp/app/MainPage.xaml.cs b/example/uwp/app/MainPage.xaml.cs index 1c1aa515d..4a8d85c91 100644 --- a/example/uwp/app/MainPage.xaml.cs +++ b/example/uwp/app/MainPage.xaml.cs @@ -100,7 +100,7 @@ namespace TdApp { var args = command.Split(" ".ToCharArray(), 2); AcceptCommand(command); - _client.Send(new TdApi.CheckAuthenticationCode(args[1], String.Empty, String.Empty), _handler); + _client.Send(new TdApi.CheckAuthenticationCode(args[1]), _handler); } else if (command.StartsWith("cap")) { diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index fb2f81d5b..917fcec8b 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -88,8 +88,11 @@ authorizationStateWaitEncryptionKey is_encrypted:Bool = AuthorizationState; //@description TDLib needs the user's phone number to authorize authorizationStateWaitPhoneNumber = AuthorizationState; -//@description TDLib needs the user's authentication code to finalize authorization @is_registered True, if the user is already registered @terms_of_service Telegram terms of service, which should be accepted before user can continue registration; may be null @code_info Information about the authorization code that was sent -authorizationStateWaitCode is_registered:Bool terms_of_service:termsOfService code_info:authenticationCodeInfo = AuthorizationState; +//@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; + +//@description The user is unregistered and need to accept terms of service and enter his first name and last name to finish registration @terms_of_service Telegram terms of service +authorizationStateWaitRegistration terms_of_service:termsOfService = AuthorizationState; //@description The user has been authorized, but needs to enter a password to start using the application @password_hint Hint for the password; may be empty @has_recovery_email_address True, if a recovery email address has been set up //@recovery_email_address_pattern Pattern of the email address to which the recovery email was sent; empty until a recovery email has been sent @@ -2805,9 +2808,11 @@ setAuthenticationPhoneNumber phone_number:string settings:phoneNumberAuthenticat resendAuthenticationCode = Ok; //@description Checks the authentication code. Works only when the current authorization state is authorizationStateWaitCode @code The verification code received via SMS, Telegram message, phone call, or flash call -//@first_name If the user is not yet registered, the first name of the user; 1-64 characters. You can also pass an empty string for unregistered user there to check verification code validness. In the latter case PHONE_NUMBER_UNOCCUPIED error will be returned for a valid code -//@last_name If the user is not yet registered; the last name of the user; optional; 0-64 characters -checkAuthenticationCode code:string first_name:string last_name:string = Ok; +checkAuthenticationCode code:string = Ok; + +//@description Finishes user registration. Works only when the current authorization state is authorizationStateWaitRegistration +//@first_name The first name of the user; 1-64 characters @last_name The last name of the user; 0-64 characters +registerUser first_name:string last_name:string = Ok; //@description Checks the authentication password for correctness. Works only when the current authorization state is authorizationStateWaitPassword @password The password to check checkAuthenticationPassword password:string = Ok; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 12725b14d6432a0c01ce8513da34306623dca88c..abb68f6354f0cae432563f94a36eaadd3a338d72 100644 GIT binary patch delta 455 zcmeA<%=zLl=Y|+Y7Hf~^A0{U-iZF6bc4QIX+{5Uj&UktAO$~W=36RvyV?sU*Kv3k& zro&;|b`Y#wz`z8e&%?k1!e}ut(ZHn~q#XpV%5lXox+*hIeqbQO2~*5CInq#H6vTrl zf+$-py90I9Dp~b01(-nQ0gr~=NGsSEV Jkz=xO1^{hPrRo3x delta 431 zcmaEHn6u|F=Y|+YmZM@zwI?SqiZF6cc4QIX+{5Uj&Uk6_O$~W=36RvyV?sU*Kv3k& zro&;|b`Y#wz`z8e&%?k1!e}ut(ZHn~q#XpV%5lX6Y+dtX@&f}I8JJ>bpoH|Z`6yhPsYR17+?1WZb~dB>WDY|ei1`}~4LIRiroUBTOrGpxWCM}wG19>8)H6l~ zxFto5b#O~Y;E`;eW4wKiF(ZpBE67m{(-|un<+mTHVEp397`A=qF2-nnmfpVWSEoyy zVpL#co?KWXK0V+RBhTas(^;qgUCih_z2GpT#P*U?j1`JF9k89{4Wo|H_6>4O7R~_1 C?vf|~ diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index 9907e1f45..6289c53a3 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -99,9 +99,12 @@ tl_object_ptr AuthManager::get_authorization_state_o case State::Ok: return make_tl_object(); case State::WaitCode: - return send_code_helper_.get_authorization_state_wait_code(terms_of_service_); + return send_code_helper_.get_authorization_state_wait_code(); case State::WaitPhoneNumber: return make_tl_object(); + case State::WaitRegistration: + return make_tl_object( + terms_of_service_.get_terms_of_service_object()); case State::WaitPassword: return make_tl_object( wait_password_state_.hint_, wait_password_state_.has_recovery_, wait_password_state_.email_address_pattern_); @@ -169,7 +172,8 @@ void AuthManager::check_bot_token(uint64 query_id, string bot_token) { void AuthManager::set_phone_number(uint64 query_id, string phone_number, td_api::object_ptr settings) { if (state_ != State::WaitPhoneNumber) { - if ((state_ == State::WaitCode || state_ == State::WaitPassword) && net_query_id_ == 0) { + if ((state_ == State::WaitCode || state_ == State::WaitPassword || state_ == State::WaitRegistration) && + net_query_id_ == 0) { // ok } else { return on_query_error(query_id, Status::Error(8, "setAuthenticationPhoneNumber unexpected")); @@ -218,33 +222,38 @@ void AuthManager::resend_authentication_code(uint64 query_id) { NetQuery::Type::Common, NetQuery::AuthFlag::Off)); } -void AuthManager::check_code(uint64 query_id, string code, string first_name, string last_name) { +void AuthManager::check_code(uint64 query_id, string code) { if (state_ != State::WaitCode) { return on_query_error(query_id, Status::Error(8, "checkAuthenticationCode unexpected")); } - code_ = code; + code_ = std::move(code); on_new_query(query_id); - if (send_code_helper_.phone_registered() || first_name.empty()) { - start_net_query(NetQueryType::SignIn, - G()->net_query_creator().create( - create_storer(telegram_api::auth_signIn(send_code_helper_.phone_number().str(), - send_code_helper_.phone_code_hash().str(), code)), - DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off)); - } else { - first_name = clean_name(first_name, MAX_NAME_LENGTH); - if (first_name.empty()) { - return on_query_error(Status::Error(8, "First name can't be empty")); - } + start_net_query(NetQueryType::SignIn, + G()->net_query_creator().create( + create_storer(telegram_api::auth_signIn(send_code_helper_.phone_number().str(), + send_code_helper_.phone_code_hash().str(), code_)), + DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off)); +} - last_name = clean_name(last_name, MAX_NAME_LENGTH); - start_net_query( - NetQueryType::SignUp, - G()->net_query_creator().create(create_storer(telegram_api::auth_signUp( - send_code_helper_.phone_number().str(), - send_code_helper_.phone_code_hash().str(), code, first_name, last_name)), - DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off)); +void AuthManager::register_user(uint64 query_id, string first_name, string last_name) { + if (state_ != State::WaitRegistration) { + return on_query_error(query_id, Status::Error(8, "registerUser unexpected")); } + + on_new_query(query_id); + first_name = clean_name(first_name, MAX_NAME_LENGTH); + if (first_name.empty()) { + return on_query_error(Status::Error(8, "First name can't be empty")); + } + + last_name = clean_name(last_name, MAX_NAME_LENGTH); + start_net_query( + NetQueryType::SignUp, + G()->net_query_creator().create(create_storer(telegram_api::auth_signUp(send_code_helper_.phone_number().str(), + send_code_helper_.phone_code_hash().str(), + code_, first_name, last_name)), + DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off)); } void AuthManager::check_password(uint64 query_id, string password) { @@ -374,7 +383,9 @@ void AuthManager::on_send_code_result(NetQueryPtr &result) { LOG(INFO) << "Receive " << to_string(sent_code); - terms_of_service_ = TermsOfService(std::move(sent_code->terms_of_service_)); + if (terms_of_service_.get_id().empty()) { + terms_of_service_ = TermsOfService(std::move(sent_code->terms_of_service_)); + } send_code_helper_.on_sent_code(std::move(sent_code)); @@ -591,6 +602,12 @@ void AuthManager::on_result(NetQueryPtr result) { DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off)); return; } + if (type == NetQueryType::SignIn && result->error().message() == CSlice("PHONE_NUMBER_UNOCCUPIED")) { + code_ = "11111"; + update_state(State::WaitRegistration); + on_query_ok(); + return; + } if (type != NetQueryType::LogOut) { if (query_id_ != 0) { if (state_ == State::WaitPhoneNumber) { @@ -686,6 +703,9 @@ bool AuthManager::load_state() { terms_of_service_ = std::move(db_state.terms_of_service_); } else if (db_state.state_ == State::WaitPassword) { wait_password_state_ = std::move(db_state.wait_password_state_); + } else if (db_state.state_ == State::WaitRegistration) { + code_ = "11111"; // the code has already been checked + terms_of_service_ = std::move(db_state.terms_of_service_); } else { UNREACHABLE(); } @@ -694,21 +714,23 @@ bool AuthManager::load_state() { } void AuthManager::save_state() { - if (state_ != State::WaitCode && state_ != State::WaitPassword) { + if (state_ != State::WaitCode && state_ != State::WaitPassword && state_ != State::WaitRegistration) { if (state_ != State::Closing) { G()->td_db()->get_binlog_pmc()->erase("auth_state"); } return; } - DbState db_state; - if (state_ == State::WaitCode) { - db_state = DbState::wait_code(api_id_, api_hash_, send_code_helper_, terms_of_service_); - } else if (state_ == State::WaitPassword) { - db_state = DbState::wait_password(api_id_, api_hash_, wait_password_state_); - } else { - UNREACHABLE(); - } + DbState db_state = [&] { + if (state_ == State::WaitCode) { + return DbState::wait_code(api_id_, api_hash_, send_code_helper_, terms_of_service_); + } else if (state_ == State::WaitPassword) { + return DbState::wait_password(api_id_, api_hash_, wait_password_state_); + } else { + CHECK(state_ == State::WaitRegistration); + return DbState::wait_registration(api_id_, api_hash_, terms_of_service_); + } + }(); G()->td_db()->get_binlog_pmc()->set("auth_state", log_event_store(db_state).as_slice().str()); } diff --git a/td/telegram/AuthManager.h b/td/telegram/AuthManager.h index 28deff855..8521f4e43 100644 --- a/td/telegram/AuthManager.h +++ b/td/telegram/AuthManager.h @@ -35,7 +35,8 @@ class AuthManager : public NetActor { void set_phone_number(uint64 query_id, string phone_number, td_api::object_ptr settings); void resend_authentication_code(uint64 query_id); - void check_code(uint64 query_id, string code, string first_name, string last_name); + void check_code(uint64 query_id, string code); + void register_user(uint64 query_id, string first_name, string last_name); void check_bot_token(uint64 query_id, string bot_token); void check_password(uint64 query_id, string password); void request_password_recovery(uint64 query_id); @@ -57,6 +58,7 @@ class AuthManager : public NetActor { WaitPhoneNumber, WaitCode, WaitPassword, + WaitRegistration, Ok, LoggingOut, DestroyingKeys, @@ -102,30 +104,32 @@ class AuthManager : public NetActor { // WaitCode SendCodeHelper send_code_helper_; - TermsOfService terms_of_service_; // WaitPassword WaitPasswordState wait_password_state_; + // WaitRegistration + TermsOfService terms_of_service_; + + DbState() = default; + // TODO layer 104+: remove terms_of_service static DbState wait_code(int32 api_id, string api_hash, SendCodeHelper send_code_helper, TermsOfService terms_of_service) { - DbState state; - state.state_ = State::WaitCode; - state.api_id_ = api_id; - state.api_hash_ = api_hash; + DbState state(State::WaitCode, api_id, api_hash); state.send_code_helper_ = std::move(send_code_helper); state.terms_of_service_ = std::move(terms_of_service); - state.state_timestamp_ = Timestamp::now(); return state; } static DbState wait_password(int32 api_id, string api_hash, WaitPasswordState wait_password_state) { - DbState state; - state.state_ = State::WaitPassword; - state.api_id_ = api_id; - state.api_hash_ = api_hash; + DbState state(State::WaitPassword, api_id, api_hash); state.wait_password_state_ = std::move(wait_password_state); - state.state_timestamp_ = Timestamp::now(); + return state; + } + + static DbState wait_registration(int32 api_id, string api_hash, TermsOfService terms_of_service) { + DbState state(State::WaitRegistration, api_id, api_hash); + state.terms_of_service_ = std::move(terms_of_service); return state; } @@ -133,6 +137,11 @@ class AuthManager : public NetActor { void store(StorerT &storer) const; template void parse(ParserT &parser); + + private: + DbState(State state, int32 api_id, string api_hash) + : state_(state), api_id_(api_id), api_hash_(api_hash), state_timestamp_(Timestamp::now()) { + } }; bool load_state(); @@ -148,7 +157,11 @@ class AuthManager : public NetActor { // State::WaitCode SendCodeHelper send_code_helper_; string code_; + + // State::WaitPassword string password_; + + // State::WaitRegistration TermsOfService terms_of_service_; // for bots diff --git a/td/telegram/AuthManager.hpp b/td/telegram/AuthManager.hpp index cadf6454d..26b78eeb2 100644 --- a/td/telegram/AuthManager.hpp +++ b/td/telegram/AuthManager.hpp @@ -51,10 +51,12 @@ void AuthManager::DbState::store(StorerT &storer) const { bool has_terms_of_service = !terms_of_service_.get_id().empty(); bool is_pbkdf2_supported = true; bool is_srp_supported = true; + bool is_wait_registration_supported = true; BEGIN_STORE_FLAGS(); STORE_FLAG(has_terms_of_service); STORE_FLAG(is_pbkdf2_supported); STORE_FLAG(is_srp_supported); + STORE_FLAG(is_wait_registration_supported); END_STORE_FLAGS(); store(state_, storer); store(api_id_, storer); @@ -69,6 +71,7 @@ void AuthManager::DbState::store(StorerT &storer) const { store(send_code_helper_, storer); } else if (state_ == State::WaitPassword) { store(wait_password_state_, storer); + } else if (state_ == State::WaitRegistration) { } else { UNREACHABLE(); } @@ -80,13 +83,21 @@ void AuthManager::DbState::parse(ParserT &parser) { bool has_terms_of_service = false; bool is_pbkdf2_supported = false; bool is_srp_supported = false; + bool is_wait_registration_supported = false; if (parser.version() >= static_cast(Version::AddTermsOfService)) { BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_terms_of_service); PARSE_FLAG(is_pbkdf2_supported); PARSE_FLAG(is_srp_supported); + PARSE_FLAG(is_wait_registration_supported); END_PARSE_FLAGS(); } + if (!is_wait_registration_supported) { + return parser.set_error("Have no wait registration support"); + } + CHECK(is_pbkdf2_supported); + CHECK(is_srp_supported); + parse(state_, parser); parse(api_id_, parser); parse(api_hash_, parser); @@ -98,17 +109,9 @@ void AuthManager::DbState::parse(ParserT &parser) { if (state_ == State::WaitCode) { parse(send_code_helper_, parser); - if (parser.version() < static_cast(Version::AddTermsOfService)) { - return parser.set_error("Have no terms of service"); - } } else if (state_ == State::WaitPassword) { - if (!is_pbkdf2_supported) { - return parser.set_error("Need PBKDF2 support"); - } - if (!is_srp_supported) { - return parser.set_error("Need SRP support"); - } parse(wait_password_state_, parser); + } else if (state_ == State::WaitRegistration) { } else { parser.set_error(PSTRING() << "Unexpected " << tag("state", static_cast(state_))); } diff --git a/td/telegram/SendCodeHelper.cpp b/td/telegram/SendCodeHelper.cpp index 5728e3d7f..ae2487153 100644 --- a/td/telegram/SendCodeHelper.cpp +++ b/td/telegram/SendCodeHelper.cpp @@ -11,17 +11,14 @@ namespace td { void SendCodeHelper::on_sent_code(telegram_api::object_ptr sent_code) { - phone_registered_ = (sent_code->flags_ & SENT_CODE_FLAG_IS_USER_REGISTERED) != 0; phone_code_hash_ = sent_code->phone_code_hash_; sent_code_info_ = get_authentication_code_info(std::move(sent_code->type_)); next_code_info_ = get_authentication_code_info(std::move(sent_code->next_type_)); next_code_timestamp_ = Timestamp::in((sent_code->flags_ & SENT_CODE_FLAG_HAS_TIMEOUT) != 0 ? sent_code->timeout_ : 0); } -td_api::object_ptr SendCodeHelper::get_authorization_state_wait_code( - const TermsOfService &terms_of_service) const { - return make_tl_object( - phone_registered_, terms_of_service.get_terms_of_service_object(), get_authentication_code_info_object()); +td_api::object_ptr SendCodeHelper::get_authorization_state_wait_code() const { + return make_tl_object(get_authentication_code_info_object()); } td_api::object_ptr SendCodeHelper::get_authentication_code_info_object() const { diff --git a/td/telegram/SendCodeHelper.h b/td/telegram/SendCodeHelper.h index 90041ed7a..54b3659dc 100644 --- a/td/telegram/SendCodeHelper.h +++ b/td/telegram/SendCodeHelper.h @@ -8,7 +8,6 @@ #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" -#include "td/telegram/TermsOfService.h" #include "td/utils/common.h" #include "td/utils/Slice.h" @@ -20,8 +19,7 @@ namespace td { class SendCodeHelper { public: void on_sent_code(telegram_api::object_ptr sent_code); - td_api::object_ptr get_authorization_state_wait_code( - const TermsOfService &terms_of_service) const; + td_api::object_ptr get_authorization_state_wait_code() const; td_api::object_ptr get_authentication_code_info_object() const; Result resend_code(); @@ -45,9 +43,6 @@ class SendCodeHelper { Slice phone_code_hash() const { return phone_code_hash_; } - bool phone_registered() const { - return phone_registered_; - } template void store(StorerT &storer) const; @@ -77,7 +72,6 @@ class SendCodeHelper { }; string phone_number_; - bool phone_registered_; string phone_code_hash_; SendCodeHelper::AuthenticationCodeInfo sent_code_info_; diff --git a/td/telegram/SendCodeHelper.hpp b/td/telegram/SendCodeHelper.hpp index 781451890..55abfdeb5 100644 --- a/td/telegram/SendCodeHelper.hpp +++ b/td/telegram/SendCodeHelper.hpp @@ -32,7 +32,7 @@ template void SendCodeHelper::store(StorerT &storer) const { using td::store; store(phone_number_, storer); - store(phone_registered_, storer); + store(true, storer); store(phone_code_hash_, storer); store(sent_code_info_, storer); store(next_code_info_, storer); @@ -41,9 +41,10 @@ void SendCodeHelper::store(StorerT &storer) const { template void SendCodeHelper::parse(ParserT &parser) { + bool legacy_is_registered = false; using td::parse; parse(phone_number_, parser); - parse(phone_registered_, parser); + parse(legacy_is_registered, parser); parse(phone_code_hash_, parser); parse(sent_code_info_, parser); parse(next_code_info_, parser); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 822d8a3a9..62aa12ba1 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3254,6 +3254,7 @@ bool Td::is_authentication_request(int32 id) { case td_api::setAuthenticationPhoneNumber::ID: case td_api::resendAuthenticationCode::ID: case td_api::checkAuthenticationCode::ID: + case td_api::registerUser::ID: case td_api::checkAuthenticationPassword::ID: case td_api::requestAuthenticationPasswordRecovery::ID: case td_api::recoverAuthenticationPassword::ID: @@ -4741,10 +4742,14 @@ void Td::on_request(uint64 id, const td_api::resendAuthenticationCode &request) void Td::on_request(uint64 id, td_api::checkAuthenticationCode &request) { CLEAN_INPUT_STRING(request.code_); + send_closure(auth_manager_actor_, &AuthManager::check_code, id, std::move(request.code_)); +} + +void Td::on_request(uint64 id, td_api::registerUser &request) { CLEAN_INPUT_STRING(request.first_name_); CLEAN_INPUT_STRING(request.last_name_); - send_closure(auth_manager_actor_, &AuthManager::check_code, id, std::move(request.code_), - std::move(request.first_name_), std::move(request.last_name_)); + send_closure(auth_manager_actor_, &AuthManager::register_user, id, std::move(request.first_name_), + std::move(request.last_name_)); } void Td::on_request(uint64 id, td_api::checkAuthenticationPassword &request) { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 2a4140820..259d0dcb8 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -372,6 +372,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::checkAuthenticationCode &request); + void on_request(uint64 id, td_api::registerUser &request); + void on_request(uint64 id, td_api::checkAuthenticationPassword &request); void on_request(uint64 id, const td_api::requestAuthenticationPasswordRecovery &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index bc1fc929c..7e4f97729 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1264,14 +1264,14 @@ class CliClient final : public Actor { } else if (op == "sdek" || op == "SetDatabaseEncryptionKey") { send_request(td_api::make_object(args)); } else if (op == "cac") { - string code; + send_request(td_api::make_object(args)); + } else if (op == "ru") { string first_name; string last_name; - std::tie(code, args) = split(args); std::tie(first_name, last_name) = split(args); - send_request(td_api::make_object(code, first_name, last_name)); + send_request(td_api::make_object(first_name, last_name)); } else if (op == "cap") { send_request(td_api::make_object(args)); } else if (op == "cab" || op == "cabt") { diff --git a/test/tdclient.cpp b/test/tdclient.cpp index e5d222a1a..38743a4b1 100644 --- a/test/tdclient.cpp +++ b/test/tdclient.cpp @@ -215,7 +215,10 @@ class DoAuthentication : public Task { function = make_tl_object(phone_, nullptr); break; case td_api::authorizationStateWaitCode::ID: - function = make_tl_object(code_, name_, ""); + function = make_tl_object(code_); + break; + case td_api::authorizationStateWaitRegistration::ID: + function = make_tl_object(name_, ""); break; case td_api::authorizationStateWaitTdlibParameters::ID: { auto parameters = td_api::make_object();