2019-02-16 17:01:47 +01:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
2019-02-16 17:01:47 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/telegram/net/NetActor.h"
|
|
|
|
#include "td/telegram/net/NetQuery.h"
|
|
|
|
#include "td/telegram/SendCodeHelper.h"
|
2019-05-14 16:26:13 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
2021-10-20 09:46:01 +02:00
|
|
|
#include "td/telegram/telegram_api.h"
|
2019-02-16 17:01:47 +01:00
|
|
|
|
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2019-02-17 14:52:34 +01:00
|
|
|
#include "td/utils/Status.h"
|
2019-02-16 17:01:47 +01:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class PhoneNumberManager final : public NetActor {
|
2019-02-16 17:01:47 +01:00
|
|
|
public:
|
|
|
|
enum class Type : int32 { ChangePhone, VerifyPhone, ConfirmPhone };
|
|
|
|
PhoneNumberManager(Type type, ActorShared<> parent);
|
|
|
|
void get_state(uint64 query_id);
|
|
|
|
|
2019-05-03 04:44:59 +02:00
|
|
|
using Settings = td_api::object_ptr<td_api::phoneNumberAuthenticationSettings>;
|
|
|
|
|
|
|
|
void set_phone_number(uint64 query_id, string phone_number, Settings settings);
|
|
|
|
void set_phone_number_and_hash(uint64 query_id, string hash, string phone_number, Settings settings);
|
2019-02-16 17:01:47 +01:00
|
|
|
|
|
|
|
void resend_authentication_code(uint64 query_id);
|
|
|
|
void check_code(uint64 query_id, string code);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Type type_;
|
|
|
|
|
|
|
|
enum class State : int32 { Ok, WaitCode } state_ = State::Ok;
|
|
|
|
enum class NetQueryType : int32 { None, SendCode, CheckCode };
|
|
|
|
|
|
|
|
ActorShared<> parent_;
|
|
|
|
uint64 query_id_ = 0;
|
|
|
|
uint64 net_query_id_ = 0;
|
|
|
|
NetQueryType net_query_type_;
|
|
|
|
|
|
|
|
SendCodeHelper send_code_helper_;
|
|
|
|
|
|
|
|
void on_new_query(uint64 query_id);
|
2021-10-20 09:46:01 +02:00
|
|
|
|
|
|
|
void on_query_ok();
|
|
|
|
|
2019-02-16 17:01:47 +01:00
|
|
|
void on_query_error(Status status);
|
2021-10-20 09:46:01 +02:00
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
static void on_query_error(uint64 id, Status status);
|
2021-10-20 09:46:01 +02:00
|
|
|
|
2019-02-16 17:01:47 +01:00
|
|
|
void start_net_query(NetQueryType net_query_type, NetQueryPtr net_query);
|
|
|
|
|
2021-10-20 09:46:01 +02:00
|
|
|
void send_new_send_code_query(uint64 query_id, const telegram_api::Function &query);
|
2019-02-16 17:01:47 +01:00
|
|
|
|
2021-10-20 09:46:01 +02:00
|
|
|
void send_new_check_code_query(const telegram_api::Function &query);
|
2019-02-16 17:01:47 +01:00
|
|
|
|
2021-10-20 09:46:01 +02:00
|
|
|
void process_check_code_result(Result<tl_object_ptr<telegram_api::User>> &&result);
|
|
|
|
|
|
|
|
void process_check_code_result(Result<bool> &&result);
|
2019-02-16 17:01:47 +01:00
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void on_result(NetQueryPtr result) final;
|
2021-10-20 09:46:01 +02:00
|
|
|
|
|
|
|
void on_send_code_result(NetQueryPtr &result);
|
|
|
|
|
|
|
|
void on_check_code_result(NetQueryPtr &result);
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void tear_down() final;
|
2019-02-16 17:01:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|