2015-03-02 12:34:16 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2015-03-02 12:34:16 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
2018-04-17 15:19:24 +00:00
|
|
|
#include "mtproto/sender.h"
|
2018-08-03 21:48:00 +00:00
|
|
|
#include "core/core_cloud_password.h"
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
namespace MTP {
|
|
|
|
class Instance;
|
|
|
|
} // namespace MTP
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
namespace Ui {
|
2016-11-15 11:56:49 +00:00
|
|
|
class InputField;
|
|
|
|
class PasswordInput;
|
2016-11-11 13:46:04 +00:00
|
|
|
class LinkButton;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2019-06-14 12:43:42 +00:00
|
|
|
namespace Core {
|
|
|
|
struct CloudPasswordState;
|
|
|
|
} // namespace Core
|
|
|
|
|
2019-11-27 08:02:56 +00:00
|
|
|
class PasscodeBox : public Ui::BoxContent {
|
2015-03-02 12:34:16 +00:00
|
|
|
public:
|
2019-07-24 14:00:30 +00:00
|
|
|
PasscodeBox(QWidget*, not_null<Main::Session*> session, bool turningOff);
|
2019-06-14 12:43:42 +00:00
|
|
|
|
|
|
|
struct CloudFields {
|
|
|
|
static CloudFields From(const Core::CloudPasswordState ¤t);
|
|
|
|
|
2022-05-06 04:27:19 +00:00
|
|
|
struct Mtp {
|
|
|
|
Core::CloudPasswordCheckRequest curRequest;
|
|
|
|
Core::CloudPasswordAlgo newAlgo;
|
|
|
|
Core::SecureSecretAlgo newSecureSecretAlgo;
|
|
|
|
};
|
|
|
|
Mtp mtp;
|
|
|
|
bool hasPassword = false;
|
2019-06-14 12:43:42 +00:00
|
|
|
bool hasRecovery = false;
|
2021-07-30 14:33:26 +00:00
|
|
|
QString fromRecoveryCode;
|
2019-06-14 12:43:42 +00:00
|
|
|
bool notEmptyPassport = false;
|
|
|
|
QString hint;
|
|
|
|
bool turningOff = false;
|
2021-07-30 11:32:49 +00:00
|
|
|
TimeId pendingResetDate = 0;
|
2019-06-14 12:43:42 +00:00
|
|
|
|
|
|
|
// 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;
|
2019-06-14 12:43:42 +00:00
|
|
|
};
|
2021-07-30 14:33:26 +00:00
|
|
|
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);
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2018-07-10 16:41:11 +00:00
|
|
|
rpl::producer<QByteArray> newPasswordSet() const;
|
|
|
|
rpl::producer<> passwordReloadNeeded() const;
|
2018-11-07 09:39:31 +00:00
|
|
|
rpl::producer<> clearUnconfirmedPassword() const;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
rpl::producer<MTPauth_Authorization> newAuthorization() const;
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
bool handleCustomCheckError(const MTP::Error &error);
|
2021-03-31 17:15:49 +00:00
|
|
|
bool handleCustomCheckError(const QString &type);
|
2019-06-14 14:04:30 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
protected:
|
2016-12-13 17:07:56 +00:00
|
|
|
void prepare() override;
|
|
|
|
void setInnerFocus() override;
|
|
|
|
|
2016-07-28 17:01:08 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
private:
|
2018-08-10 19:19:46 +00:00
|
|
|
using CheckPasswordCallback = Fn<void(
|
|
|
|
const Core::CloudPasswordResult &check)>;
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void submit();
|
2016-12-13 17:07:56 +00:00
|
|
|
void closeReplacedBy();
|
2018-05-31 12:20:28 +00:00
|
|
|
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;
|
2019-06-14 12:43:42 +00:00
|
|
|
bool onlyCheckCurrent() const;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2018-07-10 16:41:11 +00:00
|
|
|
void setPasswordDone(const QByteArray &newPasswordBytes);
|
2021-07-30 14:33:26 +00:00
|
|
|
void recoverPasswordDone(
|
|
|
|
const QByteArray &newPasswordBytes,
|
|
|
|
const MTPauth_Authorization &result);
|
2021-03-31 17:15:49 +00:00
|
|
|
void setPasswordFail(const QString &type);
|
2018-08-10 19:19:46 +00:00
|
|
|
void setPasswordFail(
|
2018-07-10 16:41:11 +00:00
|
|
|
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);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
void recoverStarted(const MTPauth_PasswordRecovery &result);
|
2021-03-12 12:48:00 +00:00
|
|
|
void recoverStartFail(const MTP::Error &error);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
void recover();
|
2019-06-14 12:43:42 +00:00
|
|
|
void submitOnlyCheckCloudPassword(const QString &oldPassword);
|
2018-04-17 15:19:24 +00:00
|
|
|
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);
|
2018-04-17 15:19:24 +00:00
|
|
|
void changeCloudPassword(
|
|
|
|
const QString &oldPassword,
|
2018-08-10 19:19:46 +00:00
|
|
|
const Core::CloudPasswordResult &check,
|
2018-04-17 15:19:24 +00:00
|
|
|
const QString &newPassword);
|
2018-08-10 19:19:46 +00:00
|
|
|
|
2018-04-17 15:19:24 +00:00
|
|
|
void sendChangeCloudPassword(
|
2018-08-10 19:19:46 +00:00
|
|
|
const Core::CloudPasswordResult &check,
|
2018-04-17 15:19:24 +00:00
|
|
|
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);
|
|
|
|
|
2019-06-14 12:43:42 +00:00
|
|
|
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();
|
2018-04-17 15:19:24 +00:00
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
Main::Session *_session = nullptr;
|
2019-11-27 08:02:56 +00:00
|
|
|
MTP::Sender _api;
|
2019-07-24 14:00:30 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
QString _pattern;
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
QPointer<Ui::BoxContent> _replacedBy;
|
2016-11-18 13:34:58 +00:00
|
|
|
bool _turningOff = false;
|
|
|
|
bool _cloudPwd = false;
|
2019-06-14 12:43:42 +00:00
|
|
|
CloudFields _cloudFields;
|
2016-11-18 13:34:58 +00:00
|
|
|
mtpRequestId _setRequest = 0;
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time _lastSrpIdInvalidTime = 0;
|
2016-11-18 13:34:58 +00:00
|
|
|
bool _skipEmailWarning = false;
|
2018-08-10 19:19:46 +00:00
|
|
|
CheckPasswordCallback _checkPasswordCallback;
|
|
|
|
bytes::vector _checkPasswordHash;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
int _aboutHeight = 0;
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::String _about, _hintText;
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
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;
|
2021-07-30 11:32:49 +00:00
|
|
|
bool _showRecoverLink = false;
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
QString _oldError, _newError, _emailError;
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2018-07-10 16:41:11 +00:00
|
|
|
rpl::event_stream<QByteArray> _newPasswordSet;
|
2021-07-30 14:33:26 +00:00
|
|
|
rpl::event_stream<MTPauth_Authorization> _newAuthorization;
|
2018-07-10 16:41:11 +00:00
|
|
|
rpl::event_stream<> _passwordReloadNeeded;
|
2018-11-07 09:39:31 +00:00
|
|
|
rpl::event_stream<> _clearUnconfirmedPassword;
|
2018-07-10 16:41:11 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
};
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
class RecoverBox final : public Ui::BoxContent {
|
2015-04-02 10:33:19 +00:00
|
|
|
public:
|
2020-06-11 16:09:46 +00:00
|
|
|
RecoverBox(
|
|
|
|
QWidget*,
|
2021-07-30 14:33:26 +00:00
|
|
|
not_null<MTP::Instance*> mtp,
|
|
|
|
Main::Session *session,
|
2020-06-11 16:09:46 +00:00
|
|
|
const QString &pattern,
|
2021-07-30 14:33:26 +00:00
|
|
|
const PasscodeBox::CloudFields &fields,
|
2021-07-30 11:32:49 +00:00
|
|
|
Fn<void()> closeParent = nullptr);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
[[nodiscard]] rpl::producer<QByteArray> newPasswordSet() const;
|
|
|
|
[[nodiscard]] rpl::producer<> recoveryExpired() const;
|
2018-07-10 16:41:11 +00:00
|
|
|
|
|
|
|
//void reloadPassword();
|
|
|
|
//void recoveryExpired();
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
protected:
|
2016-12-13 17:07:56 +00:00
|
|
|
void prepare() override;
|
|
|
|
void setInnerFocus() override;
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
private:
|
2018-05-31 12:20:28 +00:00
|
|
|
void submit();
|
|
|
|
void codeChanged();
|
2021-08-17 10:52:21 +00:00
|
|
|
void proceedToClear();
|
|
|
|
void proceedToChange(const QString &code);
|
2021-07-30 14:33:26 +00:00
|
|
|
void checkSubmitFail(const MTP::Error &error);
|
2021-07-30 11:32:49 +00:00
|
|
|
void setError(const QString &error);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
Main::Session *_session = nullptr;
|
2020-06-11 16:09:46 +00:00
|
|
|
MTP::Sender _api;
|
2016-12-13 17:07:56 +00:00
|
|
|
mtpRequestId _submitRequest = 0;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
QString _pattern;
|
2021-07-30 14:33:26 +00:00
|
|
|
|
|
|
|
PasscodeBox::CloudFields _cloudFields;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::InputField> _recoverCode;
|
2021-07-30 11:32:49 +00:00
|
|
|
object_ptr<Ui::LinkButton> _noEmailAccess;
|
|
|
|
Fn<void()> _closeParent;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
QString _error;
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2021-07-30 14:33:26 +00:00
|
|
|
rpl::event_stream<QByteArray> _newPasswordSet;
|
2018-07-10 16:41:11 +00:00
|
|
|
rpl::event_stream<> _recoveryExpired;
|
|
|
|
|
2015-03-02 12:34:16 +00:00
|
|
|
};
|
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;
|
|
|
|
};
|
2020-06-11 16:09:46 +00:00
|
|
|
[[nodiscard]] RecoveryEmailValidation ConfirmRecoveryEmail(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const QString &pattern);
|
2020-08-25 10:57:17 +00:00
|
|
|
|
|
|
|
[[nodiscard]] object_ptr<Ui::GenericBox> PrePasswordErrorBox(
|
2021-11-26 04:38:00 +00:00
|
|
|
const QString &error,
|
2020-08-25 10:57:17 +00:00
|
|
|
not_null<Main::Session*> session,
|
|
|
|
TextWithEntities &&about);
|