fixed bugs. ready to make graph feature

This commit is contained in:
Liran BN 2014-10-06 19:15:24 +03:00
parent fd612169d7
commit 72dfc10778
13 changed files with 411 additions and 1591 deletions

View file

@ -130,7 +130,6 @@ QString loginHandler::getCurrentPageContect()
parse.setText(jceLog->getPage());
else
throw jceLogin::ERROR_ON_GETTING_INFO;
return parse.toPlainText();
}
int loginHandler::makeGradeRequest(int fromYear, int toYear, int fromSemester, int toSemester)

View file

@ -2,7 +2,7 @@
#include "ui_mainscreen.h"
MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainScreen), busyFlag()
MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainScreen)
{
ui->setupUi(this);
@ -33,7 +33,6 @@ MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainSc
this->loginHandel = new loginHandler(userLoginSetting,ui->statusBar,ui->loginButton,ui->progressBar);
this->calendar = new CalendarManager(ui->calendarGridLayoutMain);
this->data = new SaveData();
busyFlag = false;
//check login File
if (data->isSaved())
@ -145,7 +144,7 @@ void MainScreen::on_ratesButton_clicked()
QString pageString;
int status = 0;
QApplication::setOverrideCursor(Qt::WaitCursor);
if (loginHandel->isLoggedInFlag() && !busyFlag)
if (loginHandel->isLoggedInFlag())
{
ui->statusBar->showMessage(tr("Getting grades..."));
if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(),
@ -170,7 +169,6 @@ void MainScreen::on_ratesButton_clicked()
{
qCritical() << Q_FUNC_INFO << "grade get ended with" << status;
}
busyFlag = true;
}
QApplication::restoreOverrideCursor();
}
@ -237,43 +235,34 @@ void MainScreen::on_graphButton_clicked()
//EVENTS ON CALENDAR TAB
void MainScreen::on_getCalendarBtn_clicked()
{
QString page;
calendar->resetTable();
page = ui->plainTextEdit->toPlainText();
calendar->setCalendar(page);
// ui->progressBar->setValue(0);
// qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
// int status = 0;
// QString page;
// QApplication::setOverrideCursor(Qt::WaitCursor);
// if (loginHandel->isLoggedInFlag())
// {
// ui->statusBar->showMessage(tr("Getting schedule..."));
// if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED)
// {
// //Use it for debug. add plain text and change the object name to 'plainTextEdit' so you will get the html request
// //ui->plainTextEdit->setPlainText(loginHandel->getCurrentPageContect());
// calendar->resetTable();
// ui->statusBar->showMessage(tr("Done. Inserting schdule into table..."),1000);
// page = loginHandel->getCurrentPageContect();
// calendar->setCalendar(page);
// ui->progressBar->setValue(100);
// qDebug() << Q_FUNC_INFO << "calendar is loaded";
// ui->statusBar->showMessage(tr("Done"));
// }
// else if (status == jceLogin::JCE_NOT_CONNECTED)
// {
// qWarning() << Q_FUNC_INFO << "not connected";
// QApplication::restoreOverrideCursor();
// QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
// }
// else
// qCritical() << Q_FUNC_INFO << "calendar get ended with" << status;
// }
// QApplication::restoreOverrideCursor();
ui->progressBar->setValue(0);
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
int status = 0;
QString page;
QApplication::setOverrideCursor(Qt::WaitCursor);
if (loginHandel->isLoggedInFlag())
{
ui->statusBar->showMessage(tr("Getting schedule..."));
if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED)
{
calendar->resetTable();
ui->statusBar->showMessage(tr("Done. Inserting schdule into table..."),1000);
page = loginHandel->getCurrentPageContect();
calendar->setCalendar(page);
ui->progressBar->setValue(100);
qDebug() << Q_FUNC_INFO << "calendar is loaded";
ui->statusBar->showMessage(tr("Done"));
}
else if (status == jceLogin::JCE_NOT_CONNECTED)
{
qWarning() << Q_FUNC_INFO << "not connected";
QApplication::restoreOverrideCursor();
QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
}
else
qCritical() << Q_FUNC_INFO << "calendar get ended with" << status;
}
QApplication::restoreOverrideCursor();
}
void MainScreen::on_exportToCVSBtn_clicked()
{

View file

@ -85,8 +85,6 @@ private:
coursesTableManager *courseTableMgr;
loginHandler *loginHandel;
bool busyFlag;
};
#endif // MAINSCREEN_H

File diff suppressed because it is too large Load diff

View file

