2019-02-16 16:49:39 +01:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2019-02-16 16:49:39 +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/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class SendCodeHelper {
|
|
|
|
public:
|
|
|
|
void on_sent_code(telegram_api::object_ptr<telegram_api::auth_sentCode> sent_code);
|
2021-11-24 15:19:16 +01:00
|
|
|
|
2022-09-06 13:04:39 +02:00
|
|
|
void on_phone_code_hash(string &&phone_code_hash);
|
|
|
|
|
2019-07-16 21:08:34 +02:00
|
|
|
td_api::object_ptr<td_api::authorizationStateWaitCode> get_authorization_state_wait_code() const;
|
2021-11-24 15:19:16 +01:00
|
|
|
|
2019-02-16 16:49:39 +01:00
|
|
|
td_api::object_ptr<td_api::authenticationCodeInfo> get_authentication_code_info_object() const;
|
2021-11-24 15:19:16 +01:00
|
|
|
|
|
|
|
Result<telegram_api::auth_resendCode> resend_code() const;
|
2019-02-16 16:49:39 +01:00
|
|
|
|
2019-05-03 04:44:59 +02:00
|
|
|
using Settings = td_api::object_ptr<td_api::phoneNumberAuthenticationSettings>;
|
2019-02-16 16:49:39 +01:00
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
telegram_api::auth_sendCode send_code(string phone_number, const Settings &settings, int32 api_id,
|
2019-12-18 17:08:05 +01:00
|
|
|
const string &api_hash);
|
2019-05-03 04:44:59 +02:00
|
|
|
|
2023-01-19 14:45:47 +01:00
|
|
|
telegram_api::auth_requestFirebaseSms request_firebase_sms(const string &token);
|
|
|
|
|
2022-09-06 13:04:39 +02:00
|
|
|
telegram_api::account_sendVerifyEmailCode send_verify_email_code(const string &email_address);
|
|
|
|
|
2019-09-02 17:16:34 +02:00
|
|
|
telegram_api::account_sendChangePhoneCode send_change_phone_code(Slice phone_number, const Settings &settings);
|
2019-02-16 16:49:39 +01:00
|
|
|
|
2019-09-02 17:16:34 +02:00
|
|
|
telegram_api::account_sendVerifyPhoneCode send_verify_phone_code(Slice phone_number, const Settings &settings);
|
2019-02-16 16:49:39 +01:00
|
|
|
|
2019-09-02 17:16:34 +02:00
|
|
|
telegram_api::account_sendConfirmPhoneCode send_confirm_phone_code(const string &hash, Slice phone_number,
|
|
|
|
const Settings &settings);
|
2019-02-16 16:49:39 +01:00
|
|
|
|
2022-09-06 16:17:39 +02:00
|
|
|
telegram_api::object_ptr<telegram_api::emailVerifyPurposeLoginSetup> get_email_verify_purpose_login_setup() const;
|
|
|
|
|
2019-02-16 16:49:39 +01:00
|
|
|
Slice phone_number() const {
|
|
|
|
return phone_number_;
|
|
|
|
}
|
|
|
|
Slice phone_code_hash() const {
|
|
|
|
return phone_code_hash_;
|
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
2019-02-16 16:49:39 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct AuthenticationCodeInfo {
|
2024-04-22 17:18:13 +02:00
|
|
|
enum class Type : int32 {
|
|
|
|
None,
|
|
|
|
Message,
|
|
|
|
Sms,
|
|
|
|
Call,
|
|
|
|
FlashCall,
|
|
|
|
MissedCall,
|
|
|
|
Fragment,
|
|
|
|
FirebaseAndroid,
|
|
|
|
FirebaseIos,
|
|
|
|
SmsWord,
|
|
|
|
SmsPhrase
|
|
|
|
};
|
2019-02-16 16:49:39 +01:00
|
|
|
Type type = Type::None;
|
|
|
|
int32 length = 0;
|
2023-01-19 13:12:55 +01:00
|
|
|
int32 push_timeout = 0;
|
2019-02-16 16:49:39 +01:00
|
|
|
string pattern;
|
|
|
|
|
|
|
|
AuthenticationCodeInfo() = default;
|
2023-01-19 13:12:55 +01:00
|
|
|
AuthenticationCodeInfo(Type type, int32 length, string pattern, int32 push_timeout = 0)
|
|
|
|
: type(type), length(length), push_timeout(push_timeout), pattern(std::move(pattern)) {
|
2019-02-16 16:49:39 +01:00
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
2019-02-16 16:49:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
string phone_number_;
|
|
|
|
string phone_code_hash_;
|
|
|
|
|
|
|
|
SendCodeHelper::AuthenticationCodeInfo sent_code_info_;
|
|
|
|
SendCodeHelper::AuthenticationCodeInfo next_code_info_;
|
2022-09-21 13:25:31 +02:00
|
|
|
double next_code_timestamp_ = 0.0;
|
2019-02-16 16:49:39 +01:00
|
|
|
|
|
|
|
static AuthenticationCodeInfo get_authentication_code_info(
|
|
|
|
tl_object_ptr<telegram_api::auth_CodeType> &&code_type_ptr);
|
2022-09-07 20:22:21 +02:00
|
|
|
static AuthenticationCodeInfo get_sent_authentication_code_info(
|
2019-02-16 16:49:39 +01:00
|
|
|
tl_object_ptr<telegram_api::auth_SentCodeType> &&sent_code_type_ptr);
|
|
|
|
|
2019-03-15 14:52:55 +01:00
|
|
|
static td_api::object_ptr<td_api::AuthenticationCodeType> get_authentication_code_type_object(
|
2019-02-16 16:49:39 +01:00
|
|
|
const AuthenticationCodeInfo &authentication_code_info);
|
2019-03-15 14:52:55 +01:00
|
|
|
|
2019-05-03 04:44:59 +02:00
|
|
|
static telegram_api::object_ptr<telegram_api::codeSettings> get_input_code_settings(const Settings &settings);
|
2019-02-16 16:49:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|