2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2019-11-27 09:45:23 +00:00
|
|
|
#include "intro/intro_signup.h"
|
2016-04-21 17:57:29 +00:00
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
#include "intro/intro_widget.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "core/file_utilities.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/photo_crop_box.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2017-03-07 09:17:37 +00:00
|
|
|
#include "ui/special_buttons.h"
|
2019-11-26 11:10:44 +00:00
|
|
|
#include "styles/style_intro.h"
|
|
|
|
#include "styles/style_boxes.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
namespace Intro {
|
2019-11-26 11:10:44 +00:00
|
|
|
namespace details {
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2019-07-24 08:46:23 +00:00
|
|
|
SignupWidget::SignupWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Main::Account*> account,
|
2019-11-26 11:10:44 +00:00
|
|
|
not_null<Data*> data)
|
2019-11-27 08:33:18 +00:00
|
|
|
: Step(parent, account, data)
|
|
|
|
, _photo(
|
|
|
|
this,
|
|
|
|
tr::lng_settings_crop_profile(tr::now),
|
|
|
|
Ui::UserpicButton::Role::ChangePhoto,
|
|
|
|
st::defaultUserpicButton)
|
|
|
|
, _first(this, st::introName, tr::lng_signup_firstname())
|
|
|
|
, _last(this, st::introName, tr::lng_signup_lastname())
|
|
|
|
, _invertOrder(langFirstNameGoesSecond()) {
|
2017-05-30 13:54:05 +00:00
|
|
|
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
|
2017-05-30 15:21:05 +00:00
|
|
|
if (_invertOrder) {
|
|
|
|
setTabOrder(_last, _first);
|
|
|
|
} else {
|
|
|
|
setTabOrder(_first, _last);
|
|
|
|
}
|
2017-05-30 13:54:05 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
setErrorCentered(true);
|
2015-09-23 17:43:08 +00:00
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
setTitleText(tr::lng_signup_title());
|
|
|
|
setDescriptionText(tr::lng_signup_desc());
|
2014-05-30 08:53:19 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
2018-06-01 07:00:18 +00:00
|
|
|
void SignupWidget::finishInit() {
|
|
|
|
showTerms();
|
|
|
|
}
|
|
|
|
|
2017-05-30 13:54:05 +00:00
|
|
|
void SignupWidget::refreshLang() {
|
2017-05-30 15:21:05 +00:00
|
|
|
_invertOrder = langFirstNameGoesSecond();
|
|
|
|
if (_invertOrder) {
|
|
|
|
setTabOrder(_last, _first);
|
|
|
|
} else {
|
|
|
|
setTabOrder(_first, _last);
|
|
|
|
}
|
2017-05-30 13:54:05 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void SignupWidget::resizeEvent(QResizeEvent *e) {
|
|
|
|
Step::resizeEvent(e);
|
2017-05-30 13:54:05 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
2015-12-08 12:33:37 +00:00
|
|
|
|
2017-05-30 13:54:05 +00:00
|
|
|
void SignupWidget::updateControlsGeometry() {
|
2016-11-24 19:28:23 +00:00
|
|
|
auto photoRight = contentLeft() + st::introNextButton.width;
|
|
|
|
auto photoTop = contentTop() + st::introPhotoTop;
|
|
|
|
_photo->moveToLeft(photoRight - _photo->width(), photoTop);
|
2015-12-08 12:33:37 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
auto firstTop = contentTop() + st::introStepFieldTop;
|
2016-12-09 18:56:01 +00:00
|
|
|
auto secondTop = firstTop + st::introName.heightMin + st::introPhoneTop;
|
2016-11-24 19:28:23 +00:00
|
|
|
if (_invertOrder) {
|
|
|
|
_last->moveToLeft(contentLeft(), firstTop);
|
|
|
|
_first->moveToLeft(contentLeft(), secondTop);
|
2015-12-08 12:33:37 +00:00
|
|
|
} else {
|
2016-11-24 19:28:23 +00:00
|
|
|
_first->moveToLeft(contentLeft(), firstTop);
|
|
|
|
_last->moveToLeft(contentLeft(), secondTop);
|
2015-12-08 12:33:37 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void SignupWidget::setInnerFocus() {
|
|
|
|
if (_invertOrder || _last->hasFocus()) {
|
2016-12-23 13:21:01 +00:00
|
|
|
_last->setFocusFast();
|
2015-09-23 17:43:08 +00:00
|
|
|
} else {
|
2016-12-23 13:21:01 +00:00
|
|
|
_first->setFocusFast();
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void SignupWidget::activate() {
|
|
|
|
Step::activate();
|
|
|
|
_first->show();
|
|
|
|
_last->show();
|
|
|
|
_photo->show();
|
|
|
|
setInnerFocus();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void SignupWidget::cancelled() {
|
|
|
|
MTP::cancel(base::take(_sentRequest));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SignupWidget::nameSubmitDone(const MTPauth_Authorization &result) {
|
2016-12-09 18:56:01 +00:00
|
|
|
auto &d = result.c_auth_authorization();
|
2019-07-05 13:38:38 +00:00
|
|
|
if (d.vuser().type() != mtpc_user || !d.vuser().c_user().is_self()) { // wtf?
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(rpl::single(Lang::Hard::ServerError()));
|
2014-05-30 08:53:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
finish(d.vuser(), _photo->takeResultImage());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
bool SignupWidget::nameSubmitFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isFloodError(error)) {
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(tr::lng_flood_error());
|
2016-04-08 10:44:35 +00:00
|
|
|
if (_invertOrder) {
|
2016-11-04 19:50:35 +00:00
|
|
|
_first->setFocus();
|
2016-04-08 10:44:35 +00:00
|
|
|
} else {
|
2016-11-04 19:50:35 +00:00
|
|
|
_last->setFocus();
|
2016-04-08 10:44:35 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
|
|
|
|
2016-12-09 18:56:01 +00:00
|
|
|
auto &err = error.type();
|
2016-12-30 13:53:51 +00:00
|
|
|
if (err == qstr("PHONE_NUMBER_FLOOD")) {
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::show(Box<InformBox>(tr::lng_error_phone_flood(tr::now)));
|
2016-12-30 13:53:51 +00:00
|
|
|
return true;
|
2019-06-05 17:43:21 +00:00
|
|
|
} else if (err == qstr("PHONE_NUMBER_INVALID")
|
|
|
|
|| err == qstr("PHONE_NUMBER_BANNED")
|
|
|
|
|| err == qstr("PHONE_CODE_EXPIRED")
|
|
|
|
|| err == qstr("PHONE_CODE_EMPTY")
|
|
|
|
|| err == qstr("PHONE_CODE_INVALID")
|
|
|
|
|| err == qstr("PHONE_NUMBER_OCCUPIED")) {
|
2016-11-24 19:28:23 +00:00
|
|
|
goBack();
|
2014-05-30 08:53:19 +00:00
|
|
|
return true;
|
|
|
|
} else if (err == "FIRSTNAME_INVALID") {
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(tr::lng_bad_name());
|
2016-11-04 19:50:35 +00:00
|
|
|
_first->setFocus();
|
2014-05-30 08:53:19 +00:00
|
|
|
return true;
|
|
|
|
} else if (err == "LASTNAME_INVALID") {
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(tr::lng_bad_name());
|
2016-11-04 19:50:35 +00:00
|
|
|
_last->setFocus();
|
2014-05-30 08:53:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-06-05 13:32:26 +00:00
|
|
|
if (Logs::DebugEnabled()) { // internal server error
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(rpl::single(err + ": " + error.description()));
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2019-06-18 16:53:27 +00:00
|
|
|
showError(rpl::single(Lang::Hard::ServerError()));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-09-23 17:43:08 +00:00
|
|
|
if (_invertOrder) {
|
2016-11-04 19:50:35 +00:00
|
|
|
_last->setFocus();
|
2015-09-23 17:43:08 +00:00
|
|
|
} else {
|
2016-11-04 19:50:35 +00:00
|
|
|
_first->setFocus();
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void SignupWidget::submit() {
|
2018-06-01 07:00:18 +00:00
|
|
|
if (_sentRequest) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-23 17:43:08 +00:00
|
|
|
if (_invertOrder) {
|
2016-11-24 19:28:23 +00:00
|
|
|
if ((_last->hasFocus() || _last->getLastText().trimmed().length()) && !_first->getLastText().trimmed().length()) {
|
2016-11-04 19:50:35 +00:00
|
|
|
_first->setFocus();
|
2015-09-23 17:43:08 +00:00
|
|
|
return;
|
2016-11-24 19:28:23 +00:00
|
|
|
} else if (!_last->getLastText().trimmed().length()) {
|
2016-11-04 19:50:35 +00:00
|
|
|
_last->setFocus();
|
2015-09-23 17:43:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2016-11-24 19:28:23 +00:00
|
|
|
if ((_first->hasFocus() || _first->getLastText().trimmed().length()) && !_last->getLastText().trimmed().length()) {
|
2016-11-04 19:50:35 +00:00
|
|
|
_last->setFocus();
|
2015-09-23 17:43:08 +00:00
|
|
|
return;
|
2016-11-24 19:28:23 +00:00
|
|
|
} else if (!_first->getLastText().trimmed().length()) {
|
2016-11-04 19:50:35 +00:00
|
|
|
_first->setFocus();
|
2015-09-23 17:43:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2018-06-01 07:00:18 +00:00
|
|
|
const auto send = [&] {
|
|
|
|
hideError();
|
|
|
|
|
|
|
|
_firstName = _first->getLastText().trimmed();
|
|
|
|
_lastName = _last->getLastText().trimmed();
|
|
|
|
_sentRequest = MTP::send(
|
|
|
|
MTPauth_SignUp(
|
|
|
|
MTP_string(getData()->phone),
|
|
|
|
MTP_bytes(getData()->phoneHash),
|
|
|
|
MTP_string(_firstName),
|
|
|
|
MTP_string(_lastName)),
|
|
|
|
rpcDone(&SignupWidget::nameSubmitDone),
|
|
|
|
rpcFail(&SignupWidget::nameSubmitFail));
|
|
|
|
};
|
|
|
|
if (_termsAccepted
|
2018-06-03 13:30:40 +00:00
|
|
|
|| getData()->termsLock.text.text.isEmpty()
|
|
|
|
|| !getData()->termsLock.popup) {
|
2018-06-01 07:00:18 +00:00
|
|
|
send();
|
|
|
|
} else {
|
2018-06-04 15:35:11 +00:00
|
|
|
acceptTerms(crl::guard(this, [=] {
|
2018-06-01 07:00:18 +00:00
|
|
|
_termsAccepted = true;
|
|
|
|
send();
|
|
|
|
}));
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
rpl::producer<QString> SignupWidget::nextButtonText() const {
|
|
|
|
return tr::lng_intro_finish();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2019-11-26 11:10:44 +00:00
|
|
|
} // namespace details
|
2016-11-24 19:28:23 +00:00
|
|
|
} // namespace Intro
|