mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Added initial implementation of cloud password management to settings.
This commit is contained in:
parent
9a57347973
commit
db46f84f2c
6 changed files with 257 additions and 3 deletions
|
@ -1080,6 +1080,8 @@ PRIVATE
|
|||
settings/cloud_password/settings_cloud_password_hint.h
|
||||
settings/cloud_password/settings_cloud_password_input.cpp
|
||||
settings/cloud_password/settings_cloud_password_input.h
|
||||
settings/cloud_password/settings_cloud_password_manage.cpp
|
||||
settings/cloud_password/settings_cloud_password_manage.h
|
||||
settings/cloud_password/settings_cloud_password_start.cpp
|
||||
settings/cloud_password/settings_cloud_password_start.h
|
||||
settings/settings_advanced.cpp
|
||||
|
|
|
@ -492,7 +492,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_settings_sessions_about" = "Control your sessions on other devices.";
|
||||
"lng_settings_passcode_disable" = "Disable Passcode";
|
||||
"lng_settings_passcode_disable_sure" = "Are you sure you want to disable passcode?";
|
||||
"lng_settings_password_disable" = "Disable cloud password";
|
||||
"lng_settings_password_disable" = "Disable Cloud Password";
|
||||
"lng_settings_password_abort" = "Abort two-step verification setup";
|
||||
"lng_settings_password_reenter_email" = "Re-enter recovery email";
|
||||
"lng_settings_about_bio" = "Any details such as age, occupation or city.\nExample: 23 y.o. designer from San Francisco";
|
||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "api/api_cloud_password.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "settings/cloud_password/settings_cloud_password_common.h"
|
||||
#include "settings/cloud_password/settings_cloud_password_manage.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
|
@ -86,8 +87,11 @@ void Email::setupContent() {
|
|||
_requestLifetime.destroy();
|
||||
|
||||
auto empty = StepData();
|
||||
empty.currentPassword = stepData().password;
|
||||
empty.currentPassword = stepData().password.isEmpty()
|
||||
? stepData().currentPassword
|
||||
: stepData().password;
|
||||
setStepData(std::move(empty));
|
||||
showOther(CloudPasswordManageId());
|
||||
});
|
||||
|
||||
if (close) {
|
||||
|
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
#include "settings/cloud_password/settings_cloud_password_manage.h"
|
||||
|
||||
#include "api/api_cloud_password.h"
|
||||
#include "core/core_cloud_password.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "lottie/lottie_icon.h"
|
||||
#include "settings/cloud_password/settings_cloud_password_common.h"
|
||||
#include "settings/cloud_password/settings_cloud_password_email.h"
|
||||
#include "settings/cloud_password/settings_cloud_password_hint.h"
|
||||
#include "settings/cloud_password/settings_cloud_password_input.h"
|
||||
#include "settings/cloud_password/settings_cloud_password_start.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_settings.h"
|
||||
|
||||
namespace Settings {
|
||||
namespace CloudPassword {
|
||||
namespace {
|
||||
|
||||
void SetupTopContent(
|
||||
not_null<Ui::VerticalLayout*> parent,
|
||||
rpl::producer<> showFinished) {
|
||||
const auto divider = Ui::CreateChild<Ui::BoxContentDivider>(parent.get());
|
||||
const auto verticalLayout = parent->add(
|
||||
object_ptr<Ui::VerticalLayout>(parent.get()));
|
||||
|
||||
auto icon = CreateLottieIcon(
|
||||
verticalLayout,
|
||||
{
|
||||
.name = u"cloud_password/intro"_q,
|
||||
.sizeOverride = {
|
||||
st::settingsFilterIconSize,
|
||||
st::settingsFilterIconSize,
|
||||
},
|
||||
},
|
||||
st::settingsFilterIconPadding);
|
||||
std::move(
|
||||
showFinished
|
||||
) | rpl::start_with_next([animate = std::move(icon.animate)] {
|
||||
animate(anim::repeat::once);
|
||||
}, verticalLayout->lifetime());
|
||||
verticalLayout->add(std::move(icon.widget));
|
||||
|
||||
verticalLayout->add(
|
||||
object_ptr<Ui::CenterWrap<>>(
|
||||
verticalLayout,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
verticalLayout,
|
||||
tr::lng_settings_cloud_password_manage_about1(),
|
||||
st::settingsFilterDividerLabel)),
|
||||
st::settingsFilterDividerLabelPadding);
|
||||
|
||||
verticalLayout->geometryValue(
|
||||
) | rpl::start_with_next([=](const QRect &r) {
|
||||
divider->setGeometry(r);
|
||||
}, divider->lifetime());
|
||||
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class Manage : public TypedAbstractStep<Manage> {
|
||||
public:
|
||||
using TypedAbstractStep::TypedAbstractStep;
|
||||
|
||||
[[nodiscard]] rpl::producer<QString> title() override;
|
||||
void setupContent();
|
||||
|
||||
[[nodiscard]] rpl::producer<std::vector<Type>> removeFromStack() override;
|
||||
|
||||
[[nodiscard]] QPointer<Ui::RpWidget> createPinnedToBottom(
|
||||
not_null<Ui::RpWidget*> parent) override;
|
||||
|
||||
private:
|
||||
rpl::variable<bool> _isBottomFillerShown;
|
||||
|
||||
QString _currentPassword;
|
||||
|
||||
rpl::lifetime _requestLifetime;
|
||||
|
||||
};
|
||||
|
||||
rpl::producer<QString> Manage::title() {
|
||||
return tr::lng_settings_cloud_password_start_title();
|
||||
}
|
||||
|
||||
rpl::producer<std::vector<Type>> Manage::removeFromStack() {
|
||||
return rpl::single(std::vector<Type>{
|
||||
CloudPasswordStartId(),
|
||||
CloudPasswordInputId(),
|
||||
CloudPasswordHintId(),
|
||||
CloudPasswordEmailId(),
|
||||
CloudPasswordManageId(),
|
||||
});
|
||||
}
|
||||
|
||||
void Manage::setupContent() {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
auto currentStepData = stepData();
|
||||
_currentPassword = base::take(currentStepData.currentPassword);
|
||||
// If we go back from Password Manage to Privacy Settings
|
||||
// we should forget the current password.
|
||||
setStepData(std::move(currentStepData));
|
||||
|
||||
const auto state = cloudPassword().stateCurrent();
|
||||
if (!state) {
|
||||
setStepData(StepData());
|
||||
showBack();
|
||||
return;
|
||||
}
|
||||
cloudPassword().state(
|
||||
) | rpl::start_with_next([=](const Core::CloudPasswordState &state) {
|
||||
if (!_requestLifetime && !state.hasPassword) {
|
||||
setStepData(StepData());
|
||||
showBack();
|
||||
}
|
||||
}, lifetime());
|
||||
|
||||
SetupTopContent(content, showFinishes());
|
||||
|
||||
AddSkip(content);
|
||||
AddButton(
|
||||
content,
|
||||
tr::lng_settings_cloud_password_manage_password_change(),
|
||||
st::settingsButton,
|
||||
{ &st::settingsIconKey, kIconLightBlue }
|
||||
)->setClickedCallback([=] {
|
||||
// Remember the current password to have ability
|
||||
// to return from Change Password to Password Manage.
|
||||
auto data = stepData();
|
||||
data.currentPassword = _currentPassword;
|
||||
setStepData(std::move(data));
|
||||
|
||||
showOther(CloudPasswordInputId());
|
||||
});
|
||||
AddButton(
|
||||
content,
|
||||
state->hasRecovery
|
||||
? tr::lng_settings_cloud_password_manage_email_change()
|
||||
: tr::lng_settings_cloud_password_manage_email_new(),
|
||||
st::settingsButton,
|
||||
{ &st::settingsIconEmail, kIconLightOrange }
|
||||
)->setClickedCallback([=] {
|
||||
});
|
||||
AddSkip(content);
|
||||
|
||||
using Divider = CloudPassword::OneEdgeBoxContentDivider;
|
||||
const auto divider = Ui::CreateChild<Divider>(this);
|
||||
divider->lower();
|
||||
const auto about = content->add(
|
||||
object_ptr<Ui::PaddingWrap<>>(
|
||||
content,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
content,
|
||||
tr::lng_settings_cloud_password_manage_about2(),
|
||||
st::boxDividerLabel),
|
||||
st::settingsDividerLabelPadding));
|
||||
rpl::combine(
|
||||
about->geometryValue(),
|
||||
content->widthValue()
|
||||
) | rpl::start_with_next([=](QRect r, int w) {
|
||||
r.setWidth(w);
|
||||
divider->setGeometry(r);
|
||||
}, divider->lifetime());
|
||||
_isBottomFillerShown.value(
|
||||
) | rpl::start_with_next([=](bool shown) {
|
||||
divider->skipEdge(Qt::BottomEdge, shown);
|
||||
}, divider->lifetime());
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
}
|
||||
|
||||
QPointer<Ui::RpWidget> Manage::createPinnedToBottom(
|
||||
not_null<Ui::RpWidget*> parent) {
|
||||
|
||||
const auto disable = [=](Fn<void()> close) {
|
||||
if (_requestLifetime) {
|
||||
return;
|
||||
}
|
||||
_requestLifetime = cloudPassword().set(
|
||||
_currentPassword,
|
||||
QString(),
|
||||
QString(),
|
||||
false,
|
||||
QString()
|
||||
) | rpl::start_with_done([=] {
|
||||
setStepData(StepData());
|
||||
close();
|
||||
showBack();
|
||||
});
|
||||
};
|
||||
|
||||
auto callback = [=] {
|
||||
controller()->show(
|
||||
Ui::MakeConfirmBox({
|
||||
.text = tr::lng_settings_cloud_password_manage_disable_sure(),
|
||||
.confirmed = disable,
|
||||
.confirmText = tr::lng_settings_auto_night_disable(),
|
||||
.confirmStyle = &st::attentionBoxButton,
|
||||
}));
|
||||
};
|
||||
auto bottomButton = CloudPassword::CreateBottomDisableButton(
|
||||
parent,
|
||||
geometryValue(),
|
||||
tr::lng_settings_password_disable(),
|
||||
std::move(callback));
|
||||
|
||||
_isBottomFillerShown = base::take(bottomButton.isBottomFillerShown);
|
||||
|
||||
return bottomButton.content;
|
||||
}
|
||||
|
||||
} // namespace CloudPassword
|
||||
|
||||
Type CloudPasswordManageId() {
|
||||
return CloudPassword::Manage::Id();
|
||||
}
|
||||
|
||||
} // namespace Settings
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
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 "settings/settings_type.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
Type CloudPasswordManageId();
|
||||
|
||||
} // namespace Settings
|
||||
|
|
@ -397,7 +397,7 @@ public:
|
|||
[[nodiscard]] rpl::producer<std::vector<Type>> removeFromStack() override;
|
||||
|
||||
[[nodiscard]] QPointer<Ui::RpWidget> createPinnedToBottom(
|
||||
not_null<Ui::RpWidget*> parent) override;
|
||||
not_null<Ui::RpWidget*> parent) override;
|
||||
|
||||
private:
|
||||
void setupContent();
|
||||
|
|
Loading…
Add table
Reference in a new issue