handling incorrect captcha and check not found cases
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "./ui_mainwindow.h"
|
||||
#include "check/check.h"
|
||||
#include "exceptions/ofdrequestexception.h"
|
||||
#include "goods/goods.h"
|
||||
#include "outputdialog.h"
|
||||
#include "adjustpicturedialog.h"
|
||||
@@ -63,9 +64,6 @@ std::string MainWindow::makeRequestToOfd(std::string captcha) {
|
||||
|
||||
void MainWindow::receiveSolvedCaptcha(std::string captcha) {
|
||||
|
||||
std::string check_content = makeRequestToOfd(captcha);
|
||||
|
||||
check = parseOfdRuAnswer(check_content);
|
||||
}
|
||||
|
||||
void MainWindow::on_parseButton_clicked() {
|
||||
@@ -79,13 +77,46 @@ void MainWindow::on_parseButton_clicked() {
|
||||
break;
|
||||
case 2:
|
||||
Net().get_captcha_from_ofdru();
|
||||
SolveCaptchaDialog dialog = SolveCaptchaDialog(this);
|
||||
connect(&dialog, &SolveCaptchaDialog::solvedCaptcha, this, &MainWindow::receiveSolvedCaptcha);
|
||||
dialog.exec();
|
||||
|
||||
OutputDialog d = OutputDialog(this, check);
|
||||
d.show();
|
||||
d.exec();
|
||||
std::string solved_captcha = "";
|
||||
bool success = true;
|
||||
bool is_captcha_solved = true;
|
||||
|
||||
do {
|
||||
SolveCaptchaDialog dialog = SolveCaptchaDialog(this, &solved_captcha);
|
||||
connect(&dialog, &SolveCaptchaDialog::solvedCaptcha, this, &MainWindow::receiveSolvedCaptcha);
|
||||
dialog.exec();
|
||||
is_captcha_solved = true;
|
||||
|
||||
try {
|
||||
std::string check_content = makeRequestToOfd(solved_captcha);
|
||||
check = parseOfdRuAnswer(check_content);
|
||||
} catch(OfdRequestException e) {
|
||||
success = false;
|
||||
if (!strcmp(e.what(), "Incorrect captcha")) {
|
||||
is_captcha_solved = false;
|
||||
QMessageBox infoDialog;
|
||||
infoDialog.setText("Captcha was not solved correctly!");
|
||||
infoDialog.setIcon(QMessageBox::Critical);
|
||||
infoDialog.setWindowTitle("Captcha is incorrect");
|
||||
infoDialog.exec();
|
||||
break;
|
||||
} else if (!strcmp(e.what(), "Does not exist")) {
|
||||
QMessageBox infoDialog;
|
||||
infoDialog.setText("Check not found. Please, ensure correctness of entered data.");
|
||||
infoDialog.setIcon(QMessageBox::Critical);
|
||||
infoDialog.setWindowTitle("Check was not found");
|
||||
infoDialog.exec();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} while (!is_captcha_solved);
|
||||
|
||||
if (success) {
|
||||
OutputDialog d = OutputDialog(this, check);
|
||||
d.exec();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user