changes the exceptions handling but has to improve
This commit is contained in:
parent
1980efe130
commit
c1d736ce02
5 changed files with 96 additions and 37 deletions
|
@ -23,14 +23,17 @@ bool loginHandler::makeConnection()
|
||||||
}
|
}
|
||||||
catch (jceLogin::jceStatus &a)
|
catch (jceLogin::jceStatus &a)
|
||||||
{
|
{
|
||||||
|
int status = (int)a;
|
||||||
if (a == jceLogin::JCE_YOU_ARE_IN)
|
switch (status)
|
||||||
|
{
|
||||||
|
case jceLogin::JCE_YOU_ARE_IN:
|
||||||
{
|
{
|
||||||
return true;
|
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);
|
usrnmEditPtr->setDisabled(false);
|
||||||
pswdEditPtr->setDisabled(false);
|
pswdEditPtr->setDisabled(false);
|
||||||
|
@ -39,29 +42,55 @@ bool loginHandler::makeConnection()
|
||||||
pswdEditPtr->setFocus();
|
pswdEditPtr->setFocus();
|
||||||
return false;
|
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();
|
jceLog->closeAll();
|
||||||
return false;
|
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();
|
jceLog->closeAll();
|
||||||
|
|
||||||
return false;
|
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;
|
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;
|
QMessageBox msgBox;
|
||||||
msgBox.setWindowTitle("Error");
|
msgBox.setWindowTitle("Error");
|
||||||
msgBox.setText(message);
|
msgBox.setText(message);
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
msgBox.setFocus();
|
msgBox.setFocus();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void popMessage(QString message);
|
void popMessage(QString message, bool addInfo = true);
|
||||||
|
|
||||||
|
|
||||||
jceLogin *jceLog;
|
jceLogin *jceLog;
|
||||||
|
|
|
@ -58,13 +58,21 @@ void MainScreen::on_ratesButton_clicked()
|
||||||
std::string pageString;
|
std::string pageString;
|
||||||
if (this->jceLog != NULL)
|
if (this->jceLog != NULL)
|
||||||
{
|
{
|
||||||
if (jceLog->getGrades())
|
if (jceLog->isLoginFlag() == true)
|
||||||
|
{
|
||||||
|
if (jceLog->getGrades() == jceLogin::JCE_GRADE_PAGE_PASSED)
|
||||||
{
|
{
|
||||||
phrase.setText(QString::fromStdString(jceLog->getPage()));
|
phrase.setText(QString::fromStdString(jceLog->getPage()));
|
||||||
pageString = phrase.toPlainText().toStdString();
|
pageString = phrase.toPlainText().toStdString();
|
||||||
courseTableMgr->setCoursesList(pageString);
|
courseTableMgr->setCoursesList(pageString);
|
||||||
courseTableMgr->insertJceCoursesIntoTable();
|
courseTableMgr->insertJceCoursesIntoTable();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,21 +24,34 @@ void jceLogin::makeConnection() throw (jceStatus)
|
||||||
if (JceConnector->makeConnect(dst_host,dst_port) == false)
|
if (JceConnector->makeConnect(dst_host,dst_port) == false)
|
||||||
throw jceStatus::ERROR_ON_OPEN_SOCKET;
|
throw jceStatus::ERROR_ON_OPEN_SOCKET;
|
||||||
|
|
||||||
|
int returnMode;
|
||||||
jceStatus status = jceStatus::JCE_NOT_CONNECTED;
|
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;
|
status = jceStatus::JCE_START_VALIDATING_PROGRESS;
|
||||||
if (checkValidation() == true) //check if username and password are matching
|
returnMode = checkValidation();
|
||||||
|
if (returnMode == true) //check if username and password are matching
|
||||||
{
|
{
|
||||||
status = jceStatus::JCE_SECOND_VALIDATION_PASSED;
|
status = jceStatus::JCE_VALIDATION_PASSED;
|
||||||
if (makeSecondVisit() == true) //siging in the website
|
returnMode = makeSecondVisit();
|
||||||
|
if (returnMode == true) //siging in the website
|
||||||
{
|
{
|
||||||
status = jceStatus::JCE_YOU_ARE_IN;
|
status = jceStatus::JCE_YOU_ARE_IN;
|
||||||
setLoginFlag(true);
|
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
|
else
|
||||||
status = jceStatus::ERROR_ON_VALIDATION;
|
status = jceStatus::ERROR_ON_VALIDATION;
|
||||||
}
|
}
|
||||||
|
@ -46,12 +59,20 @@ void jceLogin::makeConnection() throw (jceStatus)
|
||||||
status = jceStatus::ERROR_ON_VALIDATION;
|
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
|
else
|
||||||
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
|
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status = jceStatus::ERROR_ON_OPEN_SOCKET;
|
status = jceStatus::JCE_NOT_CONNECTED;
|
||||||
|
|
||||||
//we throw status even if we are IN!
|
//we throw status even if we are IN!
|
||||||
throw status;
|
throw status;
|
||||||
|
@ -129,8 +150,8 @@ int jceLogin::getGrades()
|
||||||
{
|
{
|
||||||
if (!(JceConnector->recieve(*recieverPage)))
|
if (!(JceConnector->recieve(*recieverPage)))
|
||||||
return jceLogin::ERROR_ON_GETTING_GRADES;
|
return jceLogin::ERROR_ON_GETTING_GRADES;
|
||||||
|
else
|
||||||
return true;
|
return jceLogin::JCE_GRADE_PAGE_PASSED;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||||
|
@ -160,14 +181,17 @@ std::string jceLogin::getPage()
|
||||||
bool jceLogin::checkValidation()
|
bool jceLogin::checkValidation()
|
||||||
{
|
{
|
||||||
//finds the hashed password
|
//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;
|
hasspass_position1 += 5;
|
||||||
std::size_t hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1);
|
if ((hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1)) == string::npos)
|
||||||
if ((hasspass_position2 != std::string::npos) && (hasspass_position1 != std::string::npos))
|
return false;
|
||||||
{
|
|
||||||
std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1);
|
std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1);
|
||||||
jceA->setHashedPassword(hasspass);
|
jceA->setHashedPassword(hasspass);
|
||||||
}
|
|
||||||
//finds the user id
|
//finds the user id
|
||||||
std::size_t id_position1 = recieverPage->find("value=\"-N", 0);
|
std::size_t id_position1 = recieverPage->find("value=\"-N", 0);
|
||||||
id_position1 += 9;
|
id_position1 += 9;
|
||||||
|
|
|
@ -19,15 +19,13 @@ public:
|
||||||
JCE_NOT_CONNECTED,
|
JCE_NOT_CONNECTED,
|
||||||
ERROR_ON_VALIDATION,
|
ERROR_ON_VALIDATION,
|
||||||
ERROR_ON_VALIDATION_USER_BLOCKED,
|
ERROR_ON_VALIDATION_USER_BLOCKED,
|
||||||
ERROR_ON_INPUT,
|
|
||||||
ERROR_ON_CONNECTING,
|
|
||||||
ERROR_ON_OPEN_SOCKET,
|
ERROR_ON_OPEN_SOCKET,
|
||||||
|
ERROR_ON_SEND_REQUEST,
|
||||||
ERROR_ON_GETTING_INFO,
|
ERROR_ON_GETTING_INFO,
|
||||||
ERROR_ON_GETTING_GRADES,
|
ERROR_ON_GETTING_GRADES,
|
||||||
ERROR_ON_SEND_REQUEST,
|
|
||||||
JCE_START_VALIDATING_PROGRESS,
|
JCE_START_VALIDATING_PROGRESS,
|
||||||
JCE_FIRST_VALIDATION_PASSED,
|
JCE_VALIDATION_PASSED,
|
||||||
JCE_SECOND_VALIDATION_PASSED,
|
|
||||||
JCE_YOU_ARE_IN,
|
JCE_YOU_ARE_IN,
|
||||||
JCE_GRADE_PAGE_PASSED
|
JCE_GRADE_PAGE_PASSED
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue