mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Passcode lock button added to DialogsWidget.
This commit is contained in:
@@ -27,6 +27,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||
#include "lang.h"
|
||||
#include "application.h"
|
||||
#include "intro/introsignup.h"
|
||||
#include "ui/buttons/round_button.h"
|
||||
|
||||
IntroPwdCheck::IntroPwdCheck(IntroWidget *parent) : IntroStep(parent)
|
||||
, a_errorAlpha(0)
|
||||
@@ -40,27 +41,28 @@ IntroPwdCheck::IntroPwdCheck(IntroWidget *parent) : IntroStep(parent)
|
||||
, _toRecover(this, lang(lng_signin_recover))
|
||||
, _toPassword(this, lang(lng_signin_try_password))
|
||||
, _reset(this, lang(lng_signin_reset_account), st::btnRedLink)
|
||||
, sentRequest(0) {
|
||||
, _checkRequest(this) {
|
||||
setVisible(false);
|
||||
setGeometry(parent->innerRect());
|
||||
|
||||
connect(&_next, SIGNAL(clicked()), this, SLOT(onSubmitPwd()));
|
||||
connect(&checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
|
||||
connect(&_toRecover, SIGNAL(clicked()), this, SLOT(onToRecover()));
|
||||
connect(&_toPassword, SIGNAL(clicked()), this, SLOT(onToPassword()));
|
||||
connect(&_pwdField, SIGNAL(changed()), this, SLOT(onInputChange()));
|
||||
connect(&_codeField, SIGNAL(changed()), this, SLOT(onInputChange()));
|
||||
connect(&_reset, SIGNAL(clicked()), this, SLOT(onReset()));
|
||||
_next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper);
|
||||
connect(_next, SIGNAL(clicked()), this, SLOT(onSubmitPwd()));
|
||||
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
|
||||
connect(_toRecover, SIGNAL(clicked()), this, SLOT(onToRecover()));
|
||||
connect(_toPassword, SIGNAL(clicked()), this, SLOT(onToPassword()));
|
||||
connect(_pwdField, SIGNAL(changed()), this, SLOT(onInputChange()));
|
||||
connect(_codeField, SIGNAL(changed()), this, SLOT(onInputChange()));
|
||||
connect(_reset, SIGNAL(clicked()), this, SLOT(onReset()));
|
||||
|
||||
_pwdField.setEchoMode(QLineEdit::Password);
|
||||
_pwdField->setEchoMode(QLineEdit::Password);
|
||||
|
||||
if (!_hint.isEmpty()) {
|
||||
_hintText.setText(st::introFont, lng_signin_hint(lt_password_hint, _hint));
|
||||
}
|
||||
_codeField.hide();
|
||||
_toPassword.hide();
|
||||
_toRecover.show();
|
||||
_reset.hide();
|
||||
_codeField->hide();
|
||||
_toPassword->hide();
|
||||
_toRecover->show();
|
||||
_reset->hide();
|
||||
|
||||
setMouseTracking(true);
|
||||
}
|
||||
@@ -72,26 +74,26 @@ void IntroPwdCheck::paintEvent(QPaintEvent *e) {
|
||||
if (!trivial) {
|
||||
p.setClipRect(e->rect());
|
||||
}
|
||||
if (trivial || e->rect().intersects(textRect)) {
|
||||
if (trivial || e->rect().intersects(_textRect)) {
|
||||
p.setFont(st::introHeaderFont->f);
|
||||
p.drawText(textRect, lang(lng_signin_title), style::al_top);
|
||||
p.drawText(_textRect, lang(lng_signin_title), style::al_top);
|
||||
p.setFont(st::introFont->f);
|
||||
p.drawText(textRect, lang(_pwdField.isHidden() ? lng_signin_recover_desc : lng_signin_desc), style::al_bottom);
|
||||
p.drawText(_textRect, lang(_pwdField->isHidden() ? lng_signin_recover_desc : lng_signin_desc), style::al_bottom);
|
||||
}
|
||||
if (_pwdField.isHidden()) {
|
||||
if (_pwdField->isHidden()) {
|
||||
if (!_emailPattern.isEmpty()) {
|
||||
p.drawText(QRect(textRect.x(), _pwdField.y() + _pwdField.height() + st::introFinishSkip, textRect.width(), st::introFont->height), _emailPattern, style::al_top);
|
||||
p.drawText(QRect(_textRect.x(), _pwdField->y() + _pwdField->height() + st::introFinishSkip, _textRect.width(), st::introFont->height), _emailPattern, style::al_top);
|
||||
}
|
||||
} else if (!_hint.isEmpty()) {
|
||||
_hintText.drawElided(p, _pwdField.x(), _pwdField.y() + _pwdField.height() + st::introFinishSkip, _pwdField.width(), 1, style::al_top);
|
||||
_hintText.drawElided(p, _pwdField->x(), _pwdField->y() + _pwdField->height() + st::introFinishSkip, _pwdField->width(), 1, style::al_top);
|
||||
}
|
||||
if (_a_error.animating() || error.length()) {
|
||||
if (_a_error.animating() || _error.length()) {
|
||||
p.setOpacity(a_errorAlpha.current());
|
||||
|
||||
QRect errRect((width() - st::introErrorWidth) / 2, (_pwdField.y() + _pwdField.height() + st::introFinishSkip + st::introFont->height + _next.y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight);
|
||||
QRect errRect((width() - st::introErrorWidth) / 2, (_pwdField->y() + _pwdField->height() + st::introFinishSkip + st::introFont->height + _next->y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight);
|
||||
p.setFont(st::introErrorFont);
|
||||
p.setPen(st::introErrorFg);
|
||||
p.drawText(errRect, error, QTextOption(style::al_center));
|
||||
p.drawText(errRect, _error, QTextOption(style::al_center));
|
||||
|
||||
p.setOpacity(1);
|
||||
}
|
||||
@@ -99,21 +101,21 @@ void IntroPwdCheck::paintEvent(QPaintEvent *e) {
|
||||
|
||||
void IntroPwdCheck::resizeEvent(QResizeEvent *e) {
|
||||
if (e->oldSize().width() != width()) {
|
||||
_next.move((width() - _next.width()) / 2, st::introBtnTop);
|
||||
_pwdField.move((width() - _pwdField.width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top);
|
||||
_codeField.move((width() - _codeField.width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top);
|
||||
_toRecover.move(_next.x() + (_pwdField.width() - _toRecover.width()) / 2, _next.y() + _next.height() + st::introFinishSkip);
|
||||
_toPassword.move(_next.x() + (_pwdField.width() - _toPassword.width()) / 2, _next.y() + _next.height() + st::introFinishSkip);
|
||||
_reset.move((width() - _reset.width()) / 2, _toRecover.y() + _toRecover.height() + st::introFinishSkip);
|
||||
_next->move((width() - _next->width()) / 2, st::introBtnTop);
|
||||
_pwdField->move((width() - _pwdField->width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top);
|
||||
_codeField->move((width() - _codeField->width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top);
|
||||
_toRecover->move(_next->x() + (_pwdField->width() - _toRecover->width()) / 2, _next->y() + _next->height() + st::introFinishSkip);
|
||||
_toPassword->move(_next->x() + (_pwdField->width() - _toPassword->width()) / 2, _next->y() + _next->height() + st::introFinishSkip);
|
||||
_reset->move((width() - _reset->width()) / 2, _toRecover->y() + _toRecover->height() + st::introFinishSkip);
|
||||
}
|
||||
textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height());
|
||||
_textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height());
|
||||
}
|
||||
|
||||
void IntroPwdCheck::showError(const QString &err) {
|
||||
if (!_a_error.animating() && err == error) return;
|
||||
void IntroPwdCheck::showError(const QString &error) {
|
||||
if (!_a_error.animating() && error == _error) return;
|
||||
|
||||
if (err.length()) {
|
||||
error = err;
|
||||
if (error.length()) {
|
||||
_error = error;
|
||||
a_errorAlpha.start(1);
|
||||
} else {
|
||||
a_errorAlpha.start(0);
|
||||
@@ -128,7 +130,7 @@ void IntroPwdCheck::step_error(float64 ms, bool timer) {
|
||||
_a_error.stop();
|
||||
a_errorAlpha.finish();
|
||||
if (!a_errorAlpha.current()) {
|
||||
error.clear();
|
||||
_error.clear();
|
||||
}
|
||||
} else {
|
||||
a_errorAlpha.update(dt, anim::linear);
|
||||
@@ -138,51 +140,49 @@ void IntroPwdCheck::step_error(float64 ms, bool timer) {
|
||||
|
||||
void IntroPwdCheck::activate() {
|
||||
IntroStep::activate();
|
||||
if (_pwdField.isHidden()) {
|
||||
_codeField.setFocus();
|
||||
if (_pwdField->isHidden()) {
|
||||
_codeField->setFocus();
|
||||
} else {
|
||||
_pwdField.setFocus();
|
||||
_pwdField->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void IntroPwdCheck::cancelled() {
|
||||
if (sentRequest) {
|
||||
MTP::cancel(sentRequest);
|
||||
sentRequest = 0;
|
||||
if (_sentRequest) {
|
||||
MTP::cancel(base::take(_sentRequest));
|
||||
}
|
||||
}
|
||||
|
||||
void IntroPwdCheck::stopCheck() {
|
||||
checkRequest.stop();
|
||||
_checkRequest->stop();
|
||||
}
|
||||
|
||||
void IntroPwdCheck::onCheckRequest() {
|
||||
int32 status = MTP::state(sentRequest);
|
||||
int32 status = MTP::state(_sentRequest);
|
||||
if (status < 0) {
|
||||
int32 leftms = -status;
|
||||
if (leftms >= 1000) {
|
||||
MTP::cancel(sentRequest);
|
||||
sentRequest = 0;
|
||||
if (!_pwdField.isEnabled()) {
|
||||
_pwdField.setDisabled(false);
|
||||
_codeField.setDisabled(false);
|
||||
MTP::cancel(base::take(_sentRequest));
|
||||
if (!_pwdField->isEnabled()) {
|
||||
_pwdField->setDisabled(false);
|
||||
_codeField->setDisabled(false);
|
||||
activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!sentRequest && status == MTP::RequestSent) {
|
||||
if (!_sentRequest && status == MTP::RequestSent) {
|
||||
stopCheck();
|
||||
}
|
||||
}
|
||||
|
||||
void IntroPwdCheck::pwdSubmitDone(bool recover, const MTPauth_Authorization &result) {
|
||||
sentRequest = 0;
|
||||
_sentRequest = 0;
|
||||
stopCheck();
|
||||
if (recover) {
|
||||
cSetPasswordRecovered(true);
|
||||
}
|
||||
_pwdField.setDisabled(false);
|
||||
_codeField.setDisabled(false);
|
||||
_pwdField->setDisabled(false);
|
||||
_codeField->setDisabled(false);
|
||||
const auto &d(result.c_auth_authorization());
|
||||
if (d.vuser.type() != mtpc_user || !d.vuser.c_user().is_self()) { // wtf?
|
||||
showError(lang(lng_server_error));
|
||||
@@ -193,25 +193,25 @@ void IntroPwdCheck::pwdSubmitDone(bool recover, const MTPauth_Authorization &res
|
||||
|
||||
bool IntroPwdCheck::pwdSubmitFail(const RPCError &error) {
|
||||
if (MTP::isFloodError(error)) {
|
||||
sentRequest = 0;
|
||||
_sentRequest = 0;
|
||||
stopCheck();
|
||||
_codeField.setDisabled(false);
|
||||
_codeField->setDisabled(false);
|
||||
showError(lang(lng_flood_error));
|
||||
_pwdField.setDisabled(false);
|
||||
_pwdField.notaBene();
|
||||
_pwdField->setDisabled(false);
|
||||
_pwdField->notaBene();
|
||||
return true;
|
||||
}
|
||||
if (MTP::isDefaultHandledError(error)) return false;
|
||||
|
||||
sentRequest = 0;
|
||||
_sentRequest = 0;
|
||||
stopCheck();
|
||||
_pwdField.setDisabled(false);
|
||||
_codeField.setDisabled(false);
|
||||
_pwdField->setDisabled(false);
|
||||
_codeField->setDisabled(false);
|
||||
const QString &err = error.type();
|
||||
if (err == qstr("PASSWORD_HASH_INVALID")) {
|
||||
showError(lang(lng_signin_bad_password));
|
||||
_pwdField.selectAll();
|
||||
_pwdField.notaBene();
|
||||
_pwdField->selectAll();
|
||||
_pwdField->notaBene();
|
||||
return true;
|
||||
} else if (err == qstr("PASSWORD_EMPTY")) {
|
||||
intro()->onBack();
|
||||
@@ -221,22 +221,22 @@ bool IntroPwdCheck::pwdSubmitFail(const RPCError &error) {
|
||||
} else {
|
||||
showError(lang(lng_server_error));
|
||||
}
|
||||
_pwdField.setFocus();
|
||||
_pwdField->setFocus();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IntroPwdCheck::codeSubmitFail(const RPCError &error) {
|
||||
if (MTP::isFloodError(error)) {
|
||||
showError(lang(lng_flood_error));
|
||||
_codeField.notaBene();
|
||||
_codeField->notaBene();
|
||||
return true;
|
||||
}
|
||||
if (MTP::isDefaultHandledError(error)) return false;
|
||||
|
||||
sentRequest = 0;
|
||||
_sentRequest = 0;
|
||||
stopCheck();
|
||||
_pwdField.setDisabled(false);
|
||||
_codeField.setDisabled(false);
|
||||
_pwdField->setDisabled(false);
|
||||
_codeField->setDisabled(false);
|
||||
const QString &err = error.type();
|
||||
if (err == qstr("PASSWORD_EMPTY")) {
|
||||
intro()->onBack();
|
||||
@@ -250,8 +250,8 @@ bool IntroPwdCheck::codeSubmitFail(const RPCError &error) {
|
||||
return true;
|
||||
} else if (err == qstr("CODE_INVALID")) {
|
||||
showError(lang(lng_signin_wrong_code));
|
||||
_codeField.selectAll();
|
||||
_codeField.notaBene();
|
||||
_codeField->selectAll();
|
||||
_codeField->notaBene();
|
||||
return true;
|
||||
}
|
||||
if (cDebug()) { // internal server error
|
||||
@@ -259,22 +259,22 @@ bool IntroPwdCheck::codeSubmitFail(const RPCError &error) {
|
||||
} else {
|
||||
showError(lang(lng_server_error));
|
||||
}
|
||||
_codeField.setFocus();
|
||||
_codeField->setFocus();
|
||||
return false;
|
||||
}
|
||||
|
||||
void IntroPwdCheck::recoverStarted(const MTPauth_PasswordRecovery &result) {
|
||||
_emailPattern = st::introFont->elided(lng_signin_recover_hint(lt_recover_email, qs(result.c_auth_passwordRecovery().vemail_pattern)), textRect.width());
|
||||
_emailPattern = st::introFont->elided(lng_signin_recover_hint(lt_recover_email, qs(result.c_auth_passwordRecovery().vemail_pattern)), _textRect.width());
|
||||
update();
|
||||
}
|
||||
|
||||
bool IntroPwdCheck::recoverStartFail(const RPCError &error) {
|
||||
stopCheck();
|
||||
_pwdField.setDisabled(false);
|
||||
_codeField.setDisabled(false);
|
||||
_pwdField.show();
|
||||
_codeField.hide();
|
||||
_pwdField.setFocus();
|
||||
_pwdField->setDisabled(false);
|
||||
_codeField->setDisabled(false);
|
||||
_pwdField->show();
|
||||
_codeField->hide();
|
||||
_pwdField->setFocus();
|
||||
update();
|
||||
showError(QString());
|
||||
return true;
|
||||
@@ -282,17 +282,16 @@ bool IntroPwdCheck::recoverStartFail(const RPCError &error) {
|
||||
|
||||
void IntroPwdCheck::onToRecover() {
|
||||
if (_hasRecovery) {
|
||||
if (sentRequest) {
|
||||
MTP::cancel(sentRequest);
|
||||
sentRequest = 0;
|
||||
if (_sentRequest) {
|
||||
MTP::cancel(base::take(_sentRequest));
|
||||
}
|
||||
showError(QString());
|
||||
_toRecover.hide();
|
||||
_toPassword.show();
|
||||
_pwdField.hide();
|
||||
_pwdField.setText(QString());
|
||||
_codeField.show();
|
||||
_codeField.setFocus();
|
||||
_toRecover->hide();
|
||||
_toPassword->show();
|
||||
_pwdField->hide();
|
||||
_pwdField->setText(QString());
|
||||
_codeField->show();
|
||||
_codeField->setFocus();
|
||||
if (_emailPattern.isEmpty()) {
|
||||
MTP::send(MTPauth_RequestPasswordRecovery(), rpcDone(&IntroPwdCheck::recoverStarted), rpcFail(&IntroPwdCheck::recoverStartFail));
|
||||
}
|
||||
@@ -311,36 +310,35 @@ void IntroPwdCheck::onToPassword() {
|
||||
}
|
||||
|
||||
void IntroPwdCheck::onToReset() {
|
||||
if (sentRequest) {
|
||||
MTP::cancel(sentRequest);
|
||||
sentRequest = 0;
|
||||
if (_sentRequest) {
|
||||
MTP::cancel(base::take(_sentRequest));
|
||||
}
|
||||
_toRecover.show();
|
||||
_toPassword.hide();
|
||||
_pwdField.show();
|
||||
_codeField.hide();
|
||||
_codeField.setText(QString());
|
||||
_pwdField.setFocus();
|
||||
_reset.show();
|
||||
_toRecover->show();
|
||||
_toPassword->hide();
|
||||
_pwdField->show();
|
||||
_codeField->hide();
|
||||
_codeField->setText(QString());
|
||||
_pwdField->setFocus();
|
||||
_reset->show();
|
||||
update();
|
||||
}
|
||||
|
||||
void IntroPwdCheck::onReset() {
|
||||
if (sentRequest) return;
|
||||
if (_sentRequest) return;
|
||||
ConfirmBox *box = new ConfirmBox(lang(lng_signin_sure_reset), lang(lng_signin_reset), st::attentionBoxButton);
|
||||
connect(box, SIGNAL(confirmed()), this, SLOT(onResetSure()));
|
||||
Ui::showLayer(box);
|
||||
}
|
||||
|
||||
void IntroPwdCheck::onResetSure() {
|
||||
if (sentRequest) return;
|
||||
sentRequest = MTP::send(MTPaccount_DeleteAccount(MTP_string("Forgot password")), rpcDone(&IntroPwdCheck::deleteDone), rpcFail(&IntroPwdCheck::deleteFail));
|
||||
if (_sentRequest) return;
|
||||
_sentRequest = MTP::send(MTPaccount_DeleteAccount(MTP_string("Forgot password")), rpcDone(&IntroPwdCheck::deleteDone), rpcFail(&IntroPwdCheck::deleteFail));
|
||||
}
|
||||
|
||||
bool IntroPwdCheck::deleteFail(const RPCError &error) {
|
||||
if (MTP::isDefaultHandledError(error)) return false;
|
||||
|
||||
sentRequest = 0;
|
||||
_sentRequest = 0;
|
||||
|
||||
auto type = error.type();
|
||||
if (type.startsWith(qstr("2FA_CONFIRM_WAIT_"))) {
|
||||
@@ -376,27 +374,27 @@ void IntroPwdCheck::onInputChange() {
|
||||
}
|
||||
|
||||
void IntroPwdCheck::onSubmitPwd(bool force) {
|
||||
if (sentRequest) return;
|
||||
if (_pwdField.isHidden()) {
|
||||
if (!force && !_codeField.isEnabled()) return;
|
||||
QString code = _codeField.text().trimmed();
|
||||
if (_sentRequest) return;
|
||||
if (_pwdField->isHidden()) {
|
||||
if (!force && !_codeField->isEnabled()) return;
|
||||
QString code = _codeField->text().trimmed();
|
||||
if (code.isEmpty()) {
|
||||
_codeField.notaBene();
|
||||
_codeField->notaBene();
|
||||
return;
|
||||
}
|
||||
|
||||
sentRequest = MTP::send(MTPauth_RecoverPassword(MTP_string(code)), rpcDone(&IntroPwdCheck::pwdSubmitDone, true), rpcFail(&IntroPwdCheck::codeSubmitFail));
|
||||
_sentRequest = MTP::send(MTPauth_RecoverPassword(MTP_string(code)), rpcDone(&IntroPwdCheck::pwdSubmitDone, true), rpcFail(&IntroPwdCheck::codeSubmitFail));
|
||||
} else {
|
||||
if (!force && !_pwdField.isEnabled()) return;
|
||||
if (!force && !_pwdField->isEnabled()) return;
|
||||
|
||||
_pwdField.setDisabled(true);
|
||||
_pwdField->setDisabled(true);
|
||||
setFocus();
|
||||
|
||||
showError(QString());
|
||||
|
||||
QByteArray pwdData = _salt + _pwdField.text().toUtf8() + _salt, pwdHash(32, Qt::Uninitialized);
|
||||
QByteArray pwdData = _salt + _pwdField->text().toUtf8() + _salt, pwdHash(32, Qt::Uninitialized);
|
||||
hashSha256(pwdData.constData(), pwdData.size(), pwdHash.data());
|
||||
sentRequest = MTP::send(MTPauth_CheckPassword(MTP_bytes(pwdHash)), rpcDone(&IntroPwdCheck::pwdSubmitDone, false), rpcFail(&IntroPwdCheck::pwdSubmitFail));
|
||||
_sentRequest = MTP::send(MTPauth_CheckPassword(MTP_bytes(pwdHash)), rpcDone(&IntroPwdCheck::pwdSubmitDone, false), rpcFail(&IntroPwdCheck::pwdSubmitFail));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user