mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Added handler of urls for login.
This commit is contained in:
parent
9896855789
commit
d424a8b039
7 changed files with 89 additions and 10 deletions
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "apiwrap.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_session.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "ui/boxes/confirm_phone_box.h"
|
||||
|
@ -77,6 +78,12 @@ void ConfirmPhone::resolve(
|
|||
fragmentUrl,
|
||||
timeout);
|
||||
const auto boxWeak = Ui::MakeWeak(box.data());
|
||||
using LoginCode = rpl::event_stream<QString>;
|
||||
const auto codeHandles = box->lifetime().make_state<LoginCode>();
|
||||
controller->session().account().setHandleLoginCode([=](
|
||||
const QString &code) {
|
||||
codeHandles->fire_copy(code);
|
||||
});
|
||||
box->resendRequests(
|
||||
) | rpl::start_with_next([=] {
|
||||
_api.request(MTPauth_ResendCode(
|
||||
|
@ -88,7 +95,9 @@ void ConfirmPhone::resolve(
|
|||
}
|
||||
}).send();
|
||||
}, box->lifetime());
|
||||
box->checkRequests(
|
||||
rpl::merge(
|
||||
codeHandles->events(),
|
||||
box->checkRequests()
|
||||
) | rpl::start_with_next([=](const QString &code) {
|
||||
if (_checkRequestId) {
|
||||
return;
|
||||
|
@ -120,6 +129,10 @@ void ConfirmPhone::resolve(
|
|||
boxWeak->showServerError(errorText);
|
||||
}).handleFloodErrors().send();
|
||||
}, box->lifetime());
|
||||
box->boxClosing(
|
||||
) | rpl::start_with_next([=] {
|
||||
controller->session().account().setHandleLoginCode(nullptr);
|
||||
}, box->lifetime());
|
||||
|
||||
controller->show(std::move(box), Ui::LayerOption::CloseOther);
|
||||
});
|
||||
|
|
|
@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/boxes/confirm_box.h"
|
||||
#include "boxes/phone_banned_box.h"
|
||||
#include "countries/countries_instance.h" // Countries::ExtractPhoneCode.
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_session.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
|
@ -126,7 +127,7 @@ protected:
|
|||
void prepare() override;
|
||||
|
||||
private:
|
||||
void submit();
|
||||
void submit(const QString &code);
|
||||
void sendCall();
|
||||
void updateCall();
|
||||
void sendCodeFail(const MTP::Error &error);
|
||||
|
@ -344,18 +345,20 @@ void ChangePhone::EnterCode::prepare() {
|
|||
st::changePhoneLabel);
|
||||
description->moveToLeft(st::boxPadding.left(), 0);
|
||||
|
||||
const auto submitInput = [=] { submit(_code->getDigitsOnly()); };
|
||||
|
||||
const auto phoneValue = QString();
|
||||
_code.create(
|
||||
this,
|
||||
st::defaultInputField,
|
||||
tr::lng_change_phone_code_title(),
|
||||
phoneValue);
|
||||
_code->setAutoSubmit(_codeLength, [=] { submit(); });
|
||||
_code->setAutoSubmit(_codeLength, submitInput);
|
||||
_code->setChangedCallback([=] { hideError(); });
|
||||
|
||||
_code->resize(width - 2 * st::boxPadding.left(), _code->height());
|
||||
_code->moveToLeft(st::boxPadding.left(), description->bottomNoMargins());
|
||||
connect(_code, &Ui::InputField::submitted, [=] { submit(); });
|
||||
connect(_code, &Ui::InputField::submitted, submitInput);
|
||||
|
||||
if (!_openUrl.isEmpty()) {
|
||||
_fragment.create(
|
||||
|
@ -372,6 +375,14 @@ void ChangePhone::EnterCode::prepare() {
|
|||
codeBottom + ErrorSkip() + st::boxLittleSkip);
|
||||
}
|
||||
|
||||
_controller->session().account().setHandleLoginCode([=](QString code) {
|
||||
submit(code);
|
||||
});
|
||||
boxClosing(
|
||||
) | rpl::start_with_next([controller = _controller] {
|
||||
controller->session().account().setHandleLoginCode(nullptr);
|
||||
}, lifetime());
|
||||
|
||||
setDimensions(width, countHeight());
|
||||
|
||||
if (_callTimeout > 0) {
|
||||
|
@ -379,7 +390,7 @@ void ChangePhone::EnterCode::prepare() {
|
|||
updateCall();
|
||||
}
|
||||
|
||||
addButton(tr::lng_change_phone_new_submit(), [=] { submit(); });
|
||||
addButton(tr::lng_change_phone_new_submit(), submitInput);
|
||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||
}
|
||||
|
||||
|
@ -390,14 +401,13 @@ int ChangePhone::EnterCode::countHeight() const {
|
|||
+ (_fragment ? _fragment->height() : 0);
|
||||
}
|
||||
|
||||
void ChangePhone::EnterCode::submit() {
|
||||
void ChangePhone::EnterCode::submit(const QString &code) {
|
||||
if (_requestId) {
|
||||
return;
|
||||
}
|
||||
hideError();
|
||||
|
||||
const auto session = &_controller->session();
|
||||
const auto code = _code->getDigitsOnly();
|
||||
const auto weak = Ui::MakeWeak(this);
|
||||
_requestId = session->api().request(MTPaccount_ChangePhone(
|
||||
MTP_string(_phone),
|
||||
|
|
|
@ -49,6 +49,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "settings/settings_chat.h"
|
||||
#include "settings/settings_premium.h"
|
||||
#include "mainwidget.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_session.h"
|
||||
#include "main/main_session_settings.h"
|
||||
#include "inline_bots/bot_attach_web_view.h"
|
||||
|
@ -792,6 +793,25 @@ bool ResolvePremiumOffer(
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ResolveLoginCode(
|
||||
Window::SessionController *controller,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
const auto loginCode = match->captured(2);
|
||||
if (loginCode.isEmpty()) {
|
||||
return false;
|
||||
};
|
||||
(controller
|
||||
? controller->session().account()
|
||||
: Core::App().activeAccount()).handleLoginCode(loginCode);
|
||||
if (controller) {
|
||||
controller->window().activate();
|
||||
} else if (const auto window = Core::App().activeWindow()) {
|
||||
window->activate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const std::vector<LocalUrlHandler> &LocalUrlHandlers() {
|
||||
|
@ -864,6 +884,10 @@ const std::vector<LocalUrlHandler> &LocalUrlHandlers() {
|
|||
u"premium_offer/?(\\?.+)?(#|$)"_q,
|
||||
ResolvePremiumOffer,
|
||||
},
|
||||
{
|
||||
u"^login/?(\\?code=([0-9]+))(&|$)"_q,
|
||||
ResolveLoginCode
|
||||
},
|
||||
{
|
||||
u"^([^\\?]+)(\\?|#|$)"_q,
|
||||
HandleUnknown
|
||||
|
|
|
@ -105,6 +105,11 @@ CodeWidget::CodeWidget(
|
|||
? rpl::single(Ui::FormatPhone(getData()->phone))
|
||||
: tr::lng_intro_fragment_title());
|
||||
updateDescText();
|
||||
|
||||
account->setHandleLoginCode([=](const QString &code) {
|
||||
_code->setText(code);
|
||||
submitCode();
|
||||
});
|
||||
}
|
||||
|
||||
void CodeWidget::refreshLang() {
|
||||
|
@ -217,6 +222,7 @@ void CodeWidget::activate() {
|
|||
|
||||
void CodeWidget::finished() {
|
||||
Step::finished();
|
||||
account().setHandleLoginCode(nullptr);
|
||||
_checkRequestTimer.cancel();
|
||||
_callTimer.cancel();
|
||||
apiClear();
|
||||
|
|
|
@ -602,6 +602,16 @@ void Account::destroyStaleAuthorizationKeys() {
|
|||
}
|
||||
}
|
||||
|
||||
void Account::setHandleLoginCode(Fn<void(QString)> callback) {
|
||||
_handleLoginCode = std::move(callback);
|
||||
}
|
||||
|
||||
void Account::handleLoginCode(const QString &code) const {
|
||||
if (_handleLoginCode) {
|
||||
_handleLoginCode(code);
|
||||
}
|
||||
}
|
||||
|
||||
void Account::resetAuthorizationKeys() {
|
||||
Expects(_mtp != nullptr);
|
||||
|
||||
|
|
|
@ -110,6 +110,9 @@ public:
|
|||
void suggestMainDcId(MTP::DcId mainDcId);
|
||||
void destroyStaleAuthorizationKeys();
|
||||
|
||||
void setHandleLoginCode(Fn<void(QString)> callback);
|
||||
void handleLoginCode(const QString &code) const;
|
||||
|
||||
[[nodiscard]] rpl::lifetime &lifetime() {
|
||||
return _lifetime;
|
||||
}
|
||||
|
@ -152,6 +155,8 @@ private:
|
|||
std::unique_ptr<Session> _session;
|
||||
rpl::variable<Session*> _sessionValue;
|
||||
|
||||
Fn<void(QString)> _handleLoginCode = nullptr;
|
||||
|
||||
UserId _sessionUserId = 0;
|
||||
QByteArray _sessionUserSerialized;
|
||||
int32 _sessionUserStreamVersion = 0;
|
||||
|
|
|
@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "passport/passport_panel_controller.h"
|
||||
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_session.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "passport/passport_panel_edit_document.h"
|
||||
#include "passport/passport_panel_edit_contact.h"
|
||||
|
@ -1319,12 +1321,16 @@ void PanelController::processVerificationNeeded(
|
|||
});
|
||||
const auto box = [&] {
|
||||
if (type == Value::Type::Phone) {
|
||||
return show(VerifyPhoneBox(
|
||||
const auto submit = [=](const QString &code) {
|
||||
_form->verify(value, code);
|
||||
};
|
||||
const auto account = &_form->window()->session().account();
|
||||
account->setHandleLoginCode(submit);
|
||||
const auto box = show(VerifyPhoneBox(
|
||||
text,
|
||||
value->verification.codeLength,
|
||||
value->verification.fragmentUrl,
|
||||
[=](const QString &code) { _form->verify(value, code); },
|
||||
|
||||
submit,
|
||||
value->verification.call ? rpl::single(
|
||||
value->verification.call->getText()
|
||||
) | rpl::then(rpl::duplicate(
|
||||
|
@ -1340,6 +1346,11 @@ void PanelController::processVerificationNeeded(
|
|||
) | rpl::map([=](not_null<const Value*> field) {
|
||||
return field->verification.error;
|
||||
}) | rpl::distinct_until_changed()));
|
||||
box->boxClosing(
|
||||
) | rpl::start_with_next([=] {
|
||||
account->setHandleLoginCode(nullptr);
|
||||
}, box->lifetime());
|
||||
return box;
|
||||
} else if (type == Value::Type::Email) {
|
||||
return show(VerifyEmailBox(
|
||||
text,
|
||||
|
|
Loading…
Add table
Reference in a new issue