Fixed handler of login email in intro section.

This occurs both log in with setting up of login email
and log in by code from login email (set before).
This commit is contained in:
23rd
2025-11-23 15:26:59 +03:00
parent 6590f3b741
commit 7f56192b97
5 changed files with 76 additions and 20 deletions

View File

@@ -84,10 +84,13 @@ void CodeWidget::updateDescText() {
const auto byTelegram = getData()->codeByTelegram;
const auto isFragment = !getData()->codeByFragmentUrl.isEmpty();
_isFragment = isFragment;
setDescriptionText(isEmailVerification()
const auto emailPattern = !getData()->emailPatternSetup.isEmpty()
? getData()->emailPatternSetup
: getData()->emailPatternLogin;
setDescriptionText(!emailPattern.isEmpty()
? tr::lng_intro_email_confirm_subtitle(
lt_email,
rpl::single(Ui::Text::WrapEmailPattern(getData()->emailPattern)),
rpl::single(Ui::Text::WrapEmailPattern(emailPattern)),
Ui::Text::WithEntities)
: isFragment
? tr::lng_intro_fragment_about(
@@ -229,6 +232,37 @@ void CodeWidget::codeSubmitDone(const MTPauth_Authorization &result) {
finish(result);
}
void CodeWidget::emailVerifyDone(const MTPaccount_EmailVerified &result) {
stopCheck();
_sentRequest = 0;
result.match([&](const MTPDaccount_emailVerified &data) {
_code->setEnabled(true);
showCodeError(rpl::single(
u"Unexpected type of response: emailVerifiedLogin"_q));
}, [&](const MTPDaccount_emailVerifiedLogin &data) {
getData()->emailPatternSetup.clear();
data.vsent_code().match([&](const MTPDauth_sentCode &sentData) {
fillSentCodeData(sentData);
getData()->phoneHash = qba(sentData.vphone_code_hash());
const auto next = sentData.vnext_type();
if (next && next->type() == mtpc_auth_codeTypeCall) {
getData()->callStatus = CallStatus::Waiting;
getData()->callTimeout = sentData.vtimeout().value_or(60);
} else {
getData()->callStatus = CallStatus::Disabled;
getData()->callTimeout = 0;
}
goReplace<CodeWidget>(Animate::Forward);
}, [&](const MTPDauth_sentCodeSuccess &sentData) {
finish(sentData.vauthorization());
}, [](const MTPDauth_sentCodePaymentRequired &) {
LOG(("API Error: Unexpected auth.sentCodePaymentRequired "
"(CodeWidget::emailVerifyDone)."));
});
});
}
void CodeWidget::codeSubmitFail(const MTP::Error &error) {
if (MTP::IsFloodError(error)) {
stopCheck();
@@ -352,23 +386,39 @@ void CodeWidget::submitCode(const QString &text) {
_sentCode = text;
_code->setEnabled(false);
getData()->pwdState = Core::CloudPasswordState();
_sentRequest = api().request(MTPauth_SignIn(
MTP_flags(isEmailVerification()
? MTPauth_SignIn::Flag::f_email_verification
: MTPauth_SignIn::Flag::f_phone_code),
MTP_string(getData()->phone),
MTP_bytes(getData()->phoneHash),
MTP_string(_sentCode),
MTP_emailVerificationCode(MTP_string(_sentCode))
)).done([=](const MTPauth_Authorization &result) {
codeSubmitDone(result);
}).fail([=](const MTP::Error &error) {
codeSubmitFail(error);
}).handleFloodErrors().send();
if (isEmailVerification()) {
_sentRequest = api().request(MTPaccount_VerifyEmail(
MTP_emailVerifyPurposeLoginSetup(
MTP_string(getData()->phone),
MTP_bytes(getData()->phoneHash)),
MTP_emailVerificationCode(MTP_string(_sentCode))
)).done([=](const MTPaccount_EmailVerified &result) {
emailVerifyDone(result);
}).fail([=](const MTP::Error &error) {
codeSubmitFail(error);
}).handleFloodErrors().send();
} else {
const auto isEmailLogin = !getData()->emailPatternLogin.isEmpty();
_sentRequest = api().request(MTPauth_SignIn(
MTP_flags(isEmailLogin
? MTPauth_SignIn::Flag::f_email_verification
: MTPauth_SignIn::Flag::f_phone_code),
MTP_string(getData()->phone),
MTP_bytes(getData()->phoneHash),
MTP_string(_sentCode),
MTP_emailVerificationCode(
MTP_string(isEmailLogin ? _sentCode : QString()))
)).done([=](const MTPauth_Authorization &result) {
codeSubmitDone(result);
}).fail([=](const MTP::Error &error) {
codeSubmitFail(error);
}).handleFloodErrors().send();
}
}
bool CodeWidget::isEmailVerification() const {
return !getData()->emailPattern.isEmpty();
return !getData()->emailPatternSetup.isEmpty();
}
rpl::producer<QString> CodeWidget::nextButtonText() const {

View File

@@ -62,6 +62,7 @@ private:
void codeSubmitDone(const MTPauth_Authorization &result);
void codeSubmitFail(const MTP::Error &error);
void emailVerifyDone(const MTPaccount_EmailVerified &result);
void showCodeError(rpl::producer<QString> text);
void callDone(const MTPauth_SentCode &result);

View File

@@ -78,6 +78,9 @@ EmailWidget::EmailWidget(
newInput->changes() | rpl::start_with_next([=] {
error->hide();
}, newInput->lifetime());
newInput->submits() | rpl::start_with_next([=] {
submit();
}, newInput->lifetime());
newInput->setText(getData()->email);
if (newInput->hasText()) {
newInput->selectAll();
@@ -93,7 +96,7 @@ EmailWidget::EmailWidget(
const auto done = [=](int length, const QString &pattern) {
_sentRequest = 0;
getData()->codeLength = length;
getData()->emailPattern = pattern;
getData()->emailPatternSetup = pattern;
goNext<CodeWidget>();
};
const auto fail = [=](const QString &type) {

View File

@@ -374,8 +374,9 @@ void Step::fillSentCodeData(const MTPDauth_sentCode &data) {
bad("MissedCall");
}, [&](const MTPDauth_sentCodeTypeFirebaseSms &) {
bad("FirebaseSms");
}, [&](const MTPDauth_sentCodeTypeEmailCode &) {
bad("EmailCode");
}, [&](const MTPDauth_sentCodeTypeEmailCode &data) {
getData()->emailPatternLogin = qs(data.vemail_pattern());
getData()->codeLength = data.vlength().v;
}, [&](const MTPDauth_sentCodeTypeSmsWord &) {
bad("SmsWord");
}, [&](const MTPDauth_sentCodeTypeSmsPhrase &) {

View File

@@ -65,7 +65,8 @@ struct Data {
EmailStatus emailStatus = EmailStatus::None;
QString email;
QString emailPattern;
QString emailPatternSetup;
QString emailPatternLogin;
Core::CloudPasswordState pwdState;