jce-manager/main/loginhandler.cpp

134 lines
3.2 KiB
C++
Raw Normal View History

2014-06-18 23:44:46 +00:00
#include "loginhandler.h"
2014-06-20 02:59:33 +00:00
loginHandler::loginHandler(user *ptr): logggedInFlag(false)
2014-06-18 23:44:46 +00:00
{
2014-06-20 02:59:33 +00:00
this->jceLog = new jceLogin(ptr);
2014-06-18 23:44:46 +00:00
}
2014-06-20 02:59:33 +00:00
void loginHandler::setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr)
2014-06-18 23:44:46 +00:00
{
2014-06-20 02:59:33 +00:00
2014-06-18 23:44:46 +00:00
this->statusLabelPtr = statusLabelPtr;
this->pswdEditPtr = pswdEditPtr;
this->usrnmEditPtr = usrnmEditPtr;
}
bool loginHandler::makeConnection()
{
if (this->jceLog == NULL)
return false;
try
{
jceLog->makeConnection();
}
catch (jceLogin::jceStatus &a)
{
int status = (int)a;
switch (status)
{
case jceLogin::JCE_YOU_ARE_IN:
2014-06-18 23:44:46 +00:00
{
2014-06-20 02:59:33 +00:00
logggedInFlag = true;
return logggedInFlag;
break;
2014-06-18 23:44:46 +00:00
}
case jceLogin::ERROR_ON_VALIDATION:
2014-06-18 23:44:46 +00:00
{
popMessage("Please Check Your Username & Password",false);
2014-06-18 23:44:46 +00:00
usrnmEditPtr->setDisabled(false);
pswdEditPtr->setDisabled(false);
pswdEditPtr->selectAll();
pswdEditPtr->setFocus();
return false;
}
case jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED:
2014-06-18 23:44:46 +00:00
{
popMessage("You have been blocked by JCE, please try in a couple of minutes.");
2014-06-18 23:44:46 +00:00
jceLog->closeAll();
return false;
}
case jceLogin::ERROR_ON_OPEN_SOCKET:
2014-06-18 23:44:46 +00:00
{
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.");
2014-06-18 23:44:46 +00:00
jceLog->closeAll();
return false;
break;
}
2014-06-18 23:44:46 +00:00
}
}
return false;
}
2014-06-20 02:59:33 +00:00
2014-06-20 17:13:21 +00:00
2014-06-20 02:59:33 +00:00
bool loginHandler::isLoggedInFlag()
{
return this->logggedInFlag;
}
void loginHandler::setLoginFlag(bool flag)
{
this->logggedInFlag = flag;
}
QString loginHandler::getCurrentPageContect()
{
QTextEdit phrase;
if (isLoggedInFlag())
phrase.setText(QString::fromStdString(jceLog->getPage()));
else
throw jceLogin::ERROR_ON_GETTING_INFO;
return phrase.toPlainText();
}
void loginHandler::makeDisconnectionRequest()
{
jceLog->closeAll();
2014-06-26 15:15:04 +00:00
this->logggedInFlag = false;
2014-06-20 02:59:33 +00:00
}
int loginHandler::makeGradeRequest()
{
if (isLoggedInFlag())
return jceLog->getGrades();
else
return jceLogin::JCE_NOT_CONNECTED;
}
void loginHandler::popMessage(QString message,bool addInfo)
2014-06-18 23:44:46 +00:00
{
if (addInfo)
message.append("\nIf this message appear without reason, please contact me at liranbg@gmail.com");
2014-06-18 23:44:46 +00:00
QMessageBox msgBox;
msgBox.setWindowTitle("Error");
msgBox.setText(message);
msgBox.exec();
msgBox.setFocus();
2014-06-18 23:44:46 +00:00
}