tdesktop/Telegram/SourceFiles/boxes/passcode_box.h

252 lines
6.4 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "ui/layers/box_content.h"
#include "mtproto/sender.h"
2018-08-03 21:48:00 +00:00
#include "core/core_cloud_password.h"
namespace MTP {
class Instance;
} // namespace MTP
2019-07-24 14:00:30 +00:00
namespace Main {
class Session;
} // namespace Main
namespace Ui {
class InputField;
class PasswordInput;
class LinkButton;
} // namespace Ui
namespace Core {
struct CloudPasswordState;
} // namespace Core
2019-11-27 08:02:56 +00:00
class PasscodeBox : public Ui::BoxContent {
public:
2019-07-24 14:00:30 +00:00
PasscodeBox(QWidget*, not_null<Main::Session*> session, bool turningOff);
struct CloudFields {
static CloudFields From(const Core::CloudPasswordState &current);
struct Mtp {
Core::CloudPasswordCheckRequest curRequest;
Core::CloudPasswordAlgo newAlgo;
Core::SecureSecretAlgo newSecureSecretAlgo;
};
Mtp mtp;
bool hasPassword = false;
bool hasRecovery = false;
QString fromRecoveryCode;
bool notEmptyPassport = false;
QString hint;
bool turningOff = false;
TimeId pendingResetDate = 0;
// Check cloud password for some action.
2019-06-14 14:04:30 +00:00
Fn<void(const Core::CloudPasswordResult &)> customCheckCallback;
2019-06-19 11:22:25 +00:00
rpl::producer<QString> customTitle;
2019-06-14 14:04:30 +00:00
std::optional<QString> customDescription;
2019-06-19 11:22:25 +00:00
rpl::producer<QString> customSubmitButton;
};
PasscodeBox(
QWidget*,
not_null<MTP::Instance*> mtp,
Main::Session *session,
const CloudFields &fields);
2019-07-24 14:00:30 +00:00
PasscodeBox(
QWidget*,
not_null<Main::Session*> session,
const CloudFields &fields);
rpl::producer<QByteArray> newPasswordSet() const;
rpl::producer<> passwordReloadNeeded() const;
2018-11-07 09:39:31 +00:00
rpl::producer<> clearUnconfirmedPassword() const;
rpl::producer<MTPauth_Authorization> newAuthorization() const;
2021-03-12 12:48:00 +00:00
bool handleCustomCheckError(const MTP::Error &error);
bool handleCustomCheckError(const QString &type);
2019-06-14 14:04:30 +00:00
protected:
void prepare() override;
void setInnerFocus() override;
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
private:
2018-08-10 19:19:46 +00:00
using CheckPasswordCallback = Fn<void(
const Core::CloudPasswordResult &check)>;
void submit();
void closeReplacedBy();
void oldChanged();
void newChanged();
void save(bool force = false);
void badOldPasscode();
void recoverByEmail();
void recoverExpired();
2018-08-03 21:48:00 +00:00
bool currentlyHave() const;
bool onlyCheckCurrent() const;
void setPasswordDone(const QByteArray &newPasswordBytes);
void recoverPasswordDone(
const QByteArray &newPasswordBytes,
const MTPauth_Authorization &result);
void setPasswordFail(const QString &type);
2018-08-10 19:19:46 +00:00
void setPasswordFail(
const QByteArray &newPasswordBytes,
2018-11-07 09:39:31 +00:00
const QString &email,
2021-03-12 12:48:00 +00:00
const MTP::Error &error);
2018-11-07 09:39:31 +00:00
void validateEmail(
const QString &email,
int codeLength,
const QByteArray &newPasswordBytes);
void recoverStarted(const MTPauth_PasswordRecovery &result);
2021-03-12 12:48:00 +00:00
void recoverStartFail(const MTP::Error &error);
void recover();
void submitOnlyCheckCloudPassword(const QString &oldPassword);
void setNewCloudPassword(const QString &newPassword);
2018-08-10 19:19:46 +00:00
void checkPassword(
const QString &oldPassword,
CheckPasswordCallback callback);
void checkPasswordHash(CheckPasswordCallback callback);
void changeCloudPassword(
const QString &oldPassword,
const QString &newPassword);
void changeCloudPassword(
const QString &oldPassword,
2018-08-10 19:19:46 +00:00
const Core::CloudPasswordResult &check,
const QString &newPassword);
2018-08-10 19:19:46 +00:00
void sendChangeCloudPassword(
2018-08-10 19:19:46 +00:00
const Core::CloudPasswordResult &check,
const QString &newPassword,
const QByteArray &secureSecret);
2018-08-10 19:19:46 +00:00
void suggestSecretReset(const QString &newPassword);
void resetSecret(
const Core::CloudPasswordResult &check,
const QString &newPassword,
Fn<void()> callback);
void sendOnlyCheckCloudPassword(const QString &oldPassword);
2018-08-10 19:19:46 +00:00
void sendClearCloudPassword(const Core::CloudPasswordResult &check);
void handleSrpIdInvalid();
void requestPasswordData();
void passwordChecked();
void serverError();
Main::Session *_session = nullptr;
2019-11-27 08:02:56 +00:00
MTP::Sender _api;
2019-07-24 14:00:30 +00:00
QString _pattern;
2019-09-18 11:19:05 +00:00
QPointer<Ui::BoxContent> _replacedBy;
bool _turningOff = false;
bool _cloudPwd = false;
CloudFields _cloudFields;
mtpRequestId _setRequest = 0;
crl::time _lastSrpIdInvalidTime = 0;
bool _skipEmailWarning = false;
2018-08-10 19:19:46 +00:00
CheckPasswordCallback _checkPasswordCallback;
bytes::vector _checkPasswordHash;
int _aboutHeight = 0;
2019-06-12 13:26:04 +00:00
Ui::Text::String _about, _hintText;
object_ptr<Ui::PasswordInput> _oldPasscode;
object_ptr<Ui::PasswordInput> _newPasscode;
object_ptr<Ui::PasswordInput> _reenterPasscode;
object_ptr<Ui::InputField> _passwordHint;
object_ptr<Ui::InputField> _recoverEmail;
object_ptr<Ui::LinkButton> _recover;
bool _showRecoverLink = false;
QString _oldError, _newError, _emailError;
rpl::event_stream<QByteArray> _newPasswordSet;
rpl::event_stream<MTPauth_Authorization> _newAuthorization;
rpl::event_stream<> _passwordReloadNeeded;
2018-11-07 09:39:31 +00:00
rpl::event_stream<> _clearUnconfirmedPassword;
};
class RecoverBox final : public Ui::BoxContent {
public:
RecoverBox(
QWidget*,
not_null<MTP::Instance*> mtp,
Main::Session *session,
const QString &pattern,
const PasscodeBox::CloudFields &fields,
Fn<void()> closeParent = nullptr);
[[nodiscard]] rpl::producer<QByteArray> newPasswordSet() const;
[[nodiscard]] rpl::producer<> recoveryExpired() const;
//void reloadPassword();
//void recoveryExpired();
protected:
void prepare() override;
void setInnerFocus() override;
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
private:
void submit();
void codeChanged();
void proceedToClear();
void proceedToChange(const QString &code);
void checkSubmitFail(const MTP::Error &error);
void setError(const QString &error);
Main::Session *_session = nullptr;
MTP::Sender _api;
mtpRequestId _submitRequest = 0;
QString _pattern;
PasscodeBox::CloudFields _cloudFields;
object_ptr<Ui::InputField> _recoverCode;
object_ptr<Ui::LinkButton> _noEmailAccess;
Fn<void()> _closeParent;
QString _error;
rpl::event_stream<QByteArray> _newPasswordSet;
rpl::event_stream<> _recoveryExpired;
};
2018-11-07 09:39:31 +00:00
struct RecoveryEmailValidation {
2019-09-18 11:19:05 +00:00
object_ptr<Ui::BoxContent> box;
2018-11-07 09:39:31 +00:00
rpl::producer<> reloadRequests;
rpl::producer<> cancelRequests;
};
[[nodiscard]] RecoveryEmailValidation ConfirmRecoveryEmail(
not_null<Main::Session*> session,
const QString &pattern);
[[nodiscard]] object_ptr<Ui::GenericBox> PrePasswordErrorBox(
2021-11-26 04:38:00 +00:00
const QString &error,
not_null<Main::Session*> session,
TextWithEntities &&about);