@ -61,7 +61,7 @@ void CalendarDialog::on_calStart_selectionChanged()
void CalendarDialog::on_buttonBox_accepted()
{
if(this->isOK)
qDebug() << "CalendarDialog: Valid input";
qDebug() << Q_FUNC_INFO << "CalendarDialog: Valid input";
}
void CalendarDialog::on_calEnd_selectionChanged()

View file

@ -2,123 +2,108 @@
QString CalendarPage::htmlToString()
{
return tempHtml;
return tempHtml;
}
void CalendarPage::setPage(QString html)
{
qDebug() << "parsing calendar";
courses = new std::list<calendarCourse*>();
tempHtml = getString(html);
tempHtml = tokenToLines(tempHtml);
qDebug() << "creating courses list";
calendarListInit(tempHtml);
qDebug() << "done";
courses = new std::list<calendarCourse*>();
tempHtml = getString(html);
calendarListInit(tempHtml);
}
QString CalendarPage::tokenToLines(QString &textToParse)
{
int ctr = 0;
QString temp = "";
char *tok;
char* textToTok = strdup(textToParse.toStdString().c_str());
tok = strtok(textToTok, "\n");
while(tok != NULL)
{
//amount of data before the actual needed data and no empty lines
if (strcmp(tok," \t ") != 0)
{
temp += tok;
temp += "\n";
}
ctr++;
tok = strtok(NULL, "\n");
}
return temp;
}
void CalendarPage::calendarListInit(QString &linesTokinzedString)
{
std::list<QString> stringHolder;
QString temp;
calendarCourse * cTemp = NULL;
char* tok;
char* textToTok = strdup(linesTokinzedString.toStdString().c_str());
tok = strtok(textToTok,"\n");
while (tok != NULL)
std::list<QString> stringHolder;
QString temp;
calendarCourse * cTemp = NULL;
char* tok;
char* textToTok = strdup(linesTokinzedString.toStdString().c_str());
tok = strtok(textToTok,"\n");
while (tok != NULL)
{
temp = tok;
stringHolder.push_back(temp);
tok = strtok(NULL, "\n");
temp = tok;
stringHolder.push_back(temp);
tok = strtok(NULL, "\n");
}
for (QString temp: stringHolder)
for (QString temp: stringHolder)
{
cTemp = lineToCourse(temp);
if (cTemp != NULL)
courses->push_back(cTemp);
cTemp = lineToCourse(temp);
if (cTemp != NULL)
courses->push_back(cTemp);
}
}
calendarCourse *CalendarPage::lineToCourse(QString line)
{
calendarCourse *tempC = NULL;
QString templinearray[CALENDAR_COURSE_FIELDS];//[serial,name,type,lecturer,points,semesterhours,dayandhours,room]
int serial;
double points,semesterHours;
QString name,type, lecturer,dayAndHour,room;
QString tempS = "";
int i = 0;
char* tok;
char* cLine = strdup(line.toStdString().c_str());
tok = strtok(cLine, "\t");
while(tok != NULL)
calendarCourse *tempC = NULL;
QString templinearray[CALENDAR_COURSE_FIELDS];//[serial,name,type,lecturer,points,semesterhours,dayandhours,room]
int serial;
double points,semesterHours;
QString name,type, lecturer,dayAndHour,room;
QString tempS = "";
int i = 0;
char* tok;
char* cLine = strdup(line.toStdString().c_str());
tok = strtok(cLine, "\t");
while(tok != NULL)
{
tempS = QString(tok);
tempS = QString(tok);
if (i >= 1)
if (i >= 1) //skips on semester character
{
templinearray[i-1] = tempS.trimmed();
templinearray[i-1] = tempS.trimmed();
}
i++;
if (i > 8)
break;
tok=strtok(NULL, "\t");
i++;
if (i > 8)
break;
tok=strtok(NULL, "\t");
}
if (templinearray[0] == "") //empty parsing
return NULL;
if (templinearray[0] == "") //empty parsing
return NULL;
serial = templinearray[calendarCourse::CourseScheme::SERIAL].toInt();
name = templinearray[calendarCourse::CourseScheme::NAME];
type = templinearray[calendarCourse::CourseScheme::TYPE];
serial = templinearray[calendarCourse::CourseScheme::SERIAL].toInt();
name = templinearray[calendarCourse::CourseScheme::NAME];
type = templinearray[calendarCourse::CourseScheme::TYPE];
if (!templinearray[calendarCourse::CourseScheme::LECTURER].isEmpty())
lecturer = templinearray[calendarCourse::CourseScheme::LECTURER];
else
lecturer = LECTURER_DEFAULT_STRING;
if (!templinearray[calendarCourse::CourseScheme::LECTURER].isEmpty())
lecturer = templinearray[calendarCourse::CourseScheme::LECTURER];
else
lecturer = LECTURER_DEFAULT_STRING;
if (!templinearray[calendarCourse::CourseScheme::POINTS].isEmpty())
points = templinearray[calendarCourse::CourseScheme::POINTS].toDouble();
else
points = 0;
if (!templinearray[calendarCourse::CourseScheme::SEM_HOURS].isEmpty())
semesterHours = templinearray[calendarCourse::CourseScheme::SEM_HOURS].toDouble();
else
semesterHours = 0;
if (!templinearray[calendarCourse::CourseScheme::POINTS].isEmpty())
points = templinearray[calendarCourse::CourseScheme::POINTS].toDouble();
else
points = 0;
if (!templinearray[calendarCourse::CourseScheme::SEM_HOURS].isEmpty())
semesterHours = templinearray[calendarCourse::CourseScheme::SEM_HOURS].toDouble();
else
semesterHours = 0;
dayAndHour = templinearray[calendarCourse::CourseScheme::DAY_AND_HOURS];
dayAndHour = templinearray[calendarCourse::CourseScheme::DAY_AND_HOURS];
if (!templinearray[calendarCourse::CourseScheme::ROOM].isEmpty())
room = templinearray[calendarCourse::CourseScheme::ROOM];
else
room = ROOM_DEFAULT_STRING;
if (!templinearray[calendarCourse::CourseScheme::ROOM].isEmpty())
room = templinearray[calendarCourse::CourseScheme::ROOM];
else
room = ROOM_DEFAULT_STRING;
qDebug() << serial << name << type << lecturer << points << semesterHours << dayAndHour << room;
tempC = new calendarCourse(serial,name,type,lecturer,points,semesterHours,dayAndHour,room);
return tempC;
tempC = new calendarCourse(serial,name,type,lecturer,points,semesterHours,dayAndHour,room);
// qDebug() << "serial is: " << tempC->getSerialNum();
// qDebug() << tempC->getName();
// qDebug() << tempC->getType();
// qDebug() << tempC->getLecturer();
// qDebug() << tempC->getPoints();
// qDebug() << tempC->getHourBegin() << ":" << tempC->getMinutesBegin();
// qDebug() << tempC->getHourEnd() << ":" << tempC->getMinutesEnd();
// qDebug() << tempC->getDay();
// qDebug() << tempC->getRoom();
return tempC;
}

