Short poll email confirmation in passport.

This commit is contained in:
John Preston 2018-04-17 15:26:11 +04:00
parent 9f6130cd20
commit 395f22063b
2 changed files with 62 additions and 25 deletions

View File

@ -28,6 +28,7 @@ namespace Passport {
namespace { namespace {
constexpr auto kDocumentScansLimit = 20; constexpr auto kDocumentScansLimit = 20;
constexpr auto kShortPollTimeout = TimeMs(3000);
bool ForwardServiceErrorRequired(const QString &error) { bool ForwardServiceErrorRequired(const QString &error) {
return (error == qstr("BOT_INVALID")) return (error == qstr("BOT_INVALID"))
@ -216,6 +217,7 @@ FormController::FormController(
const FormRequest &request) const FormRequest &request)
: _controller(controller) : _controller(controller)
, _request(PreprocessRequest(request)) , _request(PreprocessRequest(request))
, _shortPollTimer([=] { reloadPassword(); })
, _view(std::make_unique<PanelController>(this)) { , _view(std::make_unique<PanelController>(this)) {
} }
@ -1743,18 +1745,27 @@ void FormController::requestPassword() {
} }
void FormController::passwordDone(const MTPaccount_Password &result) { void FormController::passwordDone(const MTPaccount_Password &result) {
const auto changed = [&] {
switch (result.type()) { switch (result.type()) {
case mtpc_account_noPassword: case mtpc_account_noPassword:
parsePassword(result.c_account_noPassword()); return applyPassword(result.c_account_noPassword());
break;
case mtpc_account_password: case mtpc_account_password:
parsePassword(result.c_account_password()); return applyPassword(result.c_account_password());
break;
} }
if (!_formRequestId) { Unexpected("Type in FormController::passwordDone.");
}();
if (changed && !_formRequestId) {
showForm(); showForm();
} }
shortPollEmailConfirmation();
}
void FormController::shortPollEmailConfirmation() {
if (_password.unconfirmedPattern.isEmpty()) {
_shortPollTimer.cancel();
return;
}
_shortPollTimer.callOnce(kShortPollTimeout);
} }
void FormController::showForm() { void FormController::showForm() {
@ -1769,23 +1780,33 @@ void FormController::showForm() {
} }
} }
void FormController::parsePassword(const MTPDaccount_noPassword &result) { bool FormController::applyPassword(const MTPDaccount_noPassword &result) {
_password = PasswordSettings(); auto settings = PasswordSettings();
_password.unconfirmedPattern = qs(result.vemail_unconfirmed_pattern); settings.unconfirmedPattern = qs(result.vemail_unconfirmed_pattern);
_password.newSalt = bytes::make_vector(result.vnew_salt.v); settings.newSalt = bytes::make_vector(result.vnew_salt.v);
_password.newSecureSalt = bytes::make_vector(result.vnew_secure_salt.v); settings.newSecureSalt = bytes::make_vector(result.vnew_secure_salt.v);
openssl::AddRandomSeed(bytes::make_span(result.vsecure_random.v)); openssl::AddRandomSeed(bytes::make_span(result.vsecure_random.v));
return applyPassword(std::move(settings));
} }
void FormController::parsePassword(const MTPDaccount_password &result) { bool FormController::applyPassword(const MTPDaccount_password &result) {
_password = PasswordSettings(); auto settings = PasswordSettings();
_password.hint = qs(result.vhint); settings.hint = qs(result.vhint);
_password.hasRecovery = mtpIsTrue(result.vhas_recovery); settings.hasRecovery = mtpIsTrue(result.vhas_recovery);
_password.salt = bytes::make_vector(result.vcurrent_salt.v); settings.salt = bytes::make_vector(result.vcurrent_salt.v);
_password.unconfirmedPattern = qs(result.vemail_unconfirmed_pattern); settings.unconfirmedPattern = qs(result.vemail_unconfirmed_pattern);
_password.newSalt = bytes::make_vector(result.vnew_salt.v); settings.newSalt = bytes::make_vector(result.vnew_salt.v);
_password.newSecureSalt = bytes::make_vector(result.vnew_secure_salt.v); settings.newSecureSalt = bytes::make_vector(result.vnew_secure_salt.v);
openssl::AddRandomSeed(bytes::make_span(result.vsecure_random.v)); openssl::AddRandomSeed(bytes::make_span(result.vsecure_random.v));
return applyPassword(std::move(settings));
}
bool FormController::applyPassword(PasswordSettings &&settings) {
if (_password != settings) {
_password = std::move(settings);
return true;
}
return false;
} }
void FormController::cancel() { void FormController::cancel() {

View File

@ -178,6 +178,19 @@ struct PasswordSettings {
QString unconfirmedPattern; QString unconfirmedPattern;
QString confirmedEmail; QString confirmedEmail;
bool hasRecovery = false; bool hasRecovery = false;
bool operator==(const PasswordSettings &other) const {
return (salt == other.salt)
&& (newSalt == other.newSalt)
&& (newSecureSalt == other.newSecureSalt)
&& (hint == other.hint)
&& (unconfirmedPattern == other.unconfirmedPattern)
&& (confirmedEmail == other.confirmedEmail)
&& (hasRecovery == other.hasRecovery);
}
bool operator!=(const PasswordSettings &other) const {
return !(*this == other);
}
}; };
struct FileKey { struct FileKey {
@ -290,8 +303,9 @@ private:
const std::vector<EditFile> &source) const; const std::vector<EditFile> &source) const;
void passwordDone(const MTPaccount_Password &result); void passwordDone(const MTPaccount_Password &result);
void parsePassword(const MTPDaccount_noPassword &settings); bool applyPassword(const MTPDaccount_noPassword &settings);
void parsePassword(const MTPDaccount_password &settings); bool applyPassword(const MTPDaccount_password &settings);
bool applyPassword(PasswordSettings &&settings);
bytes::vector passwordHashForAuth(bytes::const_span password) const; bytes::vector passwordHashForAuth(bytes::const_span password) const;
void validateSecureSecret( void validateSecureSecret(
bytes::const_span salt, bytes::const_span salt,
@ -358,6 +372,7 @@ private:
void suggestReset(bytes::vector password); void suggestReset(bytes::vector password);
void suggestRestart(); void suggestRestart();
void cancelAbort(); void cancelAbort();
void shortPollEmailConfirmation();
not_null<Window::Controller*> _controller; not_null<Window::Controller*> _controller;
FormRequest _request; FormRequest _request;
@ -387,6 +402,7 @@ private:
bool _submitSuccess = false; bool _submitSuccess = false;
bool _suggestingRestart = false; bool _suggestingRestart = false;
QString _serviceErrorText; QString _serviceErrorText;
base::Timer _shortPollTimer;
rpl::lifetime _uploaderSubscriptions; rpl::lifetime _uploaderSubscriptions;
rpl::lifetime _lifetime; rpl::lifetime _lifetime;