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