From c1d736ce020214bb9eb57f7b9150829e75b32f7c Mon Sep 17 00:00:00 2001 From: liranbg Date: Thu, 19 Jun 2014 07:12:51 +0300 Subject: [PATCH] changes the exceptions handling but has to improve --- main/loginhandler.cpp | 49 +++++++++++++++++++++++++++++-------- main/loginhandler.h | 2 +- main/mainscreen.cpp | 18 ++++++++++---- src/jce/jcelogin.cpp | 56 ++++++++++++++++++++++++++++++------------- src/jce/jcelogin.h | 8 +++---- 5 files changed, 96 insertions(+), 37 deletions(-) diff --git a/main/loginhandler.cpp b/main/loginhandler.cpp index 4483d22..f2108c3 100644 --- a/main/loginhandler.cpp +++ b/main/loginhandler.cpp @@ -23,14 +23,17 @@ bool loginHandler::makeConnection() } catch (jceLogin::jceStatus &a) { - - if (a == jceLogin::JCE_YOU_ARE_IN) + int status = (int)a; + switch (status) + { + case jceLogin::JCE_YOU_ARE_IN: { return true; + break; } - else if (a == jceLogin::ERROR_ON_VALIDATION) + case jceLogin::ERROR_ON_VALIDATION: { - popMessage("check your password"); + popMessage("Please Check Your Username & Password",false); usrnmEditPtr->setDisabled(false); pswdEditPtr->setDisabled(false); @@ -39,29 +42,55 @@ bool loginHandler::makeConnection() pswdEditPtr->setFocus(); return false; } - else if (a == jceLogin::ERROR_ON_OPEN_SOCKET) + case jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED: { - popMessage("Please check your Internet status"); + popMessage("You have been blocked by JCE, please try in a couple of minutes."); jceLog->closeAll(); return false; } - else if (a == jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED) + case jceLogin::ERROR_ON_OPEN_SOCKET: { - popMessage("You were blocked, please wait couple of minutes or contact JCE"); + popMessage("Please Check Your Internet Connection."); jceLog->closeAll(); - return false; } + case jceLogin::JCE_NOT_CONNECTED: + { + jceLog->reConnect(); + /* + * Fix: need to add promte window to ask user whenever he wants to reconnect or not + */ + break; + } + case jceLogin::ERROR_ON_GETTING_INFO: + { + popMessage("Recieve Request Time Out."); + jceLog->closeAll(); + return false; + break; + } + case jceLogin::ERROR_ON_SEND_REQUEST: + { + popMessage("Send Request Time Out."); + jceLog->closeAll(); + return false; + break; + } + } } return false; } -void loginHandler::popMessage(QString message) +void loginHandler::popMessage(QString message,bool addInfo) { + if (addInfo) + message.append("\nIf this message appear without reason, please contact me at liranbg@gmail.com"); + QMessageBox msgBox; msgBox.setWindowTitle("Error"); msgBox.setText(message); msgBox.exec(); msgBox.setFocus(); + } diff --git a/main/loginhandler.h b/main/loginhandler.h index d60bcec..ba32f13 100644 --- a/main/loginhandler.h +++ b/main/loginhandler.h @@ -18,7 +18,7 @@ public: private: - void popMessage(QString message); + void popMessage(QString message, bool addInfo = true); jceLogin *jceLog; diff --git a/main/mainscreen.cpp b/main/mainscreen.cpp index 8689104..91c12f5 100644 --- a/main/mainscreen.cpp +++ b/main/mainscreen.cpp @@ -58,13 +58,21 @@ void MainScreen::on_ratesButton_clicked() std::string pageString; if (this->jceLog != NULL) { - if (jceLog->getGrades()) + if (jceLog->isLoginFlag() == true) { - phrase.setText(QString::fromStdString(jceLog->getPage())); - pageString = phrase.toPlainText().toStdString(); - courseTableMgr->setCoursesList(pageString); - courseTableMgr->insertJceCoursesIntoTable(); + if (jceLog->getGrades() == jceLogin::JCE_GRADE_PAGE_PASSED) + { + phrase.setText(QString::fromStdString(jceLog->getPage())); + pageString = phrase.toPlainText().toStdString(); + courseTableMgr->setCoursesList(pageString); + courseTableMgr->insertJceCoursesIntoTable(); + } + else + { + + } } + } } diff --git a/src/jce/jcelogin.cpp b/src/jce/jcelogin.cpp index 08eb1ae..53cfb2b 100644 --- a/src/jce/jcelogin.cpp +++ b/src/jce/jcelogin.cpp @@ -24,21 +24,34 @@ void jceLogin::makeConnection() throw (jceStatus) if (JceConnector->makeConnect(dst_host,dst_port) == false) throw jceStatus::ERROR_ON_OPEN_SOCKET; + int returnMode; jceStatus status = jceStatus::JCE_NOT_CONNECTED; - if (checkConnection() == true) //connected to host + returnMode = checkConnection(); + if (returnMode == true) //connected to host { - if (makeFirstVisit() == true) //requst and send first validation + returnMode = makeFirstVisit(); + if (returnMode == true) //requst and send first validation { - status = jceStatus::JCE_FIRST_VALIDATION_PASSED; - if (checkValidation() == true) //check if username and password are matching + status = jceStatus::JCE_START_VALIDATING_PROGRESS; + returnMode = checkValidation(); + if (returnMode == true) //check if username and password are matching { - status = jceStatus::JCE_SECOND_VALIDATION_PASSED; - if (makeSecondVisit() == true) //siging in the website + status = jceStatus::JCE_VALIDATION_PASSED; + returnMode = makeSecondVisit(); + if (returnMode == true) //siging in the website { status = jceStatus::JCE_YOU_ARE_IN; setLoginFlag(true); } + else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO) + { + status = jceLogin::ERROR_ON_GETTING_INFO; + } + else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST) + { + status = jceLogin::ERROR_ON_SEND_REQUEST; + } else status = jceStatus::ERROR_ON_VALIDATION; } @@ -46,12 +59,20 @@ void jceLogin::makeConnection() throw (jceStatus) status = jceStatus::ERROR_ON_VALIDATION; } + else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO) + { + status = jceLogin::ERROR_ON_GETTING_INFO; + } + else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST) + { + status = jceLogin::ERROR_ON_SEND_REQUEST; + } else status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED; } else - status = jceStatus::ERROR_ON_OPEN_SOCKET; + status = jceStatus::JCE_NOT_CONNECTED; //we throw status even if we are IN! throw status; @@ -129,8 +150,8 @@ int jceLogin::getGrades() { if (!(JceConnector->recieve(*recieverPage))) return jceLogin::ERROR_ON_GETTING_GRADES; - - return true; + else + return jceLogin::JCE_GRADE_PAGE_PASSED; } else return jceLogin::ERROR_ON_SEND_REQUEST; @@ -160,14 +181,17 @@ std::string jceLogin::getPage() bool jceLogin::checkValidation() { //finds the hashed password - std::size_t hasspass_position1 = recieverPage->find("-A,-N"); + std::size_t hasspass_position1,hasspass_position2; + + if ((hasspass_position1 = recieverPage->find("-A,-N")) == string::npos) + return false; hasspass_position1 += 5; - std::size_t hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1); - if ((hasspass_position2 != std::string::npos) && (hasspass_position1 != std::string::npos)) - { - std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1); - jceA->setHashedPassword(hasspass); - } + if ((hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1)) == string::npos) + return false; + + std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1); + jceA->setHashedPassword(hasspass); + //finds the user id std::size_t id_position1 = recieverPage->find("value=\"-N", 0); id_position1 += 9; diff --git a/src/jce/jcelogin.h b/src/jce/jcelogin.h index f9a9638..ff9468e 100644 --- a/src/jce/jcelogin.h +++ b/src/jce/jcelogin.h @@ -19,15 +19,13 @@ public: JCE_NOT_CONNECTED, ERROR_ON_VALIDATION, ERROR_ON_VALIDATION_USER_BLOCKED, - ERROR_ON_INPUT, - ERROR_ON_CONNECTING, ERROR_ON_OPEN_SOCKET, + ERROR_ON_SEND_REQUEST, ERROR_ON_GETTING_INFO, ERROR_ON_GETTING_GRADES, - ERROR_ON_SEND_REQUEST, + JCE_START_VALIDATING_PROGRESS, - JCE_FIRST_VALIDATION_PASSED, - JCE_SECOND_VALIDATION_PASSED, + JCE_VALIDATION_PASSED, JCE_YOU_ARE_IN, JCE_GRADE_PAGE_PASSED };