Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Fixed signup field validation (linux)
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrekV committed Jun 1, 2018
1 parent 8333adb commit 9f6b486
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
26 changes: 14 additions & 12 deletions src/ui/linux/TogglDesktop/loginwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void LoginWidget::displayTimeEntryList(
}

void LoginWidget::on_login_clicked() {
if (!validateFields()) {
if (!validateFields(false)) {
return;
}
TogglApi::instance->login(ui->email->text(), ui->password->text());
Expand All @@ -94,7 +94,7 @@ void LoginWidget::loginDone() {
TogglApi::instance->googleLogin(oauth2->accessToken());
}

bool LoginWidget::validateFields() {
bool LoginWidget::validateFields(const bool signup) {
if (ui->email->text().isEmpty()) {
ui->email->setFocus();
TogglApi::instance->displayError(QString("Please enter valid email address"), true);
Expand All @@ -105,21 +105,23 @@ bool LoginWidget::validateFields() {
TogglApi::instance->displayError(QString("A password is required"), true);
return false;
}
if (selectedCountryId == -1) {
ui->countryComboBox->setFocus();
TogglApi::instance->displayError(QString("Please select Country before signing up"), true);
return false;
}
if (ui->tosCheckBox->checkState() == Qt::Unchecked) {
ui->tosCheckBox->setFocus();
TogglApi::instance->displayError(QString("You must agree to the terms of service and privacy policy to use Toggl"), true);
return false;
if (signup) {
if (selectedCountryId == -1) {
ui->countryComboBox->setFocus();
TogglApi::instance->displayError(QString("Please select Country before signing up"), true);
return false;
}
if (ui->tosCheckBox->checkState() == Qt::Unchecked) {
ui->tosCheckBox->setFocus();
TogglApi::instance->displayError(QString("You must agree to the terms of service and privacy policy to use Toggl"), true);
return false;
}
}
return true;
}

void LoginWidget::on_signup_clicked() {
if (!validateFields()) {
if (!validateFields(true)) {
return;
}
TogglApi::instance->signup(ui->email->text(), ui->password->text());
Expand Down
3 changes: 2 additions & 1 deletion src/ui/linux/TogglDesktop/loginwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class LoginWidget : public QWidget {
void on_googleLogin_linkActivated(const QString &link);

void loginDone();
bool validateFields();
bool validateFields(
const bool signup);

void on_signup_clicked();

Expand Down

0 comments on commit 9f6b486

Please sign in to comment.