2014-09-08 15:54:52 +00:00
|
|
|
#include "loginhandler.h"
|
|
|
|
|
2014-10-12 19:19:43 +00:00
|
|
|
loginHandler::loginHandler(user *ptr, QPushButton *loginButtonPtr, jceStatusBar *progressbarPtr): logggedInFlag(false)
|
2014-09-08 15:54:52 +00:00
|
|
|
{
|
2014-09-22 02:04:38 +00:00
|
|
|
this->loginButtonPtr = loginButtonPtr;
|
2014-10-12 19:19:43 +00:00
|
|
|
this->statusBar = progressbarPtr;
|
2014-09-22 02:04:38 +00:00
|
|
|
|
2014-10-04 00:54:27 +00:00
|
|
|
|
|
|
|
|
2014-10-12 19:19:43 +00:00
|
|
|
statusBar->setIconConnectionStatus(jceStatusBar::Disconnected);
|
2014-09-22 02:04:38 +00:00
|
|
|
|
|
|
|
//user settings
|
|
|
|
userPtr = ptr;
|
2014-10-12 19:19:43 +00:00
|
|
|
this->jceLog = new jceLogin(userPtr,statusBar);
|
2014-09-22 02:04:38 +00:00
|
|
|
QObject::connect(this->jceLog,SIGNAL(connectionReadyAfterDisconnection()),this,SLOT(readyAfterConnectionLost()));
|
2014-10-04 00:54:27 +00:00
|
|
|
|
2014-09-08 15:54:52 +00:00
|
|
|
}
|
2014-09-22 02:04:38 +00:00
|
|
|
bool loginHandler::login(QString username,QString password)
|
2014-09-08 15:54:52 +00:00
|
|
|
{
|
2014-09-22 22:17:05 +00:00
|
|
|
qDebug() << Q_FUNC_INFO << "logging in with username and password";
|
2014-09-22 02:04:38 +00:00
|
|
|
if (isLoggedInFlag())
|
|
|
|
{
|
2014-09-22 22:17:05 +00:00
|
|
|
qDebug() << Q_FUNC_INFO << "we are already connected. Logging out and return false";
|
2014-09-22 02:04:38 +00:00
|
|
|
logout();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
userPtr->setUsername(username);
|
|
|
|
userPtr->setPassword(password);
|
|
|
|
|
|
|
|
if (makeConnection() == true)
|
|
|
|
{
|
|
|
|
loginButtonPtr->setText(QObject::tr("Logout"));
|
|
|
|
return isLoggedInFlag();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-12 22:14:26 +00:00
|
|
|
|
2014-09-22 02:04:38 +00:00
|
|
|
logout();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void loginHandler::logout()
|
|
|
|
{
|
|
|
|
loginButtonPtr->setText(QObject::tr("Login"));
|
2014-10-12 19:19:43 +00:00
|
|
|
statusBar->setIconConnectionStatus(jceStatusBar::Disconnected);
|
2014-09-22 02:04:38 +00:00
|
|
|
jceLog->closeAll();
|
|
|
|
logggedInFlag = false;
|
2014-09-08 15:54:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool loginHandler::makeConnection()
|
|
|
|
{
|
2014-09-22 02:04:38 +00:00
|
|
|
if (this->jceLog == NULL)
|
|
|
|
return false;
|
2014-09-17 01:08:38 +00:00
|
|
|
|
2014-09-22 02:04:38 +00:00
|
|
|
int status = (int)jceLog->makeConnection();
|
2014-09-17 01:08:38 +00:00
|
|
|
switch (status)
|
2014-09-22 02:04:38 +00:00
|
|
|
{
|
|
|
|
case jceLogin::JCE_YOU_ARE_IN:
|
|
|
|
{
|
|
|
|
logggedInFlag = true;
|
|
|
|
return logggedInFlag;
|
|
|
|
}
|
|
|
|
case jceLogin::ERROR_ON_VALIDATION:
|
|
|
|
{
|
|
|
|
popMessage(QObject::tr("Please Check Your Username & Password"),false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED:
|
|
|
|
{
|
2014-09-23 02:57:35 +00:00
|
|
|
popMessage(QObject::tr("You have been <b>BLOCKED</b> by JCE, please try in a couple of minutes."));
|
2014-09-22 02:04:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case jceLogin::ERROR_ON_OPEN_SOCKET:
|
|
|
|
{
|
|
|
|
popMessage(QObject::tr("Please Check Your Internet Connection."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case jceLogin::JCE_NOT_CONNECTED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case jceLogin::ERROR_ON_GETTING_INFO:
|
|
|
|
{
|
|
|
|
popMessage(QObject::tr("Receive Request Timeout."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case jceLogin::ERROR_ON_SEND_REQUEST:
|
|
|
|
{
|
|
|
|
popMessage(QObject::tr("Send Request Timeout."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-09-08 15:54:52 +00:00
|
|
|
}
|
|
|
|
|
2014-09-22 02:04:38 +00:00
|
|
|
void loginHandler::readyAfterConnectionLost()
|
|
|
|
{
|
|
|
|
qWarning() << Q_FUNC_INFO;
|
|
|
|
setLoginFlag(false);
|
2014-10-12 22:14:26 +00:00
|
|
|
statusBar->setIconConnectionStatus(jceStatusBar::Disconnected);
|
2014-09-22 02:04:38 +00:00
|
|
|
login(userPtr->getUsername(),userPtr->getPassword());
|
2014-09-08 15:54:52 +00:00
|
|
|
|
2014-09-22 02:04:38 +00:00
|
|
|
}
|
2014-09-08 15:54:52 +00:00
|
|
|
bool loginHandler::isLoggedInFlag()
|
|
|
|
{
|
2014-09-22 02:04:38 +00:00
|
|
|
if (jceLog->isLoginFlag()) //checking connection and then if logged in
|
|
|
|
return this->logggedInFlag;
|
|
|
|
else
|
|
|
|
this->setLoginFlag(false);
|
|
|
|
return false;
|
2014-09-08 15:54:52 +00:00
|
|
|
}
|
|
|
|
void loginHandler::setLoginFlag(bool flag)
|
|
|
|
{
|
2014-09-22 02:04:38 +00:00
|
|
|
this->logggedInFlag = flag;
|
2014-09-08 15:54:52 +00:00
|
|
|
}
|
|
|
|
QString loginHandler::getCurrentPageContect()
|
|
|
|
{
|
2014-10-05 12:33:57 +00:00
|
|
|
QTextEdit parse;
|
2014-09-22 02:04:38 +00:00
|
|
|
if (isLoggedInFlag())
|
2014-10-05 12:33:57 +00:00
|
|
|
parse.setText(jceLog->getPage());
|
2014-09-22 02:04:38 +00:00
|
|
|
else
|
2014-10-12 02:52:07 +00:00
|
|
|
return "";
|
2014-10-05 12:33:57 +00:00
|
|
|
return parse.toPlainText();
|
2014-09-08 15:54:52 +00:00
|
|
|
}
|
|
|
|
int loginHandler::makeGradeRequest(int fromYear, int toYear, int fromSemester, int toSemester)
|
|
|
|
{
|
2014-09-22 02:04:38 +00:00
|
|
|
if (isLoggedInFlag())
|
2014-10-12 22:14:26 +00:00
|
|
|
{
|
|
|
|
statusBar->setIconConnectionStatus(jceStatusBar::Sending);
|
2014-09-22 02:04:38 +00:00
|
|
|
return jceLog->getGrades(fromYear, toYear, fromSemester, toSemester);
|
2014-10-12 22:14:26 +00:00
|
|
|
}
|
2014-09-22 02:04:38 +00:00
|
|
|
else
|
|
|
|
return jceLogin::JCE_NOT_CONNECTED;
|
2014-09-08 15:54:52 +00:00
|
|
|
}
|
|
|
|
int loginHandler::makeCalendarRequest(int year, int semester)
|
|
|
|
{
|
2014-09-22 02:04:38 +00:00
|
|
|
if (isLoggedInFlag())
|
2014-10-12 22:14:26 +00:00
|
|
|
{
|
|
|
|
statusBar->setIconConnectionStatus(jceStatusBar::Sending);
|
2014-09-22 02:04:38 +00:00
|
|
|
return jceLog->getCalendar(year,semester);
|
2014-10-12 22:14:26 +00:00
|
|
|
}
|
2014-09-22 02:04:38 +00:00
|
|
|
else
|
|
|
|
return jceLogin::JCE_NOT_CONNECTED;
|
|
|
|
}
|
2014-10-08 04:14:50 +00:00
|
|
|
int loginHandler::makeExamsScheduleRequest(int year, int semester)
|
|
|
|
{
|
2014-10-12 22:14:26 +00:00
|
|
|
|
2014-10-08 04:14:50 +00:00
|
|
|
if (isLoggedInFlag())
|
2014-10-12 22:14:26 +00:00
|
|
|
{
|
|
|
|
statusBar->setIconConnectionStatus(jceStatusBar::Sending);
|
2014-10-08 04:14:50 +00:00
|
|
|
return jceLog->getExams(year,semester);
|
2014-10-12 22:14:26 +00:00
|
|
|
}
|
2014-10-08 04:14:50 +00:00
|
|
|
else
|
|
|
|
return jceLogin::JCE_NOT_CONNECTED;
|
|
|
|
}
|
2014-09-22 02:04:38 +00:00
|
|
|
|
2014-09-08 15:54:52 +00:00
|
|
|
void loginHandler::popMessage(QString message,bool addInfo)
|
|
|
|
{
|
2014-09-22 02:04:38 +00:00
|
|
|
if (addInfo)
|
|
|
|
message.append(QObject::tr("\nIf this message appear without reason, please contact me at liranbg@gmail.com"));
|
|
|
|
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle(QObject::tr("Error"));
|
|
|
|
msgBox.setText(message);
|
|
|
|
msgBox.exec();
|
|
|
|
msgBox.setFocus();
|
2014-09-08 15:54:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|