Add class EmailVerification.
This commit is contained in:
parent
8f16191182
commit
886a6125e9
@ -330,6 +330,7 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/DownloadManager.cpp
|
td/telegram/DownloadManager.cpp
|
||||||
td/telegram/DownloadManagerCallback.cpp
|
td/telegram/DownloadManagerCallback.cpp
|
||||||
td/telegram/DraftMessage.cpp
|
td/telegram/DraftMessage.cpp
|
||||||
|
td/telegram/EmailVerification.cpp
|
||||||
td/telegram/EmojiStatus.cpp
|
td/telegram/EmojiStatus.cpp
|
||||||
td/telegram/FileReferenceManager.cpp
|
td/telegram/FileReferenceManager.cpp
|
||||||
td/telegram/files/FileBitmask.cpp
|
td/telegram/files/FileBitmask.cpp
|
||||||
@ -541,6 +542,7 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/DownloadManager.h
|
td/telegram/DownloadManager.h
|
||||||
td/telegram/DownloadManagerCallback.h
|
td/telegram/DownloadManagerCallback.h
|
||||||
td/telegram/DraftMessage.h
|
td/telegram/DraftMessage.h
|
||||||
|
td/telegram/EmailVerification.h
|
||||||
td/telegram/EmojiStatus.h
|
td/telegram/EmojiStatus.h
|
||||||
td/telegram/EncryptedFile.h
|
td/telegram/EncryptedFile.h
|
||||||
td/telegram/FileReferenceManager.h
|
td/telegram/FileReferenceManager.h
|
||||||
|
@ -271,7 +271,7 @@ void AuthManager::set_phone_number(uint64 query_id, string phone_number,
|
|||||||
email_code_info_ = {};
|
email_code_info_ = {};
|
||||||
next_phone_number_login_date_ = 0;
|
next_phone_number_login_date_ = 0;
|
||||||
code_ = string();
|
code_ = string();
|
||||||
email_code_ = nullptr;
|
email_code_ = {};
|
||||||
|
|
||||||
if (send_code_helper_.phone_number() != phone_number) {
|
if (send_code_helper_.phone_number() != phone_number) {
|
||||||
send_code_helper_ = SendCodeHelper();
|
send_code_helper_ = SendCodeHelper();
|
||||||
@ -320,21 +320,20 @@ void AuthManager::resend_authentication_code(uint64 query_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::send_auth_sign_in_query() {
|
void AuthManager::send_auth_sign_in_query() {
|
||||||
bool is_email = email_code_ != nullptr;
|
bool is_email = !email_code_.is_empty();
|
||||||
int32 flags =
|
int32 flags =
|
||||||
is_email ? telegram_api::auth_signIn::EMAIL_VERIFICATION_MASK : telegram_api::auth_signIn::PHONE_CODE_MASK;
|
is_email ? telegram_api::auth_signIn::EMAIL_VERIFICATION_MASK : telegram_api::auth_signIn::PHONE_CODE_MASK;
|
||||||
start_net_query(NetQueryType::SignIn,
|
start_net_query(NetQueryType::SignIn,
|
||||||
G()->net_query_creator().create_unauth(telegram_api::auth_signIn(
|
G()->net_query_creator().create_unauth(telegram_api::auth_signIn(
|
||||||
flags, send_code_helper_.phone_number().str(), send_code_helper_.phone_code_hash().str(), code_,
|
flags, send_code_helper_.phone_number().str(), send_code_helper_.phone_code_hash().str(), code_,
|
||||||
is_email ? get_input_email_verification(email_code_) : nullptr)));
|
is_email ? email_code_.get_input_email_verification() : nullptr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::check_email_code(uint64 query_id, td_api::object_ptr<td_api::EmailAddressAuthentication> &&code) {
|
void AuthManager::check_email_code(uint64 query_id, EmailVerification &&code) {
|
||||||
if (code == nullptr) {
|
if (code.is_empty()) {
|
||||||
return on_query_error(query_id, Status::Error(400, "Code must be non-empty"));
|
return on_query_error(query_id, Status::Error(400, "Code must be non-empty"));
|
||||||
}
|
}
|
||||||
if (state_ != State::WaitEmailCode &&
|
if (state_ != State::WaitEmailCode && !(state_ == State::WaitEmailAddress && code.is_email_code())) {
|
||||||
!(state_ == State::WaitEmailAddress && code->get_id() == td_api::emailAddressAuthenticationCode::ID)) {
|
|
||||||
return on_query_error(query_id, Status::Error(400, "Call to checkAuthenticationEmailCode unexpected"));
|
return on_query_error(query_id, Status::Error(400, "Call to checkAuthenticationEmailCode unexpected"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,7 +347,7 @@ void AuthManager::check_email_code(uint64 query_id, td_api::object_ptr<td_api::E
|
|||||||
start_net_query(
|
start_net_query(
|
||||||
NetQueryType::VerifyEmailAddress,
|
NetQueryType::VerifyEmailAddress,
|
||||||
G()->net_query_creator().create_unauth(telegram_api::account_verifyEmail(
|
G()->net_query_creator().create_unauth(telegram_api::account_verifyEmail(
|
||||||
send_code_helper_.get_email_verify_purpose_login_setup(), get_input_email_verification(email_code_))));
|
send_code_helper_.get_email_verify_purpose_login_setup(), email_code_.get_input_email_verification())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,7 +357,7 @@ void AuthManager::check_code(uint64 query_id, string code) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
code_ = std::move(code);
|
code_ = std::move(code);
|
||||||
email_code_ = nullptr;
|
email_code_ = {};
|
||||||
|
|
||||||
on_new_query(query_id);
|
on_new_query(query_id);
|
||||||
send_auth_sign_in_query();
|
send_auth_sign_in_query();
|
||||||
@ -1200,35 +1199,4 @@ void AuthManager::save_state() {
|
|||||||
G()->td_db()->get_binlog_pmc()->set("auth_state", log_event_store(db_state).as_slice().str());
|
G()->td_db()->get_binlog_pmc()->set("auth_state", log_event_store(db_state).as_slice().str());
|
||||||
}
|
}
|
||||||
|
|
||||||
telegram_api::object_ptr<telegram_api::EmailVerification> AuthManager::get_input_email_verification(
|
|
||||||
const td_api::object_ptr<td_api::EmailAddressAuthentication> &code) {
|
|
||||||
CHECK(code != nullptr);
|
|
||||||
switch (code->get_id()) {
|
|
||||||
case td_api::emailAddressAuthenticationCode::ID: {
|
|
||||||
auto token = static_cast<const td_api::emailAddressAuthenticationCode *>(code.get())->code_;
|
|
||||||
if (!clean_input_string(token)) {
|
|
||||||
token.clear();
|
|
||||||
}
|
|
||||||
return telegram_api::make_object<telegram_api::emailVerificationCode>(token);
|
|
||||||
}
|
|
||||||
case td_api::emailAddressAuthenticationAppleId::ID: {
|
|
||||||
auto token = static_cast<const td_api::emailAddressAuthenticationAppleId *>(code.get())->token_;
|
|
||||||
if (!clean_input_string(token)) {
|
|
||||||
token.clear();
|
|
||||||
}
|
|
||||||
return telegram_api::make_object<telegram_api::emailVerificationApple>(token);
|
|
||||||
}
|
|
||||||
case td_api::emailAddressAuthenticationGoogleId::ID: {
|
|
||||||
auto token = static_cast<const td_api::emailAddressAuthenticationGoogleId *>(code.get())->token_;
|
|
||||||
if (!clean_input_string(token)) {
|
|
||||||
token.clear();
|
|
||||||
}
|
|
||||||
return telegram_api::make_object<telegram_api::emailVerificationGoogle>(token);
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/telegram/EmailVerification.h"
|
||||||
#include "td/telegram/net/NetActor.h"
|
#include "td/telegram/net/NetActor.h"
|
||||||
#include "td/telegram/net/NetQuery.h"
|
#include "td/telegram/net/NetQuery.h"
|
||||||
#include "td/telegram/SendCodeHelper.h"
|
#include "td/telegram/SendCodeHelper.h"
|
||||||
@ -38,7 +39,7 @@ class AuthManager final : public NetActor {
|
|||||||
td_api::object_ptr<td_api::phoneNumberAuthenticationSettings> settings);
|
td_api::object_ptr<td_api::phoneNumberAuthenticationSettings> settings);
|
||||||
void set_email_address(uint64 query_id, string email_address);
|
void set_email_address(uint64 query_id, string email_address);
|
||||||
void resend_authentication_code(uint64 query_id);
|
void resend_authentication_code(uint64 query_id);
|
||||||
void check_email_code(uint64 query_id, td_api::object_ptr<td_api::EmailAddressAuthentication> &&code);
|
void check_email_code(uint64 query_id, EmailVerification &&code);
|
||||||
void check_code(uint64 query_id, string code);
|
void check_code(uint64 query_id, string code);
|
||||||
void register_user(uint64 query_id, string first_name, string last_name);
|
void register_user(uint64 query_id, string first_name, string last_name);
|
||||||
void request_qr_code_authentication(uint64 query_id, vector<UserId> other_user_ids);
|
void request_qr_code_authentication(uint64 query_id, vector<UserId> other_user_ids);
|
||||||
@ -223,7 +224,7 @@ class AuthManager final : public NetActor {
|
|||||||
string email_address_;
|
string email_address_;
|
||||||
SentEmailCode email_code_info_;
|
SentEmailCode email_code_info_;
|
||||||
int32 next_phone_number_login_date_ = 0;
|
int32 next_phone_number_login_date_ = 0;
|
||||||
td_api::object_ptr<td_api::EmailAddressAuthentication> email_code_;
|
EmailVerification email_code_;
|
||||||
|
|
||||||
// State::WaitCode
|
// State::WaitCode
|
||||||
SendCodeHelper send_code_helper_;
|
SendCodeHelper send_code_helper_;
|
||||||
@ -302,9 +303,6 @@ class AuthManager final : public NetActor {
|
|||||||
static void send_ok(uint64 query_id);
|
static void send_ok(uint64 query_id);
|
||||||
static void on_query_error(uint64 query_id, Status status);
|
static void on_query_error(uint64 query_id, Status status);
|
||||||
|
|
||||||
static telegram_api::object_ptr<telegram_api::EmailVerification> get_input_email_verification(
|
|
||||||
const td_api::object_ptr<td_api::EmailAddressAuthentication> &code);
|
|
||||||
|
|
||||||
void start_up() final;
|
void start_up() final;
|
||||||
void tear_down() final;
|
void tear_down() final;
|
||||||
};
|
};
|
||||||
|
53
td/telegram/EmailVerification.cpp
Normal file
53
td/telegram/EmailVerification.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
//
|
||||||
|
#include "td/telegram/EmailVerification.h"
|
||||||
|
|
||||||
|
#include "td/telegram/misc.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
EmailVerification::EmailVerification(td_api::object_ptr<td_api::EmailAddressAuthentication> &&code) {
|
||||||
|
if (code == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (code->get_id()) {
|
||||||
|
case td_api::emailAddressAuthenticationCode::ID:
|
||||||
|
type_ = Type::Code;
|
||||||
|
code_ = static_cast<const td_api::emailAddressAuthenticationCode *>(code.get())->code_;
|
||||||
|
break;
|
||||||
|
case td_api::emailAddressAuthenticationAppleId::ID:
|
||||||
|
type_ = Type::Apple;
|
||||||
|
code_ = static_cast<const td_api::emailAddressAuthenticationAppleId *>(code.get())->token_;
|
||||||
|
break;
|
||||||
|
case td_api::emailAddressAuthenticationGoogleId::ID:
|
||||||
|
type_ = Type::Google;
|
||||||
|
code_ = static_cast<const td_api::emailAddressAuthenticationGoogleId *>(code.get())->token_;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!clean_input_string(code_)) {
|
||||||
|
*this = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
telegram_api::object_ptr<telegram_api::EmailVerification> EmailVerification::get_input_email_verification() const {
|
||||||
|
switch (type_) {
|
||||||
|
case Type::Code:
|
||||||
|
return telegram_api::make_object<telegram_api::emailVerificationCode>(code_);
|
||||||
|
case Type::Apple:
|
||||||
|
return telegram_api::make_object<telegram_api::emailVerificationApple>(code_);
|
||||||
|
case Type::Google:
|
||||||
|
return telegram_api::make_object<telegram_api::emailVerificationGoogle>(code_);
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace td
|
37
td/telegram/EmailVerification.h
Normal file
37
td/telegram/EmailVerification.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
||||||
|
//
|
||||||
|
// 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"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
class EmailVerification {
|
||||||
|
enum class Type : int32 { None, Code, Apple, Google };
|
||||||
|
Type type_ = Type::None;
|
||||||
|
string code_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
EmailVerification() = default;
|
||||||
|
|
||||||
|
explicit EmailVerification(td_api::object_ptr<td_api::EmailAddressAuthentication> &&code);
|
||||||
|
|
||||||
|
telegram_api::object_ptr<telegram_api::EmailVerification> get_input_email_verification() const;
|
||||||
|
|
||||||
|
bool is_empty() const {
|
||||||
|
return type_ == Type::None;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_email_code() const {
|
||||||
|
return type_ == Type::Code;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace td
|
@ -4274,7 +4274,7 @@ void Td::on_request(uint64 id, const td_api::resendAuthenticationCode &request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::checkAuthenticationEmailCode &request) {
|
void Td::on_request(uint64 id, td_api::checkAuthenticationEmailCode &request) {
|
||||||
send_closure(auth_manager_actor_, &AuthManager::check_email_code, id, std::move(request.code_));
|
send_closure(auth_manager_actor_, &AuthManager::check_email_code, id, EmailVerification(std::move(request.code_)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::checkAuthenticationCode &request) {
|
void Td::on_request(uint64 id, td_api::checkAuthenticationCode &request) {
|
||||||
|
Loading…
Reference in New Issue
Block a user