View file

@ -22,7 +22,6 @@ protected:
private:
QString tokenToLines(QString &textToParse);
void calendarListInit(QString &linesTokinzedString);
calendarCourse* lineToCourse(QString line);

View file

@ -38,7 +38,7 @@ void calendarSchedule::setPage(QString html)
{
CalendarPage::setPage(html);
qDebug() << Q_FUNC_INFO << "inserting into table";
// insertCourseIntoTable();
insertCourseIntoTable();
}
void calendarSchedule::clearTableItems()
@ -61,12 +61,10 @@ void calendarSchedule::insertCourseIntoTable()
int row,col;
for (calendarCourse *coursePtr: *getCourses())
{
qDebug() << coursePtr->getSerialNum();
courseString = "";
currentHour = coursePtr->getHourBegin();
currentDay = coursePtr->getDay();
blocksNumber = coursePtr->getHourEnd() - coursePtr->getHourBegin(); //every hour is a block to fill!
qDebug() << blocksNumber;
while (blocksNumber >= 0)
{
row = currentHour - HOURS_BEGIN;

View file

@ -4,7 +4,6 @@ GradePage::GradePage(QString html) : Page()
{
courses = new std::list<gradeCourse*>();
tempHtml = getString(html);
tempHtml = tokenToLines(tempHtml);
coursesListInit(tempHtml);
}
@ -49,26 +48,6 @@ void GradePage::coursesListInit(QString &linesTokinzedString)
courses->push_back(cTemp);
}
}
QString GradePage::tokenToLines(QString &textToPhrase)
{
QString temp = "";
char *tok;
char* textToTok = strdup(textToPhrase.toStdString().c_str());
tok = strtok(textToTok, "\n");
while(tok != NULL)
{
//amount of data before the actual needed data and no empty lines
if (strcmp(tok," \t ") != 0)
{
temp += tok;
temp += "\n";
}
tok = strtok(NULL, "\n");
}
return temp;
}
gradeCourse* GradePage::lineToCourse(QString line)
{
gradeCourse *tempC = NULL;

View file

@ -27,7 +27,6 @@ public:
private:
QString tokenToLines(QString &textToPhrase);
void coursesListInit(QString &linesTokinzedString);
gradeCourse* lineToCourse(QString line);

View file

@ -8,14 +8,14 @@ Page::Page() { dateHeader = "";}
*/
QString Page::getString(QString &htmlToParse)
{
makeText(htmlToParse);
return this->text;
makeText(htmlToParse);
return this->text;
}
void Page::makeText(QString &html)
{
int index = 0;
index = html.indexOf("<tbody>",0); //set index into the place where the data is
manageTableContent(html, index);
int index = 0;
index = html.indexOf("<tbody>",0); //set index into the place where the data is
manageTableContent(html, index);
}
/**
* @brief Page::manageTableContent strip html, make it string
@ -24,141 +24,153 @@ void Page::makeText(QString &html)
*/
void Page::manageTableContent(QString &html, int index)
{
if (index == -1)
return;
QString temp;
for (int i = index; i < html.length(); i++)
if (index == -1)
return;
QString temp;
for (int i = index; i < html.length(); i++)
{
if (html.at(i) == '<')
if (html.at(i) == '<')
{
//<tr> / <td> / <th>
QString endofTable = "</tbody>";
QString tableTag = html.mid(i, 4); //legth of "tr/td"
if (tableTag == "<tr>")
{
if (!dateHeader.isEmpty())
temp += dateHeader;
i = stitchText(html, temp, i+4);
if (i == -1) //EOF
break;
}
else if (tableTag == "</tr")
{
temp += "\n"; //end row -> new line
i+=5;
}
else if (tableTag == "<td>" || tableTag == "<th>")
{
if (!dateHeader.isEmpty())
temp += "\t"; // new cell -> tab between data
if (html.mid(i, 6) == "<td><a") //link to lecturer portal, need to be deleted
{
i += 6;
while (html.at(++i) != '>');
i = stitchText(html, temp, i+1);
}
else
i = stitchText(html, temp, i+4);
if (dateHeader.isEmpty())
temp += "\t";
if (i == -1) //EOF
break;
}
else if (tableTag == "<td ") // a Year title (in grades table)
{
if (!dateHeader.isEmpty())
if (!temp.isEmpty())
if (temp.lastIndexOf(dateHeader) == temp.length()-dateHeader.length())
{
temp.chop(dateHeader.length()+1);
temp += "\t";
}
while ((html.mid(i,3) != "<b>") && (i < (int)html.length()))
{
if (html.mid(i,5) == "</td>")
break;
i++;
}
i = stitchText(html, temp, i);
}
if (html.mid(i,(endofTable).length()) == endofTable) //is end of table
//<tr> / <td> / <th>
QString endofTable = "</tbody>";
QString tableTag = html.mid(i, 4); //legth of "tr/td"
if (tableTag == "<tr>")
{
if (!dateHeader.isEmpty())
temp += dateHeader;
i = stitchText(html, temp, i+4);
if (i == -1) //EOF
break;
}
else if (tableTag == "</tr")
{
temp += "\n"; //end row -> new line
i+=5;
}
else if (tableTag == "<td>" || tableTag == "<th>")
{
if (!dateHeader.isEmpty())
temp += "\t"; // new cell -> tab between data
if (html.mid(i, 6) == "<td><a") //link to lecturer portal, need to be deleted
{
i += 6;
while (html.at(++i) != '>');
i = stitchText(html, temp, i+1);
}
else
i = stitchText(html, temp, i+4);
if (dateHeader.isEmpty())
temp += "\t";
if (i == -1) //EOF
break;
}
else if (tableTag == "<td ") // a Year title (in grades table) or Day and Hour (in calendar page)
{
if (!dateHeader.isEmpty())
{
//checking if theres a need to fill a timestamp of course
//if the string is not empty, then we will chop the last date stamp to avoid multiple date stamp in empty rows
if (!temp.isEmpty())
if (temp.lastIndexOf(dateHeader) == temp.length()-dateHeader.length())
{
temp.chop(dateHeader.length()+5);
temp += "\t";
}
}
while ((html.mid(i,5) != "</td>") && (i < (int)html.length()))
{
if (html.mid(i,3) == "<b>") //for gpa. year & semester title
{
break;
}
else if ((html.at(i) == '>') && (html.mid(i+4,3) != "<b>")) //for calendar. day and hours
{
i += 1; //lenght of >
break;
}
i++;
}
i = stitchText(html, temp, i);
temp += "\t";
}
if (html.mid(i,(endofTable).length()) == endofTable) //is end of table
{
break;
}
}
}
this->text = temp;
this->text = temp;
}
int Page::stitchText(QString &from, QString &to, int index)
{
if (from.at(index) == '<')
if (from.mid(index,3) == "<b>")
{
QString bTag = from.mid(index, 3);
QString dateline = from.mid(index,from.indexOf("</b>",index+4)-index);
QString temp;
QString date;
char* tok;
int i = 0;
char* textToTok = strdup(dateline.toStdString().c_str());
tok = strtok(textToTok,"<>&nbsp;:");
while (tok != NULL)
QString bTag = from.mid(index, 3);
QString dateline = from.mid(index,from.indexOf("</b>",index+4)-index);
QString temp;
QString date;
char* tok;
int i = 0;
char* textToTok = strdup(dateline.toStdString().c_str());
tok = strtok(textToTok,"<>&nbsp;:");
while (tok != NULL)
{
if (i == 1)
if (i == 1)
{
temp = tok;
date += temp + "\t";
temp = tok;
date += temp + "\t";
}
else if (i == 3)
else if (i == 3)
{
temp = tok;
date += temp;
temp = tok;
date += temp;
}
i++;
tok = strtok(NULL, "<>&nbsp;:");
i++;
tok = strtok(NULL, "<>&nbsp;:");
}
dateHeader = date;
if (bTag != "<b>")
return index-1; //go back one step - for the main function to inc i
index += dateline.length();
dateHeader = date;
if (bTag != "<b>")
return index-1; //go back one step - for the main function to inc i
index += dateline.length();
}
while (from.at(index) != '<' && index < (int)from.length())
while (from.at(index) != '<' && index < (int)from.length())
{
if (from[index] == '&')
if (from[index] == '&')
{
//&nbsp;
QString nbspChr = from.mid(index, 6);
if (nbspChr == "&nbsp;")
//&nbsp;
QString nbspChr = from.mid(index, 6);
if (nbspChr == "&nbsp;")
{
index += 5;
from.replace(index,1,' ');
index += 5;
from.replace(index,1,' ');
}
}
if (endOfString(index,(int) from.length()))
return -1; //EOF
if (endOfString(index,(int) from.length()))
return -1; //EOF
else if (from.at(index) == '<')
return index - 1; //go back one step - for the main function to inc i
else if (from.at(index) == '<')
return index - 1; //go back one step - for the main function to inc i
if ((from.at(index) != '\n') && (from.at(index) != '\t')) //check the actuall data before continue
to += from.at(index);
index++;
if ((from.at(index) != '\n') && (from.at(index) != '\t')) //check the actuall data before continue
to += from.at(index);
index++;
}
return index-1;
return index-1;
}
bool Page::endOfString(int index, int length)
{
if(index < length)
return false;
return true;
if(index < length)
return false;
return true;
}

View file

@ -6,21 +6,21 @@
*/
jceLogin::jceLogin(user* username, QProgressBar *progressbarPtr)
{
this->progressBar = progressbarPtr;
this->recieverPage = new QString();
this->jceA = username;
this->JceConnector = new jceSSLClient(progressBar);
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
this->progressBar = progressbarPtr;
this->recieverPage = new QString();
this->jceA = username;
this->JceConnector = new jceSSLClient(progressBar);
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
}
jceLogin::~jceLogin()
{
this->jceA = NULL;
delete recieverPage;
delete JceConnector;
JceConnector = NULL;
recieverPage = NULL;
this->jceA = NULL;
delete recieverPage;
delete JceConnector;
JceConnector = NULL;
recieverPage = NULL;
}
/**
* @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it.
@ -28,74 +28,74 @@ jceLogin::~jceLogin()
*/
int jceLogin::makeConnection()
{
qDebug() << "jceLogin::makeConnection(); connection to be make";
qDebug() << "jceLogin::makeConnection(); connection to be make";
if (this->recieverPage == NULL)
this->recieverPage = new QString();
if (this->recieverPage == NULL)
this->recieverPage = new QString();
int returnMode; //gets status according to called function of validation step
jceStatus status = jceStatus::JCE_NOT_CONNECTED;
int returnMode; //gets status according to called function of validation step
jceStatus status = jceStatus::JCE_NOT_CONNECTED;
returnMode = checkConnection(); //checking socket status. is connected?
returnMode = checkConnection(); //checking socket status. is connected?
if (returnMode == false)
if (returnMode == false)
{
if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection
return jceStatus::ERROR_ON_OPEN_SOCKET;
else
returnMode = true;
if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection
return jceStatus::ERROR_ON_OPEN_SOCKET;
else
returnMode = true;
}
if (returnMode == true) //connected to host
if (returnMode == true) //connected to host
{
returnMode = makeFirstVisit();
if (returnMode == true) //requst and send first validation
returnMode = makeFirstVisit();
if (returnMode == true) //requst and send first validation
{
status = jceStatus::JCE_START_VALIDATING_PROGRESS;
returnMode = checkValidation();
if (returnMode == 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_VALIDATION_PASSED;
returnMode = makeSecondVisit();
if (returnMode == true) //siging in the website
status = jceStatus::JCE_VALIDATION_PASSED;
returnMode = makeSecondVisit();
if (returnMode == true) //siging in the website
{
qDebug() << "jceLogin::makeConnection(); Signed in succeesfully";
status = jceStatus::JCE_YOU_ARE_IN;
setLoginFlag(true);
qDebug() << "jceLogin::makeConnection(); Signed in succeesfully";
status = jceStatus::JCE_YOU_ARE_IN;
setLoginFlag(true);
}
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
{
status = jceLogin::ERROR_ON_GETTING_INFO;
status = jceLogin::ERROR_ON_GETTING_INFO;
}
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
{
status = jceLogin::ERROR_ON_SEND_REQUEST;
status = jceLogin::ERROR_ON_SEND_REQUEST;
}
else
status = jceStatus::ERROR_ON_VALIDATION;
}
else
else
status = jceStatus::ERROR_ON_VALIDATION;
}
else
status = jceStatus::ERROR_ON_VALIDATION;
}
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
{
status = jceLogin::ERROR_ON_GETTING_INFO;
status = jceLogin::ERROR_ON_GETTING_INFO;
}
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
{
status = jceLogin::ERROR_ON_SEND_REQUEST;
status = jceLogin::ERROR_ON_SEND_REQUEST;
}
else
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
else
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
}
else
status = jceStatus::JCE_NOT_CONNECTED;
else
status = jceStatus::JCE_NOT_CONNECTED;
//we throw status even if we are IN!
qDebug() << "jceLogin::makeConnection(); return status: " << status;
return status;
//we throw status even if we are IN!
qDebug() << "jceLogin::makeConnection(); return status: " << status;
return status;
}
/**
@ -104,21 +104,21 @@ int jceLogin::makeConnection()
*/
bool jceLogin::checkConnection() const
{
if (JceConnector->isConnected())
return true;
if (JceConnector->isConnected())
return true;
return false;
return false;
}
/**
* @brief jceLogin::closeAll
*/
void jceLogin::closeAll()
{
this->JceConnector->makeDiconnect();
if ((this->recieverPage != NULL) && (!this->recieverPage->isEmpty()))
this->JceConnector->makeDiconnect();
if ((this->recieverPage != NULL) && (!this->recieverPage->isEmpty()))
{
delete recieverPage;
recieverPage = NULL;
delete recieverPage;
recieverPage = NULL;
}
}
@ -127,17 +127,17 @@ void jceLogin::closeAll()
*/
void jceLogin::reMakeConnection()
{
if (this->JceConnector != NULL)
delete JceConnector;
if (this->recieverPage != NULL)
delete recieverPage;
recieverPage = NULL;
JceConnector = NULL;
this->recieverPage = new QString();
this->JceConnector = new jceSSLClient(progressBar);
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
emit connectionReadyAfterDisconnection();
if (this->JceConnector != NULL)
delete JceConnector;
if (this->recieverPage != NULL)
delete recieverPage;
recieverPage = NULL;
JceConnector = NULL;
this->recieverPage = new QString();
this->JceConnector = new jceSSLClient(progressBar);
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
emit connectionReadyAfterDisconnection();
}
/**
@ -146,17 +146,17 @@ void jceLogin::reMakeConnection()
*/
int jceLogin::makeFirstVisit()
{
QString usr = jceA->getUsername();
QString psw = jceA->getPassword();
if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
QString usr = jceA->getUsername();
QString psw = jceA->getPassword();
if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
{
if (!JceConnector->recieveData(*recieverPage,true))
return jceLogin::ERROR_ON_GETTING_INFO;
if (!JceConnector->recieveData(*recieverPage,true))
return jceLogin::ERROR_ON_GETTING_INFO;
}
else
return jceLogin::ERROR_ON_SEND_REQUEST;
else
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
return true;
}
/**
* @brief jceLogin::makeSecondVisit making the second validation step of jce student portal login
@ -164,19 +164,19 @@ int jceLogin::makeFirstVisit()
*/
int jceLogin::makeSecondVisit()
{
QString usrid=jceA->getUserID();
QString pswid=jceA->getHashedPassword();
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
QString usrid=jceA->getUserID();
QString pswid=jceA->getHashedPassword();
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
{
if (!(JceConnector->recieveData(*recieverPage,true)))
return jceLogin::ERROR_ON_GETTING_INFO;
if (!(JceConnector->recieveData(*recieverPage,true)))
return jceLogin::ERROR_ON_GETTING_INFO;
return true;
return true;
}
else
return jceLogin::ERROR_ON_SEND_REQUEST;
else
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
return true;
}
/**
* @brief jceLogin::getCalendar according to parameters, we make an HTML request and send it over socket to server
@ -186,17 +186,17 @@ int jceLogin::makeSecondVisit()
*/
int jceLogin::getCalendar(int year, int semester)
{
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester)))))
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester)))))
{
if (!(JceConnector->recieveData(*recieverPage,false)))
return jceLogin::ERROR_ON_GETTING_PAGE;
else
return jceLogin::JCE_PAGE_PASSED;
if (!(JceConnector->recieveData(*recieverPage,false)))
return jceLogin::ERROR_ON_GETTING_PAGE;
else
return jceLogin::JCE_PAGE_PASSED;
}
else
return jceLogin::ERROR_ON_SEND_REQUEST;
else
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
return true;
}
/**
@ -209,17 +209,17 @@ int jceLogin::getCalendar(int year, int semester)
*/
int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester)
{
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
{
if (!(JceConnector->recieveData(*recieverPage,false)))
return jceLogin::ERROR_ON_GETTING_PAGE;
else
return jceLogin::JCE_PAGE_PASSED;
if (!(JceConnector->recieveData(*recieverPage,false)))
return jceLogin::ERROR_ON_GETTING_PAGE;
else
return jceLogin::JCE_PAGE_PASSED;
}
else
return jceLogin::ERROR_ON_SEND_REQUEST;
else
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
return true;
}
/**
@ -229,43 +229,43 @@ int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemest
bool jceLogin::checkValidation()
{
//finds the hashed password
QString constUserID_TAG = "value=\"-N";
QString constHassID_TAG = "-A,-N";
QString hasspass,hassid;
std::size_t hasspass_position1,hasspass_position2;
std::size_t id_position1,id_position2;
//finds the hashed password
QString constUserID_TAG = "value=\"-N";
QString constHassID_TAG = "-A,-N";
QString hasspass,hassid;
std::size_t hasspass_position1,hasspass_position2;
std::size_t id_position1,id_position2;
hasspass_position1 = this->recieverPage->toStdString().find(constHassID_TAG.toStdString()); //looking for hasspass index
if (hasspass_position1 == std::string::npos) //didnt find the tag
return false;
else
hasspass_position1 += constHassID_TAG.length(); //skip the index of tag
hasspass_position2 = this->recieverPage->toStdString().find(",-A,-A", hasspass_position1);
//finds the hass pass
if (hasspass_position2 != std::string::npos) //found the hasspass! storing it
hasspass = recieverPage->mid(hasspass_position1,hasspass_position2-hasspass_position1);
else
return false;
//finds the user id
id_position1 = this->recieverPage->toStdString().find(constUserID_TAG.toStdString(), 0); //looking for hassid index
if (id_position1 == std::string::npos) //didnt find the tag
return false;
else
id_position1 += constUserID_TAG.length(); //skip the index of tag
id_position2 = this->recieverPage->toStdString().find(",-A", id_position1);
if (id_position2 != std::string::npos) //found the hassid! storing it
hassid = recieverPage->mid(id_position1,id_position2-id_position1);
else
return false;
hasspass_position1 = this->recieverPage->toStdString().find(constHassID_TAG.toStdString()); //looking for hasspass index
if (hasspass_position1 == std::string::npos) //didnt find the tag
return false;
else
hasspass_position1 += constHassID_TAG.length(); //skip the index of tag
hasspass_position2 = this->recieverPage->toStdString().find(",-A,-A", hasspass_position1);
//finds the hass pass
if (hasspass_position2 != std::string::npos) //found the hasspass! storing it
hasspass = recieverPage->mid(hasspass_position1,hasspass_position2-hasspass_position1);
else
return false;
//finds the user id
id_position1 = this->recieverPage->toStdString().find(constUserID_TAG.toStdString(), 0); //looking for hassid index
if (id_position1 == std::string::npos) //didnt find the tag
return false;
else
id_position1 += constUserID_TAG.length(); //skip the index of tag
id_position2 = this->recieverPage->toStdString().find(",-A", id_position1);
if (id_position2 != std::string::npos) //found the hassid! storing it
hassid = recieverPage->mid(id_position1,id_position2-id_position1);
else
return false;
//setting user information with given data hassid and hasspass
jceA->setHashedPassword(hasspass);
jceA->setUserID(hassid);
//setting user information with given data hassid and hasspass
jceA->setHashedPassword(hasspass);
jceA->setUserID(hassid);
qDebug() << "jceLogin::checkValidation(); Found Hashed: " << hasspass << "And ID: " << hassid;
qDebug() << "jceLogin::checkValidation(); Found Hashed: " << hasspass << "And ID: " << hassid;
return true;
return true;
}
/**
* @brief jceLogin::setLoginFlag
@ -273,7 +273,7 @@ bool jceLogin::checkValidation()
*/
void jceLogin::setLoginFlag(bool x)
{
this->loginFlag = x;
this->loginFlag = x;
}
/**
* @brief jceLogin::isLoginFlag checking if there is a connection, if true - > return if we signed in. otherwise, return not (not connected dough)
@ -281,9 +281,9 @@ void jceLogin::setLoginFlag(bool x)
*/
bool jceLogin::isLoginFlag() const
{
if (checkConnection())
return this->loginFlag;
return false;
if (checkConnection())
return this->loginFlag;
return false;
}
/**
@ -292,27 +292,27 @@ bool jceLogin::isLoginFlag() const
*/
QString jceLogin::getPage()
{
return *recieverPage;
return *recieverPage;
}
void jceLogin::reValidation()
{
qDebug() << Q_FUNC_INFO << "Revalidating user";
qDebug() << Q_FUNC_INFO << "Revalidating user";
if (makeFirstVisit() == true)
if (makeFirstVisit() == true)
{
if (checkValidation())
if (checkValidation())
{
if (makeSecondVisit() == true)
qDebug() << Q_FUNC_INFO << "Validated";
else
qWarning() << Q_FUNC_INFO << "Second visit finished with an error";
if (makeSecondVisit() == true)
qDebug() << Q_FUNC_INFO << "Validated";
else
qWarning() << Q_FUNC_INFO << "Second visit finished with an error";
}
else
qDebug() << Q_FUNC_INFO << "checking validation ended with an error";
else
qDebug() << Q_FUNC_INFO << "checking validation ended with an error";
}
else
else
{
qDebug() << Q_FUNC_INFO << "Couldnt Validate User";
qDebug() << Q_FUNC_INFO << "Couldnt Validate User";
}
}

