2014-09-08 15:54:52 +00:00
|
|
|
#include "loginhandler.h"
|
|
|
|
|
2014-10-04 00:54:27 +00:00
|
|
|
loginHandler::loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr,QProgressBar *progressbarPtr): logggedInFlag(false)
|
2014-09-08 15:54:52 +00:00
|
|
|
{
|
2014-09-22 02:04:38 +00:00
|
|
|
this->loginButtonPtr = loginButtonPtr;
|
2014-10-04 00:54:27 +00:00
|
|
|
this->progressBar = progressbarPtr;
|
2014-09-22 02:04:38 +00:00
|
|
|
|
|
|
|
//statusBar
|
|
|
|
statusBar = statusBarPtr;
|
2014-10-04 00:54:27 +00:00
|
|
|
iconButtomStatusLabel = new QLabel(statusBarPtr);
|
|
|
|
iconButtomStatusLabel->setAlignment(Qt::AlignHCenter);
|
|
|
|
|
|
|
|
//display progressbar and then ball icon.
|
|
|
|
statusBar->addPermanentWidget(progressBar,0);
|
2014-09-22 02:04:38 +00:00
|
|
|
statusBar->addPermanentWidget(iconButtomStatusLabel,0);
|
2014-10-04 00:54:27 +00:00
|
|
|
|
2014-09-22 02:04:38 +00:00
|
|
|
setIconConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
|
|
|
|
|
|
|
|
//user settings
|
|
|
|
userPtr = ptr;
|
2014-10-04 00:54:27 +00:00
|
|
|
this->jceLog = new jceLogin(userPtr,progressBar);
|
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;
|
|
|
|
}
|
|
|
|
setIconConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS);
|
|
|
|
|
|
|
|
userPtr->setUsername(username);
|
|
|
|
userPtr->setPassword(password);
|
|
|
|
|
|
|
|
if (makeConnection() == true)
|
|
|
|
{
|
|
|
|
setIconConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN);
|
|
|
|
loginButtonPtr->setText(QObject::tr("Logout"));
|
|
|
|
return isLoggedInFlag();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
logout();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void loginHandler::logout()
|
|
|
|
{
|
|
|
|
loginButtonPtr->setText(QObject::tr("Login"));
|
|
|
|
setIconConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
|
|
|
|
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);
|
|
|
|
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
|
|
|
|
throw jceLogin::ERROR_ON_GETTING_INFO;
|
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())
|
|
|
|
return jceLog->getGrades(fromYear, toYear, fromSemester, toSemester);
|
|
|
|
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())
|
|
|
|
return jceLog->getCalendar(year,semester);
|
|
|
|
else
|
|
|
|
return jceLogin::JCE_NOT_CONNECTED;
|
|
|
|
}
|
2014-10-08 04:14:50 +00:00
|
|
|
|
|
|
|
int loginHandler::makeExamsScheduleRequest(int year, int semester)
|
|
|
|
{
|
|
|
|
if (isLoggedInFlag())
|
|
|
|
return jceLog->getExams(year,semester);
|
|
|
|
else
|
|
|
|
return jceLogin::JCE_NOT_CONNECTED;
|
|
|
|
}
|
2014-09-22 02:04:38 +00:00
|
|
|
void loginHandler::setIconConnectionStatus(jceLogin::jceStatus statusDescription)
|
|
|
|
{
|
|
|
|
QPixmap iconPix;
|
|
|
|
switch (statusDescription)
|
|
|
|
{
|
|
|
|
case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS:
|
|
|
|
iconPix.load(":/icons/blueStatusIcon.png");
|
|
|
|
statusBar->showMessage(tr("Connecting..."));
|
|
|
|
break;
|
|
|
|
case jceLogin::jceStatus::JCE_YOU_ARE_IN:
|
|
|
|
iconPix.load(":/icons/greenStatusIcon.png");
|
|
|
|
statusBar->showMessage(tr("Connected"));
|
|
|
|
break;
|
|
|
|
case jceLogin::jceStatus::JCE_NOT_CONNECTED:
|
|
|
|
iconPix.load(":/icons/redStatusIcon.png");
|
|
|
|
statusBar->showMessage(tr("Disconnected"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
iconPix.load(":/icons/redStatusIcon.png");
|
|
|
|
statusBar->showMessage(tr("Ready."));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
iconButtomStatusLabel->setPixmap(iconPix);
|
|
|
|
|
|
|
|
this->statusBar->repaint();
|
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
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|