View file

@ -12,57 +12,58 @@
class jceLogin : public QObject
{
Q_OBJECT
Q_OBJECT
public:
jceLogin(user* username,QProgressBar *progressbarPtr);
~jceLogin();
jceLogin(user* username,QProgressBar *progressbarPtr);
~jceLogin();
enum jceStatus {
JCE_NOT_CONNECTED,
ERROR_ON_VALIDATION,
ERROR_ON_VALIDATION_USER_BLOCKED,
ERROR_ON_OPEN_SOCKET,
ERROR_ON_SEND_REQUEST,
ERROR_ON_GETTING_INFO,
ERROR_ON_GETTING_PAGE,
enum jceStatus {
JCE_NOT_CONNECTED,
ERROR_ON_VALIDATION,
ERROR_ON_VALIDATION_USER_BLOCKED,
ERROR_ON_OPEN_SOCKET,
ERROR_ON_SEND_REQUEST,
ERROR_ON_GETTING_INFO,
ERROR_ON_GETTING_PAGE,
JCE_START_VALIDATING_PROGRESS,
JCE_VALIDATION_PASSED,
JCE_YOU_ARE_IN,
JCE_PAGE_PASSED
};
JCE_START_VALIDATING_PROGRESS,
JCE_VALIDATION_PASSED,
JCE_YOU_ARE_IN,
JCE_PAGE_PASSED
};
int makeConnection();
void closeAll();
bool checkConnection() const;
bool isLoginFlag() const;
int makeConnection();
void closeAll();
int getCalendar(int year, int semester);
int getGrades(int fromYear, int toYear, int fromSemester, int toSemester);
bool checkConnection() const;
bool isLoginFlag() const;
QString getPage();
int getCalendar(int year, int semester);
int getGrades(int fromYear, int toYear, int fromSemester, int toSemester);
QString getPage();
private slots:
void reValidation();
void reMakeConnection();
void reValidation();
void reMakeConnection();
signals:
void connectionReadyAfterDisconnection();
void connectionReadyAfterDisconnection();
private:
int makeFirstVisit();
int makeSecondVisit();
bool checkValidation();
void setLoginFlag(bool x);
int makeFirstVisit();
int makeSecondVisit();
bool checkValidation();
void setLoginFlag(bool x);
bool loginFlag;
QString * recieverPage;
user * jceA;
jceSSLClient * JceConnector;
QProgressBar *progressBar;
bool loginFlag;
QString * recieverPage;
user * jceA;
jceSSLClient * JceConnector;
QProgressBar *progressBar;
};