fixed bugs, added option to keep login
This commit is contained in:
parent
050fb21e1d
commit
1980efe130
29 changed files with 3434 additions and 3392 deletions
58
README.md
58
README.md
|
@ -1,29 +1,29 @@
|
|||
jceAverageCalculator
|
||||
====================
|
||||
|
||||
Compile with QT
|
||||
|
||||
Launch, insert your JCE username and password.<br>
|
||||
Once your logged in, go to Coure Tab and hit "ADD"<br>
|
||||
Now you will see all your courses in a table content<br>
|
||||
<br>
|
||||
Edit your grade and see the average difference.<br>
|
||||
|
||||
Optional: <br>
|
||||
hit setting tab to select the date interval<br>
|
||||
p.s -> you need to clear the table before.<br>
|
||||
|
||||
Thanks to <br>
|
||||
<ul>
|
||||
<li><a href='mailto:sagidayan@gmail.com'>Sagi Dayan</a></li>
|
||||
<li><a href='mailto:nadav2051@gmail.com'>Nadav Luzzato</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
Made by
|
||||
<ul>
|
||||
<li><a href='mailto:liranbg@gmail.com'>Liran Ben Gida</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
jceAverageCalculator
|
||||
====================
|
||||
|
||||
Compile with QT
|
||||
|
||||
Launch, insert your JCE username and password.<br>
|
||||
Once your logged in, go to Coure Tab and hit "ADD"<br>
|
||||
Now you will see all your courses in a table content<br>
|
||||
<br>
|
||||
Edit your grade and see the average difference.<br>
|
||||
|
||||
Optional: <br>
|
||||
hit setting tab to select the date interval<br>
|
||||
p.s -> you need to clear the table before.<br>
|
||||
|
||||
Thanks to <br>
|
||||
<ul>
|
||||
<li><a href='mailto:sagidayan@gmail.com'>Sagi Dayan</a></li>
|
||||
<li><a href='mailto:nadav2051@gmail.com'>Nadav Luzzato</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
Made by
|
||||
<ul>
|
||||
<li><a href='mailto:liranbg@gmail.com'>Liran Ben Gida</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
|
102
jceGrade.pro
102
jceGrade.pro
|
@ -1,51 +1,51 @@
|
|||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2014-05-31T19:49:42
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui network
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
TARGET = jceGrade
|
||||
TEMPLATE = app
|
||||
RC_FILE = appConfigure.rc
|
||||
CONFIG += c++11 static console
|
||||
|
||||
SOURCES += main/coursestablemanager.cpp \
|
||||
main/loginhandler.cpp \
|
||||
main/main.cpp \
|
||||
main/mainscreen.cpp \
|
||||
src/connection/qtsslsocket.cpp \
|
||||
src/user.cpp \
|
||||
src/grades/Course.cpp \
|
||||
src/grades/GradePage.cpp \
|
||||
src/grades/Page.cpp \
|
||||
src/jce/jcedate.cpp \
|
||||
src/jce/jcelogin.cpp \
|
||||
src/data/savedata.cpp
|
||||
|
||||
|
||||
|
||||
HEADERS += main/coursestablemanager.h \
|
||||
main/loginhandler.h \
|
||||
main/mainscreen.h \
|
||||
src/connection/qtsslsocket.h \
|
||||
src/user.h \
|
||||
src/grades/Course.h \
|
||||
src/grades/GradePage.h \
|
||||
src/grades/Page.h \
|
||||
src/jce/jcedate.h \
|
||||
src/jce/jcelogin.h \
|
||||
src/jce/jceLoginHtmlScripts.h \
|
||||
src/data/savedata.h
|
||||
|
||||
|
||||
|
||||
FORMS += \
|
||||
main/mainscreen.ui
|
||||
|
||||
OTHER_FILES +=
|
||||
|
||||
RESOURCES += \
|
||||
resources/connectionstatus.qrc
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2014-05-31T19:49:42
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui network
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
TARGET = jceGrade
|
||||
TEMPLATE = app
|
||||
RC_FILE = appConfigure.rc
|
||||
CONFIG += c++11 static
|
||||
|
||||
SOURCES += main/coursestablemanager.cpp \
|
||||
main/loginhandler.cpp \
|
||||
main/main.cpp \
|
||||
main/mainscreen.cpp \
|
||||
src/connection/qtsslsocket.cpp \
|
||||
src/user.cpp \
|
||||
src/grades/Course.cpp \
|
||||
src/grades/GradePage.cpp \
|
||||
src/grades/Page.cpp \
|
||||
src/jce/jcedate.cpp \
|
||||
src/jce/jcelogin.cpp \
|
||||
src/data/savedata.cpp
|
||||
|
||||
|
||||
|
||||
HEADERS += main/coursestablemanager.h \
|
||||
main/loginhandler.h \
|
||||
main/mainscreen.h \
|
||||
src/connection/qtsslsocket.h \
|
||||
src/user.h \
|
||||
src/grades/Course.h \
|
||||
src/grades/GradePage.h \
|
||||
src/grades/Page.h \
|
||||
src/jce/jcedate.h \
|
||||
src/jce/jcelogin.h \
|
||||
src/jce/jceLoginHtmlScripts.h \
|
||||
src/data/savedata.h
|
||||
|
||||
|
||||
|
||||
FORMS += \
|
||||
main/mainscreen.ui
|
||||
|
||||
OTHER_FILES +=
|
||||
|
||||
RESOURCES += \
|
||||
resources/connectionstatus.qrc
|
||||
|
|
|
@ -1,252 +1,252 @@
|
|||
#include "coursestablemanager.h"
|
||||
|
||||
coursesTableManager::coursesTableManager(QTableWidget *ptr, user *usrPtr)
|
||||
{
|
||||
this->gp = NULL;
|
||||
this->us = usrPtr;
|
||||
this->courseTBL = ptr;
|
||||
|
||||
/*
|
||||
* Initilizing Table
|
||||
*/
|
||||
courseTBL->setRowCount(0);
|
||||
courseTBL->setColumnCount(COURSE_FIELDS);
|
||||
QStringList mz;
|
||||
mz << "Serial" << "Name" << "Type" << "Points" << "Hours" << "Grade" << "Additions";
|
||||
courseTBL->setHorizontalHeaderLabels(mz);
|
||||
courseTBL->verticalHeader()->setVisible(true);
|
||||
courseTBL->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
courseTBL->setShowGrid(true);
|
||||
courseTBL->setStyleSheet("QTableView {selection-background-color: red;}");
|
||||
|
||||
}
|
||||
|
||||
coursesTableManager::~coursesTableManager()
|
||||
{
|
||||
courseTBL = NULL;
|
||||
delete gp;
|
||||
gp=NULL;
|
||||
}
|
||||
/**
|
||||
* @brief coursesTableManager::insertJceCoursesIntoTable phrasing the course list to rows in table
|
||||
*/
|
||||
void coursesTableManager::insertJceCoursesIntoTable()
|
||||
{
|
||||
for (Course *c: *gp->getCourses())
|
||||
{
|
||||
if (us->getInfluenceCourseOnly())
|
||||
{
|
||||
if (isCourseInfluence(c))
|
||||
addRow(c);
|
||||
}
|
||||
else
|
||||
addRow(c);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief coursesTableManager::setCoursesList creating courses list with given html page
|
||||
* @param html
|
||||
*/
|
||||
void coursesTableManager::setCoursesList(std::string &html)
|
||||
{
|
||||
gp = new GradePage(html);
|
||||
}
|
||||
/**
|
||||
* @brief coursesTableManager::changes when user changes the table manually it updates it
|
||||
* @param change string change
|
||||
* @param row row index
|
||||
* @param col col index
|
||||
* @return if change has been done
|
||||
*/
|
||||
bool coursesTableManager::changes(QString change, int row, int col)
|
||||
{
|
||||
|
||||
bool isNumFlag = true;
|
||||
|
||||
int serialCourse = courseTBL->item(row,Course::CourseScheme::SERIAL)->text().toInt();
|
||||
for (Course *c: *gp->getCourses())
|
||||
{
|
||||
if (c->getSerialNum() == serialCourse)
|
||||
{
|
||||
switch (col)
|
||||
{
|
||||
case (Course::CourseScheme::NAME):
|
||||
c->setName(change.toStdString());
|
||||
break;
|
||||
case (Course::CourseScheme::TYPE):
|
||||
c->setType(change.toStdString());
|
||||
break;
|
||||
case (Course::CourseScheme::POINTS):
|
||||
{
|
||||
change.toDouble(&isNumFlag);
|
||||
|
||||
if (!isNumFlag)
|
||||
{
|
||||
courseTBL->item(row,col)->setText(QString::number(c->getPoints()));
|
||||
}
|
||||
else
|
||||
c->setPoints(change.toDouble());
|
||||
break;
|
||||
}
|
||||
case (Course::CourseScheme::HOURS):
|
||||
{
|
||||
change.toDouble(&isNumFlag);
|
||||
|
||||
if (!isNumFlag)
|
||||
{
|
||||
courseTBL->item(row,col)->setText(QString::number(c->getHours()));
|
||||
}
|
||||
else
|
||||
c->setHours(change.toDouble());
|
||||
break;
|
||||
}
|
||||
case (Course::CourseScheme::GRADE):
|
||||
{
|
||||
change.toDouble(&isNumFlag);
|
||||
|
||||
if (!isNumFlag)
|
||||
{
|
||||
courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((change.toDouble() >= 0) && (change.toDouble() <= 100))
|
||||
c->setGrade(change.toDouble());
|
||||
else
|
||||
courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (Course::CourseScheme::ADDITION):
|
||||
c->setAdditions(change.toStdString());
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isNumFlag;
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief coursesTableManager::addRow adds row with given information
|
||||
* @param courseToAdd if exists, add its information to table
|
||||
*/
|
||||
void coursesTableManager::addRow(const Course *courseToAdd)
|
||||
{
|
||||
int i,j;
|
||||
i = courseTBL->rowCount();
|
||||
j = 0;
|
||||
QTableWidgetItem *serial,*name,*type,*points,*hours,*grade,*addition;
|
||||
const Course * c;
|
||||
if (courseToAdd != NULL)
|
||||
{
|
||||
c = courseToAdd;
|
||||
if (!isCourseAlreadyInserted(c->getSerialNum()))
|
||||
{
|
||||
courseTBL->setRowCount(courseTBL->rowCount()+1);
|
||||
serial = new QTableWidgetItem(QString::number(c->getSerialNum()));
|
||||
serial->setFlags(serial->flags() & ~Qt::ItemIsEditable);
|
||||
points = new QTableWidgetItem(QString::number(c->getPoints()));
|
||||
points->setFlags(serial->flags() & ~Qt::ItemIsEditable);
|
||||
hours = new QTableWidgetItem(QString::number(c->getHours()));
|
||||
hours->setFlags(serial->flags() & ~Qt::ItemIsEditable);
|
||||
grade = new QTableWidgetItem(QString::number(c->getGrade()));
|
||||
name = new QTableWidgetItem(QString::fromStdString(c->getName()));
|
||||
name->setFlags(serial->flags() & ~Qt::ItemIsEditable);
|
||||
type = new QTableWidgetItem(QString::fromStdString(c->getType()));
|
||||
type->setFlags(serial->flags() & ~Qt::ItemIsEditable);
|
||||
addition = new QTableWidgetItem(QString::fromStdString(c->getAddidtions()));
|
||||
|
||||
courseTBL->setItem(i,j++,serial);
|
||||
courseTBL->setItem(i,j++,name);
|
||||
courseTBL->setItem(i,j++,type);
|
||||
courseTBL->setItem(i,j++,points);
|
||||
courseTBL->setItem(i,j++,hours);
|
||||
courseTBL->setItem(i,j++,grade);
|
||||
courseTBL->setItem(i,j,addition);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
courseTBL->resizeColumnsToContents();
|
||||
|
||||
}
|
||||
double coursesTableManager::getAvg()
|
||||
{
|
||||
if (this->gp != NULL)
|
||||
return gp->getAvg();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus)
|
||||
{
|
||||
if (ignoreCourseStatus)
|
||||
{
|
||||
int i = 0;
|
||||
while (i < courseTBL->rowCount())
|
||||
{
|
||||
if (courseTBL->item(i,Course::CourseScheme::POINTS)->text().compare("0") == 0)
|
||||
courseTBL->removeRow(i--);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Course *c: *gp->getCourses())
|
||||
{
|
||||
if (!(isCourseAlreadyInserted(c->getSerialNum())))
|
||||
if (c->getPoints() == 0)
|
||||
addRow(c);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void coursesTableManager::clearTable()
|
||||
{
|
||||
if (courseTBL->rowCount() == 0)
|
||||
return;
|
||||
|
||||
int i = 0; //starting point
|
||||
while (courseTBL->rowCount() > i)
|
||||
{
|
||||
gp->removeCourse(courseTBL->item(i,Course::CourseScheme::SERIAL)->text().toStdString());
|
||||
courseTBL->removeRow(i);
|
||||
}
|
||||
gp = NULL;
|
||||
courseTBL->repaint();
|
||||
}
|
||||
|
||||
Course *coursesTableManager::getCourseByRow(int row)
|
||||
{
|
||||
QString courseSerial = courseTBL->item(row,Course::CourseScheme::SERIAL)->text();
|
||||
for (Course *c: *gp->getCourses())
|
||||
{
|
||||
if (c->getSerialNum() == courseSerial.toDouble())
|
||||
return c;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool coursesTableManager::isCourseAlreadyInserted(double courseID)
|
||||
{
|
||||
int i=0;
|
||||
for (i = 0; i < courseTBL->rowCount(); ++i)
|
||||
{
|
||||
QString courseSerial = courseTBL->item(i,Course::CourseScheme::SERIAL)->text();
|
||||
if (QString::number(courseID) == courseSerial)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool coursesTableManager::isCourseInfluence(const Course *courseToCheck)
|
||||
{
|
||||
if (courseToCheck->getPoints() > 0)
|
||||
return true;
|
||||
return false;
|
||||
|
||||
}
|
||||
#include "coursestablemanager.h"
|
||||
|
||||
coursesTableManager::coursesTableManager(QTableWidget *ptr, user *usrPtr)
|
||||
{
|
||||
this->gp = NULL;
|
||||
this->us = usrPtr;
|
||||
this->courseTBL = ptr;
|
||||
|
||||
/*
|
||||
* Initilizing Table
|
||||
*/
|
||||
courseTBL->setRowCount(0);
|
||||
courseTBL->setColumnCount(COURSE_FIELDS);
|
||||
QStringList mz;
|
||||
mz << "Serial" << "Name" << "Type" << "Points" << "Hours" << "Grade" << "Additions";
|
||||
courseTBL->setHorizontalHeaderLabels(mz);
|
||||
courseTBL->verticalHeader()->setVisible(true);
|
||||
courseTBL->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
courseTBL->setShowGrid(true);
|
||||
courseTBL->setStyleSheet("QTableView {selection-background-color: red;}");
|
||||
|
||||
}
|
||||
|
||||
coursesTableManager::~coursesTableManager()
|
||||
{
|
||||
courseTBL = NULL;
|
||||
delete gp;
|
||||
gp=NULL;
|
||||
}
|
||||
/**
|
||||
* @brief coursesTableManager::insertJceCoursesIntoTable phrasing the course list to rows in table
|
||||
*/
|
||||
void coursesTableManager::insertJceCoursesIntoTable()
|
||||
{
|
||||
for (Course *c: *gp->getCourses())
|
||||
{
|
||||
if (us->getInfluenceCourseOnly())
|
||||
{
|
||||
if (isCourseInfluence(c))
|
||||
addRow(c);
|
||||
}
|
||||
else
|
||||
addRow(c);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief coursesTableManager::setCoursesList creating courses list with given html page
|
||||
* @param html
|
||||
*/
|
||||
void coursesTableManager::setCoursesList(std::string &html)
|
||||
{
|
||||
gp = new GradePage(html);
|
||||
}
|
||||
/**
|
||||
* @brief coursesTableManager::changes when user changes the table manually it updates it
|
||||
* @param change string change
|
||||
* @param row row index
|
||||
* @param col col index
|
||||
* @return if change has been done
|
||||
*/
|
||||
bool coursesTableManager::changes(QString change, int row, int col)
|
||||
{
|
||||
|
||||
bool isNumFlag = true;
|
||||
|
||||
int serialCourse = courseTBL->item(row,Course::CourseScheme::SERIAL)->text().toInt();
|
||||
for (Course *c: *gp->getCourses())
|
||||
{
|
||||
if (c->getSerialNum() == serialCourse)
|
||||
{
|
||||
switch (col)
|
||||
{
|
||||
case (Course::CourseScheme::NAME):
|
||||
c->setName(change.toStdString());
|
||||
break;
|
||||
case (Course::CourseScheme::TYPE):
|
||||
c->setType(change.toStdString());
|
||||
break;
|
||||
case (Course::CourseScheme::POINTS):
|
||||
{
|
||||
change.toDouble(&isNumFlag);
|
||||
|
||||
if (!isNumFlag)
|
||||
{
|
||||
courseTBL->item(row,col)->setText(QString::number(c->getPoints()));
|
||||
}
|
||||
else
|
||||
c->setPoints(change.toDouble());
|
||||
break;
|
||||
}
|
||||
case (Course::CourseScheme::HOURS):
|
||||
{
|
||||
change.toDouble(&isNumFlag);
|
||||
|
||||
if (!isNumFlag)
|
||||
{
|
||||
courseTBL->item(row,col)->setText(QString::number(c->getHours()));
|
||||
}
|
||||
else
|
||||
c->setHours(change.toDouble());
|
||||
break;
|
||||
}
|
||||
case (Course::CourseScheme::GRADE):
|
||||
{
|
||||
change.toDouble(&isNumFlag);
|
||||
|
||||
if (!isNumFlag)
|
||||
{
|
||||
courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((change.toDouble() >= 0) && (change.toDouble() <= 100))
|
||||
c->setGrade(change.toDouble());
|
||||
else
|
||||
courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (Course::CourseScheme::ADDITION):
|
||||
c->setAdditions(change.toStdString());
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isNumFlag;
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief coursesTableManager::addRow adds row with given information
|
||||
* @param courseToAdd if exists, add its information to table
|
||||
*/
|
||||
void coursesTableManager::addRow(const Course *courseToAdd)
|
||||
{
|
||||
int i,j;
|
||||
i = courseTBL->rowCount();
|
||||
j = 0;
|
||||
QTableWidgetItem *serial,*name,*type,*points,*hours,*grade,*addition;
|
||||
const Course * c;
|
||||
if (courseToAdd != NULL)
|
||||
{
|
||||
c = courseToAdd;
|
||||
if (!isCourseAlreadyInserted(c->getSerialNum()))
|
||||
{
|
||||
courseTBL->setRowCount(courseTBL->rowCount()+1);
|
||||
serial = new QTableWidgetItem(QString::number(c->getSerialNum()));
|
||||
serial->setFlags(serial->flags() & ~Qt::ItemIsEditable);
|
||||
points = new QTableWidgetItem(QString::number(c->getPoints()));
|
||||
points->setFlags(serial->flags() & ~Qt::ItemIsEditable);
|
||||
hours = new QTableWidgetItem(QString::number(c->getHours()));
|
||||
hours->setFlags(serial->flags() & ~Qt::ItemIsEditable);
|
||||
grade = new QTableWidgetItem(QString::number(c->getGrade()));
|
||||
name = new QTableWidgetItem(QString::fromStdString(c->getName()));
|
||||
name->setFlags(serial->flags() & ~Qt::ItemIsEditable);
|
||||
type = new QTableWidgetItem(QString::fromStdString(c->getType()));
|
||||
type->setFlags(serial->flags() & ~Qt::ItemIsEditable);
|
||||
addition = new QTableWidgetItem(QString::fromStdString(c->getAddidtions()));
|
||||
|
||||
courseTBL->setItem(i,j++,serial);
|
||||
courseTBL->setItem(i,j++,name);
|
||||
courseTBL->setItem(i,j++,type);
|
||||
courseTBL->setItem(i,j++,points);
|
||||
courseTBL->setItem(i,j++,hours);
|
||||
courseTBL->setItem(i,j++,grade);
|
||||
courseTBL->setItem(i,j,addition);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
courseTBL->resizeColumnsToContents();
|
||||
|
||||
}
|
||||
double coursesTableManager::getAvg()
|
||||
{
|
||||
if (this->gp != NULL)
|
||||
return gp->getAvg();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus)
|
||||
{
|
||||
if (ignoreCourseStatus)
|
||||
{
|
||||
int i = 0;
|
||||
while (i < courseTBL->rowCount())
|
||||
{
|
||||
if (courseTBL->item(i,Course::CourseScheme::POINTS)->text().compare("0") == 0)
|
||||
courseTBL->removeRow(i--);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Course *c: *gp->getCourses())
|
||||
{
|
||||
if (!(isCourseAlreadyInserted(c->getSerialNum())))
|
||||
if (c->getPoints() == 0)
|
||||
addRow(c);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void coursesTableManager::clearTable()
|
||||
{
|
||||
if (courseTBL->rowCount() == 0)
|
||||
return;
|
||||
|
||||
int i = 0; //starting point
|
||||
while (courseTBL->rowCount() > i)
|
||||
{
|
||||
gp->removeCourse(courseTBL->item(i,Course::CourseScheme::SERIAL)->text().toStdString());
|
||||
courseTBL->removeRow(i);
|
||||
}
|
||||
gp = NULL;
|
||||
courseTBL->repaint();
|
||||
}
|
||||
|
||||
Course *coursesTableManager::getCourseByRow(int row)
|
||||
{
|
||||
QString courseSerial = courseTBL->item(row,Course::CourseScheme::SERIAL)->text();
|
||||
for (Course *c: *gp->getCourses())
|
||||
{
|
||||
if (c->getSerialNum() == courseSerial.toDouble())
|
||||
return c;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool coursesTableManager::isCourseAlreadyInserted(double courseID)
|
||||
{
|
||||
int i=0;
|
||||
for (i = 0; i < courseTBL->rowCount(); ++i)
|
||||
{
|
||||
QString courseSerial = courseTBL->item(i,Course::CourseScheme::SERIAL)->text();
|
||||
if (QString::number(courseID) == courseSerial)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool coursesTableManager::isCourseInfluence(const Course *courseToCheck)
|
||||
{
|
||||
if (courseToCheck->getPoints() > 0)
|
||||
return true;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
#ifndef COURSESTABLEMANAGER_H
|
||||
#define COURSESTABLEMANAGER_H
|
||||
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QHeaderView>
|
||||
#include <QMessageBox>
|
||||
#include <QTableWidget>
|
||||
#include <QString>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "src/grades/Course.h"
|
||||
#include "src/grades/GradePage.h"
|
||||
#include "src/user.h"
|
||||
|
||||
class coursesTableManager
|
||||
{
|
||||
public:
|
||||
coursesTableManager(QTableWidget *, user *usrPtr);
|
||||
~coursesTableManager();
|
||||
void insertJceCoursesIntoTable();
|
||||
void setCoursesList(std::string &htmlPage);
|
||||
bool changes(QString change, int row, int col);
|
||||
void addRow(const Course * courseToAdd = 0);
|
||||
double getAvg();
|
||||
|
||||
void influnceCourseChanged(bool status);
|
||||
void clearTable();
|
||||
|
||||
private:
|
||||
QTableWidget *courseTBL;
|
||||
GradePage *gp;
|
||||
user *us;
|
||||
|
||||
Course * getCourseByRow(int row);
|
||||
bool isCourseAlreadyInserted(double courseID);
|
||||
bool isCourseInfluence(const Course *courseToCheck);
|
||||
};
|
||||
|
||||
#endif // COURSESTABLEMANAGER_H
|
||||
#ifndef COURSESTABLEMANAGER_H
|
||||
#define COURSESTABLEMANAGER_H
|
||||
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QHeaderView>
|
||||
#include <QMessageBox>
|
||||
#include <QTableWidget>
|
||||
#include <QString>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "src/grades/Course.h"
|
||||
#include "src/grades/GradePage.h"
|
||||
#include "src/user.h"
|
||||
|
||||
class coursesTableManager
|
||||
{
|
||||
public:
|
||||
coursesTableManager(QTableWidget *, user *usrPtr);
|
||||
~coursesTableManager();
|
||||
void insertJceCoursesIntoTable();
|
||||
void setCoursesList(std::string &htmlPage);
|
||||
bool changes(QString change, int row, int col);
|
||||
void addRow(const Course * courseToAdd = 0);
|
||||
double getAvg();
|
||||
|
||||
void influnceCourseChanged(bool status);
|
||||
void clearTable();
|
||||
|
||||
private:
|
||||
QTableWidget *courseTBL;
|
||||
GradePage *gp;
|
||||
user *us;
|
||||
|
||||
Course * getCourseByRow(int row);
|
||||
bool isCourseAlreadyInserted(double courseID);
|
||||
bool isCourseInfluence(const Course *courseToCheck);
|
||||
};
|
||||
|
||||
#endif // COURSESTABLEMANAGER_H
|
||||
|
|
|
@ -1,67 +1,67 @@
|
|||
#include "loginhandler.h"
|
||||
|
||||
loginHandler::loginHandler(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr)
|
||||
{
|
||||
this->jceLog = ptr;
|
||||
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)
|
||||
{
|
||||
|
||||
if (a == jceLogin::JCE_YOU_ARE_IN)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (a == jceLogin::ERROR_ON_VALIDATION)
|
||||
{
|
||||
popMessage("check your password");
|
||||
|
||||
usrnmEditPtr->setDisabled(false);
|
||||
pswdEditPtr->setDisabled(false);
|
||||
|
||||
pswdEditPtr->selectAll();
|
||||
pswdEditPtr->setFocus();
|
||||
return false;
|
||||
}
|
||||
else if (a == jceLogin::ERROR_ON_OPEN_SOCKET)
|
||||
{
|
||||
popMessage("Please check your internet status");
|
||||
|
||||
jceLog->closeAll();
|
||||
|
||||
return false;
|
||||
}
|
||||
else if (a == jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED)
|
||||
{
|
||||
std::cout << "error!!!!!!" << (jceLog->getPage()) << std::endl;
|
||||
popMessage("You were blocked, please wait couple of minutes or contact JCE");
|
||||
jceLog->closeAll();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void loginHandler::popMessage(QString message)
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle("Error");
|
||||
msgBox.setText(message);
|
||||
msgBox.exec();
|
||||
msgBox.setFocus();
|
||||
}
|
||||
|
||||
|
||||
#include "loginhandler.h"
|
||||
|
||||
loginHandler::loginHandler()
|
||||
{
|
||||
|
||||
}
|
||||
void loginHandler::setPointers(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr)
|
||||
{
|
||||
this->jceLog = ptr;
|
||||
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)
|
||||
{
|
||||
|
||||
if (a == jceLogin::JCE_YOU_ARE_IN)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (a == jceLogin::ERROR_ON_VALIDATION)
|
||||
{
|
||||
popMessage("check your password");
|
||||
|
||||
usrnmEditPtr->setDisabled(false);
|
||||
pswdEditPtr->setDisabled(false);
|
||||
|
||||
pswdEditPtr->selectAll();
|
||||
pswdEditPtr->setFocus();
|
||||
return false;
|
||||
}
|
||||
else if (a == jceLogin::ERROR_ON_OPEN_SOCKET)
|
||||
{
|
||||
popMessage("Please check your Internet status");
|
||||
jceLog->closeAll();
|
||||
return false;
|
||||
}
|
||||
else if (a == jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED)
|
||||
{
|
||||
popMessage("You were blocked, please wait couple of minutes or contact JCE");
|
||||
jceLog->closeAll();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void loginHandler::popMessage(QString message)
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle("Error");
|
||||
msgBox.setText(message);
|
||||
msgBox.exec();
|
||||
msgBox.setFocus();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,29 +1,31 @@
|
|||
#ifndef LOGINHANDLER_H
|
||||
#define LOGINHANDLER_H
|
||||
#include <QString>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QPixmap>
|
||||
|
||||
#include "src/jce/jcelogin.h"
|
||||
|
||||
class loginHandler
|
||||
{
|
||||
public:
|
||||
loginHandler(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr);
|
||||
bool makeConnection();
|
||||
|
||||
private:
|
||||
|
||||
void popMessage(QString message);
|
||||
|
||||
|
||||
jceLogin *jceLog;
|
||||
|
||||
QLabel *statusLabelPtr;
|
||||
QLineEdit *pswdEditPtr;
|
||||
QLineEdit *usrnmEditPtr;
|
||||
};
|
||||
|
||||
#endif // LOGINHANDLER_H
|
||||
#ifndef LOGINHANDLER_H
|
||||
#define LOGINHANDLER_H
|
||||
#include <QString>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QPixmap>
|
||||
|
||||
#include "src/jce/jcelogin.h"
|
||||
#include "./src/data/savedata.h"
|
||||
|
||||
class loginHandler
|
||||
{
|
||||
public:
|
||||
loginHandler();
|
||||
void setPointers(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr);
|
||||
bool makeConnection();
|
||||
|
||||
private:
|
||||
|
||||
void popMessage(QString message);
|
||||
|
||||
|
||||
jceLogin *jceLog;
|
||||
|
||||
QLabel *statusLabelPtr;
|
||||
QLineEdit *pswdEditPtr;
|
||||
QLineEdit *usrnmEditPtr;
|
||||
};
|
||||
|
||||
#endif // LOGINHANDLER_H
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "mainscreen.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainScreen w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
#include "mainscreen.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainScreen w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
|
|
@ -1,268 +1,286 @@
|
|||
#include "mainscreen.h"
|
||||
#include "ui_mainscreen.h"
|
||||
|
||||
|
||||
MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScreen)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
this->setFixedSize(this->size()); //main not resizeable
|
||||
|
||||
//Login Tab
|
||||
ui->pswdLineEdit->setEchoMode((QLineEdit::Password));
|
||||
|
||||
//Status Bar
|
||||
ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };");
|
||||
ButtomStatusLabel = new QLabel(this);
|
||||
statusLabel = new QLabel(this);
|
||||
ui->statusBar->setMaximumSize(this->geometry().width(),StatusIconHeight);
|
||||
ui->statusBar->addPermanentWidget(ButtomStatusLabel,0);
|
||||
ui->statusBar->addPermanentWidget(statusLabel,1);
|
||||
setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
|
||||
|
||||
//Course and Setting Tab
|
||||
ui->CoursesTab->setDisabled(true);
|
||||
ui->SettingsTab->setDisabled(true);
|
||||
ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue));
|
||||
|
||||
|
||||
|
||||
//Pointer allocating
|
||||
this->jceLog = NULL;
|
||||
this->userLoginSetting = new user("","");
|
||||
this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting);
|
||||
|
||||
|
||||
updateDates();
|
||||
|
||||
}
|
||||
|
||||
MainScreen::~MainScreen()
|
||||
{
|
||||
delete userLoginSetting;
|
||||
delete jceLog;
|
||||
delete ui;
|
||||
}
|
||||
void MainScreen::on_ratesButton_clicked()
|
||||
{
|
||||
QTextEdit phrase;
|
||||
std::string pageString;
|
||||
if (this->jceLog != NULL)
|
||||
{
|
||||
if (jceLog->getGrades())
|
||||
{
|
||||
phrase.setText(QString::fromStdString(jceLog->getPage()));
|
||||
pageString = phrase.toPlainText().toStdString();
|
||||
courseTableMgr->setCoursesList(pageString);
|
||||
courseTableMgr->insertJceCoursesIntoTable();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainScreen::on_spinBoxFromYear_editingFinished()
|
||||
{
|
||||
if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value())
|
||||
{
|
||||
ui->spinBoxFromYear->setValue(ui->spinBoxToYear->value());
|
||||
ui->spinBoxFromYear->setFocus();
|
||||
updateDates();
|
||||
}
|
||||
else
|
||||
updateDates();
|
||||
}
|
||||
void MainScreen::on_spinBoxToYear_editingFinished()
|
||||
{
|
||||
if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value())
|
||||
{
|
||||
ui->spinBoxToYear->setValue(ui->spinBoxFromYear->value());
|
||||
ui->spinBoxToYear->setFocus();
|
||||
updateDates();
|
||||
}
|
||||
else
|
||||
updateDates();
|
||||
}
|
||||
void MainScreen::on_spinBoxFromSem_editingFinished()
|
||||
{
|
||||
if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value())
|
||||
{
|
||||
if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value())
|
||||
{
|
||||
ui->spinBoxFromSem->setValue(ui->spinBoxToSemester->value());
|
||||
ui->spinBoxFromSem->setFocus();
|
||||
}
|
||||
}
|
||||
updateDates();
|
||||
}
|
||||
void MainScreen::on_spinBoxToSemester_editingFinished()
|
||||
{
|
||||
if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value())
|
||||
{
|
||||
if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value())
|
||||
{
|
||||
ui->spinBoxToSemester->setValue(ui->spinBoxFromSem->value());
|
||||
ui->spinBoxToSemester->setFocus();
|
||||
}
|
||||
}
|
||||
updateDates();
|
||||
}
|
||||
|
||||
void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item)
|
||||
{
|
||||
if (this->courseTableMgr->changes(item->text(),item->row(),item->column()))
|
||||
ui->avgLCD->display(courseTableMgr->getAvg());
|
||||
else
|
||||
QMessageBox::critical(this,"Error","Missmatching data");
|
||||
}
|
||||
|
||||
void MainScreen::on_loginButton_clicked()
|
||||
{
|
||||
if (this->jceLog == NULL)
|
||||
uiSetConnectMode();
|
||||
else
|
||||
{
|
||||
if (jceLog->isLoginFlag() == true)
|
||||
uiSetDisconnectMode();
|
||||
else
|
||||
uiSetConnectMode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainScreen::on_checkBox_toggled(bool checked)
|
||||
{
|
||||
this->userLoginSetting->setInfluenceCourseOnly(checked);
|
||||
this->courseTableMgr->influnceCourseChanged(checked);
|
||||
}
|
||||
void MainScreen::on_usrnmLineEdit_editingFinished()
|
||||
{
|
||||
ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower());
|
||||
}
|
||||
void MainScreen::updateDates()
|
||||
{
|
||||
std::string fy,ty,fs,ts;
|
||||
fy = std::to_string(ui->spinBoxFromYear->value());
|
||||
ty = std::to_string(ui->spinBoxToYear->value());
|
||||
fs = std::to_string(ui->spinBoxFromSem->value());
|
||||
ts = std::to_string(ui->spinBoxToSemester->value());
|
||||
userLoginSetting->setDate(fy,fs,ty,ts);
|
||||
}
|
||||
|
||||
void MainScreen::uiSetDisconnectMode()
|
||||
{
|
||||
setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
|
||||
ui->usrnmLineEdit->setText("");
|
||||
ui->pswdLineEdit->setText("");
|
||||
ui->usrnmLineEdit->setEnabled(true);
|
||||
ui->pswdLineEdit->setEnabled(true);
|
||||
|
||||
delete jceLog;
|
||||
jceLog = NULL;
|
||||
ui->loginButton->setText("&Login");
|
||||
this->ui->ratesButton->setDisabled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
void MainScreen::uiSetConnectMode()
|
||||
{
|
||||
std::string page;
|
||||
|
||||
if (this->jceLog != NULL)
|
||||
delete jceLog;
|
||||
|
||||
string username;
|
||||
string password;
|
||||
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty()))
|
||||
{
|
||||
//add icon near to username and password to mark it
|
||||
return;
|
||||
}
|
||||
setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS);
|
||||
|
||||
username = ui->usrnmLineEdit->text().toStdString();
|
||||
password = ui->pswdLineEdit->text().toStdString();
|
||||
|
||||
ui->usrnmLineEdit->setDisabled(true);
|
||||
ui->pswdLineEdit->setDisabled(true);
|
||||
|
||||
userLoginSetting->setUsername(username);
|
||||
userLoginSetting->setPassword(password);
|
||||
|
||||
this->repaint();
|
||||
page = "connecting with username ";
|
||||
page = username;
|
||||
page += "and password: ";
|
||||
page += password;
|
||||
ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page));
|
||||
|
||||
jceLog = new jceLogin(userLoginSetting);
|
||||
this->loginHandel = new loginHandler(jceLog,statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit);
|
||||
|
||||
if (loginHandel->makeConnection() == true)
|
||||
{
|
||||
page = this->jceLog->getPage();
|
||||
ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page));
|
||||
setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN);
|
||||
ui->loginButton->setText("&Logout");
|
||||
this->ui->ratesButton->setEnabled(true);
|
||||
ui->CoursesTab->setEnabled(true);
|
||||
ui->SettingsTab->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
uiSetDisconnectMode();
|
||||
}
|
||||
}
|
||||
void MainScreen::setLabelConnectionStatus(jceLogin::jceStatus statusDescription)
|
||||
{
|
||||
QPixmap iconPix;
|
||||
switch (statusDescription)
|
||||
{
|
||||
|
||||
case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS:
|
||||
iconPix.load(":/icons/blueStatusIcon.png");
|
||||
statusLabel->setText("Connecting");
|
||||
break;
|
||||
case jceLogin::jceStatus::JCE_YOU_ARE_IN:
|
||||
iconPix.load(":/icons/greenStatusIcon.png");
|
||||
statusLabel->setText("Connected");
|
||||
break;
|
||||
default:
|
||||
iconPix.load(":/icons/redStatusIcon.png");
|
||||
statusLabel->setText("Disconnected");
|
||||
break;
|
||||
}
|
||||
ButtomStatusLabel->setPixmap(iconPix);
|
||||
|
||||
this->repaint();
|
||||
}
|
||||
void MainScreen::on_actionCredits_triggered()
|
||||
{
|
||||
QMessageBox::about(this, "About", "A tiny application to calculate your grades average. <br><br>"
|
||||
"This software is licensed under Qt5's <br>GNU LESSER GENERAL PUBLIC LICENSE V2<br>"
|
||||
"The source code is available at github:<br>"
|
||||
"<a href='https://github.com/liranbg/jceAverageCalculator'>jceAverageCalculator Repository</a>"
|
||||
"<br><br>This front end is Powered by <a href='https://github.com/liranbg/jceConnection'>Jce Connection</a><br><br>"
|
||||
"Made by:"
|
||||
"<ul>"
|
||||
"<li><a href='mailto:liranbg@gmail.com'>Liran Ben Gida</a></li>"
|
||||
"</ul>"
|
||||
"Thanks to: "
|
||||
"<ul>"
|
||||
"<li><a href='mailto:sagidayan@gmail.com'>Sagi Dayan</a></li>"
|
||||
"<li><a href='mailto:nadav2051@gmail.com'>Nadav Luzzato</a></li>"
|
||||
"</ul>");
|
||||
}
|
||||
|
||||
void MainScreen::on_clearTableButton_clicked()
|
||||
{
|
||||
|
||||
courseTableMgr->clearTable();
|
||||
ui->avgLCD->display(courseTableMgr->getAvg());
|
||||
}
|
||||
|
||||
void MainScreen::on_actionExit_triggered()
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#include "mainscreen.h"
|
||||
#include "ui_mainscreen.h"
|
||||
|
||||
|
||||
MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScreen)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
this->setFixedSize(this->size()); //main not resizeable
|
||||
|
||||
//Login Tab
|
||||
ui->pswdLineEdit->setEchoMode((QLineEdit::Password));
|
||||
|
||||
//Status Bar
|
||||
ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };");
|
||||
ButtomStatusLabel = new QLabel(this);
|
||||
statusLabel = new QLabel(this);
|
||||
ui->statusBar->setMaximumSize(this->geometry().width(),StatusIconHeight);
|
||||
ui->statusBar->addPermanentWidget(ButtomStatusLabel,0);
|
||||
ui->statusBar->addPermanentWidget(statusLabel,1);
|
||||
setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
|
||||
|
||||
//Course and Setting Tab
|
||||
ui->CoursesTab->setDisabled(true);
|
||||
ui->SettingsTab->setDisabled(true);
|
||||
ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue));
|
||||
|
||||
|
||||
|
||||
//Pointer allocating
|
||||
this->jceLog = NULL;
|
||||
this->userLoginSetting = new user("","");
|
||||
this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting);
|
||||
this->loginHandel = new loginHandler();
|
||||
|
||||
updateDates();
|
||||
|
||||
//check login File
|
||||
SaveData::init();
|
||||
if (SaveData::isSaved())
|
||||
{
|
||||
ui->usrnmLineEdit->setText(SaveData::getUsername());
|
||||
ui->pswdLineEdit->setText(SaveData::getPassword());
|
||||
ui->keepLogin->setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
MainScreen::~MainScreen()
|
||||
{
|
||||
delete userLoginSetting;
|
||||
delete jceLog;
|
||||
delete loginHandel;
|
||||
delete ui;
|
||||
}
|
||||
void MainScreen::on_ratesButton_clicked()
|
||||
{
|
||||
QTextEdit phrase;
|
||||
std::string pageString;
|
||||
if (this->jceLog != NULL)
|
||||
{
|
||||
if (jceLog->getGrades())
|
||||
{
|
||||
phrase.setText(QString::fromStdString(jceLog->getPage()));
|
||||
pageString = phrase.toPlainText().toStdString();
|
||||
courseTableMgr->setCoursesList(pageString);
|
||||
courseTableMgr->insertJceCoursesIntoTable();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainScreen::on_spinBoxFromYear_editingFinished()
|
||||
{
|
||||
if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value())
|
||||
{
|
||||
ui->spinBoxFromYear->setValue(ui->spinBoxToYear->value());
|
||||
ui->spinBoxFromYear->setFocus();
|
||||
updateDates();
|
||||
}
|
||||
else
|
||||
updateDates();
|
||||
}
|
||||
void MainScreen::on_spinBoxToYear_editingFinished()
|
||||
{
|
||||
if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value())
|
||||
{
|
||||
ui->spinBoxToYear->setValue(ui->spinBoxFromYear->value());
|
||||
ui->spinBoxToYear->setFocus();
|
||||
updateDates();
|
||||
}
|
||||
else
|
||||
updateDates();
|
||||
}
|
||||
void MainScreen::on_spinBoxFromSem_editingFinished()
|
||||
{
|
||||
if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value())
|
||||
{
|
||||
if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value())
|
||||
{
|
||||
ui->spinBoxFromSem->setValue(ui->spinBoxToSemester->value());
|
||||
ui->spinBoxFromSem->setFocus();
|
||||
}
|
||||
}
|
||||
updateDates();
|
||||
}
|
||||
void MainScreen::on_spinBoxToSemester_editingFinished()
|
||||
{
|
||||
if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value())
|
||||
{
|
||||
if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value())
|
||||
{
|
||||
ui->spinBoxToSemester->setValue(ui->spinBoxFromSem->value());
|
||||
ui->spinBoxToSemester->setFocus();
|
||||
}
|
||||
}
|
||||
updateDates();
|
||||
}
|
||||
|
||||
void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item)
|
||||
{
|
||||
if (this->courseTableMgr->changes(item->text(),item->row(),item->column()))
|
||||
ui->avgLCD->display(courseTableMgr->getAvg());
|
||||
else
|
||||
QMessageBox::critical(this,"Error","Missmatching data");
|
||||
}
|
||||
|
||||
void MainScreen::on_loginButton_clicked()
|
||||
{
|
||||
if (this->jceLog == NULL)
|
||||
uiSetConnectMode();
|
||||
else
|
||||
{
|
||||
if (jceLog->isLoginFlag() == true)
|
||||
uiSetDisconnectMode();
|
||||
else
|
||||
uiSetConnectMode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainScreen::on_checkBox_toggled(bool checked)
|
||||
{
|
||||
this->userLoginSetting->setInfluenceCourseOnly(checked);
|
||||
this->courseTableMgr->influnceCourseChanged(checked);
|
||||
}
|
||||
void MainScreen::on_usrnmLineEdit_editingFinished()
|
||||
{
|
||||
ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower());
|
||||
}
|
||||
void MainScreen::updateDates()
|
||||
{
|
||||
std::string fy,ty,fs,ts;
|
||||
fy = std::to_string(ui->spinBoxFromYear->value());
|
||||
ty = std::to_string(ui->spinBoxToYear->value());
|
||||
fs = std::to_string(ui->spinBoxFromSem->value());
|
||||
ts = std::to_string(ui->spinBoxToSemester->value());
|
||||
userLoginSetting->setDate(fy,fs,ty,ts);
|
||||
}
|
||||
|
||||
void MainScreen::uiSetDisconnectMode()
|
||||
{
|
||||
setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
|
||||
ui->usrnmLineEdit->setText("");
|
||||
ui->pswdLineEdit->setText("");
|
||||
ui->usrnmLineEdit->setEnabled(true);
|
||||
ui->pswdLineEdit->setEnabled(true);
|
||||
|
||||
delete jceLog;
|
||||
jceLog = NULL;
|
||||
ui->loginButton->setText("&Login");
|
||||
this->ui->ratesButton->setDisabled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
void MainScreen::uiSetConnectMode() //fix before distrbute
|
||||
{
|
||||
std::string page;
|
||||
|
||||
if (this->jceLog != NULL)
|
||||
delete jceLog;
|
||||
|
||||
string username;
|
||||
string password;
|
||||
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty()))
|
||||
{
|
||||
//add icon near to username and password to mark it
|
||||
return;
|
||||
}
|
||||
setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS);
|
||||
|
||||
username = ui->usrnmLineEdit->text().toStdString();
|
||||
password = ui->pswdLineEdit->text().toStdString();
|
||||
|
||||
ui->usrnmLineEdit->setDisabled(true);
|
||||
ui->pswdLineEdit->setDisabled(true);
|
||||
|
||||
userLoginSetting->setUsername(username);
|
||||
userLoginSetting->setPassword(password);
|
||||
|
||||
this->repaint();
|
||||
page = "connecting with username ";
|
||||
page = username;
|
||||
page += "and password: ";
|
||||
page += password;
|
||||
ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page));
|
||||
|
||||
jceLog = new jceLogin(userLoginSetting);
|
||||
this->loginHandel->setPointers(jceLog,statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit);
|
||||
|
||||
if (loginHandel->makeConnection() == true)
|
||||
{
|
||||
page = this->jceLog->getPage();
|
||||
ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page));
|
||||
setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN);
|
||||
ui->loginButton->setText("&Logout");
|
||||
this->ui->ratesButton->setEnabled(true);
|
||||
ui->CoursesTab->setEnabled(true);
|
||||
ui->SettingsTab->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
uiSetDisconnectMode();
|
||||
}
|
||||
}
|
||||
void MainScreen::setLabelConnectionStatus(jceLogin::jceStatus statusDescription)
|
||||
{
|
||||
QPixmap iconPix;
|
||||
switch (statusDescription)
|
||||
{
|
||||
|
||||
case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS:
|
||||
iconPix.load(":/icons/blueStatusIcon.png");
|
||||
statusLabel->setText("Connecting");
|
||||
break;
|
||||
case jceLogin::jceStatus::JCE_YOU_ARE_IN:
|
||||
iconPix.load(":/icons/greenStatusIcon.png");
|
||||
statusLabel->setText("Connected");
|
||||
break;
|
||||
default:
|
||||
iconPix.load(":/icons/redStatusIcon.png");
|
||||
statusLabel->setText("Disconnected");
|
||||
break;
|
||||
}
|
||||
ButtomStatusLabel->setPixmap(iconPix);
|
||||
|
||||
this->repaint();
|
||||
}
|
||||
void MainScreen::on_actionCredits_triggered()
|
||||
{
|
||||
QMessageBox::about(this, "About", "A tiny application to calculate your grades average. <br><br>"
|
||||
"This software is licensed under Qt5's <br>GNU LESSER GENERAL PUBLIC LICENSE V2<br>"
|
||||
"The source code is available at github:<br>"
|
||||
"<a href='https://github.com/liranbg/jceAverageCalculator'>jceAverageCalculator Repository</a>"
|
||||
"<br><br>This front end is Powered by <a href='https://github.com/liranbg/jceConnection'>Jce Connection</a><br><br>"
|
||||
"Made by:"
|
||||
"<ul>"
|
||||
"<li><a href='mailto:liranbg@gmail.com'>Liran Ben Gida</a></li>"
|
||||
"</ul>"
|
||||
"Thanks to: "
|
||||
"<ul>"
|
||||
"<li><a href='mailto:sagidayan@gmail.com'>Sagi Dayan</a></li>"
|
||||
"<li><a href='mailto:nadav2051@gmail.com'>Nadav Luzzato</a></li>"
|
||||
"</ul>");
|
||||
}
|
||||
|
||||
void MainScreen::on_clearTableButton_clicked()
|
||||
{
|
||||
|
||||
courseTableMgr->clearTable();
|
||||
ui->avgLCD->display(courseTableMgr->getAvg());
|
||||
}
|
||||
|
||||
void MainScreen::on_actionExit_triggered()
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
void MainScreen::on_keepLogin_clicked()
|
||||
{
|
||||
if (ui->keepLogin->isChecked())
|
||||
SaveData::save(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text());
|
||||
|
||||
else
|
||||
SaveData::deleteData();
|
||||
}
|
||||
|
|
|
@ -1,78 +1,80 @@
|
|||
#ifndef MAINSCREEN_H
|
||||
#define MAINSCREEN_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QApplication>
|
||||
#include <QString>
|
||||
#include <QMessageBox>
|
||||
#include <QTextEdit>
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#include "src/grades/GradePage.h"
|
||||
#include "src/jce/jcelogin.h"
|
||||
#include "coursestablemanager.h"
|
||||
#include "loginhandler.h"
|
||||
|
||||
#define StatusIconHeight 35
|
||||
namespace Ui {
|
||||
class MainScreen;
|
||||
}
|
||||
|
||||
class MainScreen : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainScreen(QWidget *parent = 0);
|
||||
~MainScreen();
|
||||
|
||||
private slots:
|
||||
|
||||
void on_ratesButton_clicked();
|
||||
|
||||
void on_spinBoxFromYear_editingFinished();
|
||||
|
||||
void on_spinBoxFromSem_editingFinished();
|
||||
|
||||
void on_spinBoxToYear_editingFinished();
|
||||
|
||||
void on_spinBoxToSemester_editingFinished();
|
||||
|
||||
void on_loginButton_clicked();
|
||||
|
||||
void on_checkBox_toggled(bool checked);
|
||||
|
||||
void on_usrnmLineEdit_editingFinished();
|
||||
|
||||
void on_actionCredits_triggered();
|
||||
|
||||
void on_clearTableButton_clicked();
|
||||
|
||||
void on_actionExit_triggered();
|
||||
|
||||
void on_coursesTable_itemChanged(QTableWidgetItem *item);
|
||||
|
||||
private:
|
||||
|
||||
void updateDates();
|
||||
void uiSetDisconnectMode();
|
||||
void uiSetConnectMode();
|
||||
void setLabelConnectionStatus(jceLogin::jceStatus statusDescription);
|
||||
|
||||
Ui::MainScreen *ui;
|
||||
|
||||
jceLogin *jceLog;
|
||||
user *userLoginSetting;
|
||||
|
||||
coursesTableManager *courseTableMgr;
|
||||
loginHandler *loginHandel;
|
||||
|
||||
QLabel *ButtomStatusLabel;
|
||||
QLabel *statusLabel;
|
||||
|
||||
};
|
||||
|
||||
#endif // MAINSCREEN_H
|
||||
#ifndef MAINSCREEN_H
|
||||
#define MAINSCREEN_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QApplication>
|
||||
#include <QString>
|
||||
#include <QMessageBox>
|
||||
#include <QTextEdit>
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#include "src/grades/GradePage.h"
|
||||
#include "src/jce/jcelogin.h"
|
||||
#include "coursestablemanager.h"
|
||||
#include "loginhandler.h"
|
||||
|
||||
#define StatusIconHeight 35
|
||||
namespace Ui {
|
||||
class MainScreen;
|
||||
}
|
||||
|
||||
class MainScreen : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainScreen(QWidget *parent = 0);
|
||||
~MainScreen();
|
||||
|
||||
private slots:
|
||||
|
||||
void on_ratesButton_clicked();
|
||||
|
||||
void on_spinBoxFromYear_editingFinished();
|
||||
|
||||
void on_spinBoxFromSem_editingFinished();
|
||||
|
||||
void on_spinBoxToYear_editingFinished();
|
||||
|
||||
void on_spinBoxToSemester_editingFinished();
|
||||
|
||||
void on_loginButton_clicked();
|
||||
|
||||
void on_checkBox_toggled(bool checked);
|
||||
|
||||
void on_usrnmLineEdit_editingFinished();
|
||||
|
||||
void on_actionCredits_triggered();
|
||||
|
||||
void on_clearTableButton_clicked();
|
||||
|
||||
void on_actionExit_triggered();
|
||||
|
||||
void on_coursesTable_itemChanged(QTableWidgetItem *item);
|
||||
|
||||
void on_keepLogin_clicked();
|
||||
|
||||
private:
|
||||
|
||||
void updateDates();
|
||||
void uiSetDisconnectMode();
|
||||
void uiSetConnectMode();
|
||||
void setLabelConnectionStatus(jceLogin::jceStatus statusDescription);
|
||||
|
||||
Ui::MainScreen *ui;
|
||||
|
||||
jceLogin *jceLog;
|
||||
user *userLoginSetting;
|
||||
|
||||
coursesTableManager *courseTableMgr;
|
||||
loginHandler *loginHandel;
|
||||
|
||||
QLabel *ButtomStatusLabel;
|
||||
QLabel *statusLabel;
|
||||
|
||||
};
|
||||
|
||||
#endif // MAINSCREEN_H
|
||||
|
|
1480
main/mainscreen.ui
1480
main/mainscreen.ui
File diff suppressed because it is too large
Load diff
|
@ -1,8 +1,8 @@
|
|||
<RCC>
|
||||
<qresource prefix="/icons">
|
||||
<file>blueStatusIcon.png</file>
|
||||
<file>greenStatusIcon.png</file>
|
||||
<file>redStatusIcon.png</file>
|
||||
<file>icon.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
<RCC>
|
||||
<qresource prefix="/icons">
|
||||
<file>blueStatusIcon.png</file>
|
||||
<file>greenStatusIcon.png</file>
|
||||
<file>redStatusIcon.png</file>
|
||||
<file>icon.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -1,37 +1,66 @@
|
|||
#include "qtsslsocket.h"
|
||||
|
||||
qtsslsocket::qtsslsocket(std::string server,int port) : flag(false)
|
||||
|
||||
bool qtsslsocket::makeConnect(std::string server,int port)
|
||||
{
|
||||
if (this->socket != NULL) //already connected?
|
||||
{
|
||||
socket->close();
|
||||
socket = NULL;
|
||||
}
|
||||
|
||||
if (this->socket == NULL) //if was connected, we deleted it and remake it
|
||||
socket = new QSslSocket();
|
||||
|
||||
|
||||
if (this->socket != NULL) //now we will connect it to host
|
||||
{
|
||||
socket->connectToHostEncrypted(server.c_str(), port);
|
||||
if (socket->waitForEncrypted()) //waiting for encryption
|
||||
flag = true;
|
||||
}
|
||||
|
||||
return isCon(); //return true/false upon isCon function
|
||||
}
|
||||
|
||||
qtsslsocket::qtsslsocket() : flag(false)
|
||||
{
|
||||
socket = new QSslSocket();
|
||||
socket->connectToHostEncrypted(server.c_str(), port);
|
||||
if (socket->waitForEncrypted())
|
||||
flag = true;
|
||||
}
|
||||
|
||||
|
||||
qtsslsocket::~qtsslsocket() {
|
||||
socket->close();
|
||||
socket = NULL;
|
||||
}
|
||||
|
||||
bool qtsslsocket::isCon()
|
||||
{
|
||||
return flag;
|
||||
return ((flag) && (this->socket != NULL));
|
||||
|
||||
}
|
||||
|
||||
//need to fix the method
|
||||
bool qtsslsocket::send(std::string str)
|
||||
{
|
||||
int status;
|
||||
bool flag = isCon();
|
||||
if (flag)
|
||||
this->socket->write(str.c_str());
|
||||
|
||||
if (flag) //if connected
|
||||
{
|
||||
status = socket->write(str.c_str(),str.length());
|
||||
while (socket->waitForBytesWritten());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
bool qtsslsocket::recieve(std::string &str)
|
||||
{
|
||||
bool flag = false;
|
||||
QString s = "";
|
||||
while (socket->waitForReadyRead(milisTimeOut))
|
||||
s.append((socket->readAll().data()));
|
||||
s.append(socket->readAll());
|
||||
|
||||
str = s.toStdString();
|
||||
if (s.size() > 0)
|
||||
flag = true;
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
|
|
@ -7,24 +7,24 @@
|
|||
#include <QString>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#define milisTimeOut 5000
|
||||
#define milisTimeOut 3000
|
||||
|
||||
class qtsslsocket : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
qtsslsocket(std::string server,int port);
|
||||
~qtsslsocket() {
|
||||
socket->close();
|
||||
socket = NULL;
|
||||
}
|
||||
qtsslsocket();
|
||||
~qtsslsocket();
|
||||
|
||||
bool makeConnect(std::string server,int port);
|
||||
bool isCon();
|
||||
bool send(std::string str);
|
||||
bool recieve(std::string &str);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
QSslSocket *socket;
|
||||
bool flag;
|
||||
};
|
||||
|
|
|
@ -1,200 +1,200 @@
|
|||
#include "savedata.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Checks the status tag in the file
|
||||
* @return boolean the status
|
||||
*/
|
||||
bool SaveData::isSaved()
|
||||
{
|
||||
QString status;
|
||||
QFile* file = new QFile(FILE_NAME);
|
||||
/* Opening file for read */
|
||||
if(file->open(QIODevice::ReadOnly|QIODevice::Text))
|
||||
{
|
||||
status = getValViaTag("status", file);
|
||||
if(status == "true")
|
||||
{
|
||||
file->close(); //close & return
|
||||
return true;
|
||||
}
|
||||
return false; //close & return
|
||||
file->close();
|
||||
}
|
||||
/* If Faild to open */
|
||||
std::cout << "Faild To Accsess file: " << FILE_NAME << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This Function will modify the file, and save the data.
|
||||
* @param username - QString
|
||||
* @param password - QString
|
||||
* @return true if saved - false if error
|
||||
*/
|
||||
bool SaveData::save(QString username, QString password)
|
||||
{
|
||||
std::cout << "Trying to save data..." << std::endl;
|
||||
QFile file(FILE_NAME);
|
||||
if(!file.open(QIODevice::WriteOnly|QIODevice::Text))
|
||||
return false; /* IO Error! */
|
||||
QTextStream output(&file);
|
||||
QString hash_pass = hashPassword(password);
|
||||
output << "[status]true[/]\n[username]"<<username<<"[/]\n"<<"[password]"<<hash_pass<<"[/]"; //Un Hashed Password in string!
|
||||
file.close();
|
||||
std::cout << "Saved!" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deletes the data from file, and sets status tag to false.
|
||||
* @return true if success
|
||||
*/
|
||||
bool SaveData::deleteData()
|
||||
{
|
||||
QFile file(FILE_NAME);
|
||||
if(!file.open(QIODevice::WriteOnly|QIODevice::Text))
|
||||
return false; /* IO Error! */
|
||||
QTextStream output(&file);
|
||||
output << DEFAULT_DATA_EMPTY;
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief username getter
|
||||
* @return QString - username
|
||||
*/
|
||||
QString SaveData::getUsername()
|
||||
{
|
||||
QString username = "";
|
||||
QFile* file = new QFile(FILE_NAME);
|
||||
|
||||
/* Opening file for read */
|
||||
if(file->open(QIODevice::ReadOnly|QIODevice::Text))
|
||||
username = getValViaTag("username", file);
|
||||
file->close();
|
||||
return username;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief getter for password
|
||||
* @return QString - password
|
||||
*/
|
||||
QString SaveData::getPassword()
|
||||
{
|
||||
QString pass = "";
|
||||
QFile* file = new QFile(FILE_NAME);
|
||||
/* Opening file for read */
|
||||
if(file->open(QIODevice::ReadOnly|QIODevice::Text))
|
||||
pass = getValViaTag("password", file);
|
||||
file->close();
|
||||
pass = deHashPasword(pass);
|
||||
return pass;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This is A functions that will init the tags file.
|
||||
* if it exist - do nothing
|
||||
* if there is no file, it will create it and run the deleteData function
|
||||
* so tags will be set.
|
||||
*/
|
||||
void SaveData::init()
|
||||
{
|
||||
QFile file(FILE_NAME);
|
||||
if(!file.exists())
|
||||
{
|
||||
file.open(QIODevice::ReadWrite | QIODevice::Text);
|
||||
file.close();
|
||||
deleteData();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function will return the vale of a given tag name.
|
||||
* NOTE: valid tag names are : "status", "username", "password"
|
||||
* if tag is invalid - will return "" - an empty QString!
|
||||
* @param tag - QString, the tag name
|
||||
* @param file - a QFile pointer
|
||||
* @return QString - the value in tag
|
||||
* NOTE: if NULL value, or an invalid tag name -> return "" (empty QString!)
|
||||
*/
|
||||
QString SaveData::getValViaTag(QString tag, QFile* file)
|
||||
{
|
||||
QString val, line , tmpTag;
|
||||
QTextStream textStream( file);
|
||||
while((line = textStream.readLine()) != NULL)
|
||||
{
|
||||
std::cout << "DEBUG: line => " << line.toStdString() << std::endl;
|
||||
for(int i = 0 ; i< line.length() ;++i)
|
||||
{
|
||||
if(line[i] == '[' && line[i+1] != '/') //get open tag at begining of line and not end of tag ("[/")
|
||||
{
|
||||
i++;
|
||||
tmpTag = line.mid(i, tag.length());
|
||||
if(tmpTag == tag)
|
||||
{
|
||||
i+= tag.length()+1; // i is now right after '['
|
||||
int j = i;
|
||||
while(line[j] != '[')// put j at the end of the value
|
||||
j++;
|
||||
/* Then... the value is :*/
|
||||
val = line.mid(i, j-i);
|
||||
std::cout << "DEBUG: ["<<tag.toStdString()<<"]"<<val.toStdString()<<"[/]"<<std::endl;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""; //this will be as NULL
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function will provide the user the most basic security of the stored password.
|
||||
* it is NOT an encryption! it will store every char of the password as ascii encoded,
|
||||
* separated by "-" for the deHsh func.
|
||||
* @param pass - a QString to "hash"
|
||||
* @return QString - The "hashed" password
|
||||
*/
|
||||
QString SaveData::hashPassword(QString pass)
|
||||
{
|
||||
QString hash="";
|
||||
int code;
|
||||
for(QChar c : pass)
|
||||
{
|
||||
code = (int)c.toLatin1();
|
||||
hash.append(QString::number(code));
|
||||
hash.append("-");
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function will "dehash" the "hashed" password.
|
||||
* uses standard c string.h strtok with the "-" as the choping points.
|
||||
* builds a QString from the ascii.
|
||||
* @param pass - The hashed password
|
||||
* @return QString - password uncoded
|
||||
*/
|
||||
QString SaveData::deHashPasword(QString pass)
|
||||
{
|
||||
char* cpyPass = strdup(pass.toStdString().c_str());
|
||||
char* tok;
|
||||
char* ch;
|
||||
int val;
|
||||
QString password;
|
||||
tok = strtok(cpyPass,"-");
|
||||
while (tok != NULL)
|
||||
{
|
||||
ch = tok;
|
||||
val = atoi(ch);
|
||||
password.append(val);
|
||||
tok = strtok(NULL, "-");
|
||||
}
|
||||
return password;
|
||||
}
|
||||
#include "savedata.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Checks the status tag in the file
|
||||
* @return boolean the status
|
||||
*/
|
||||
bool SaveData::isSaved()
|
||||
{
|
||||
QString status;
|
||||
QFile* file = new QFile(FILE_NAME);
|
||||
/* Opening file for read */
|
||||
if(file->open(QIODevice::ReadOnly|QIODevice::Text))
|
||||
{
|
||||
status = getValViaTag("status", file);
|
||||
if(status == "true")
|
||||
{
|
||||
file->close(); //close & return
|
||||
return true;
|
||||
}
|
||||
return false; //close & return
|
||||
file->close();
|
||||
}
|
||||
/* If Faild to open */
|
||||
std::cout << "Faild To Accsess file: " << FILE_NAME << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This Function will modify the file, and save the data.
|
||||
* @param username - QString
|
||||
* @param password - QString
|
||||
* @return true if saved - false if error
|
||||
*/
|
||||
bool SaveData::save(QString username, QString password)
|
||||
{
|
||||
std::cout << "Trying to save data..." << std::endl;
|
||||
QFile file(FILE_NAME);
|
||||
if(!file.open(QIODevice::WriteOnly|QIODevice::Text))
|
||||
return false; /* IO Error! */
|
||||
QTextStream output(&file);
|
||||
QString hash_pass = hashPassword(password);
|
||||
output << "[status]true[/]\n[username]"<<username<<"[/]\n"<<"[password]"<<hash_pass<<"[/]"; //Un Hashed Password in string!
|
||||
file.close();
|
||||
std::cout << "Saved!" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deletes the data from file, and sets status tag to false.
|
||||
* @return true if success
|
||||
*/
|
||||
bool SaveData::deleteData()
|
||||
{
|
||||
QFile file(FILE_NAME);
|
||||
if(!file.open(QIODevice::WriteOnly|QIODevice::Text))
|
||||
return false; /* IO Error! */
|
||||
QTextStream output(&file);
|
||||
output << DEFAULT_DATA_EMPTY;
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief username getter
|
||||
* @return QString - username
|
||||
*/
|
||||
QString SaveData::getUsername()
|
||||
{
|
||||
QString username = "";
|
||||
QFile* file = new QFile(FILE_NAME);
|
||||
|
||||
/* Opening file for read */
|
||||
if(file->open(QIODevice::ReadOnly|QIODevice::Text))
|
||||
username = getValViaTag("username", file);
|
||||
file->close();
|
||||
return username;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief getter for password
|
||||
* @return QString - password
|
||||
*/
|
||||
QString SaveData::getPassword()
|
||||
{
|
||||
QString pass = "";
|
||||
QFile* file = new QFile(FILE_NAME);
|
||||
/* Opening file for read */
|
||||
if(file->open(QIODevice::ReadOnly|QIODevice::Text))
|
||||
pass = getValViaTag("password", file);
|
||||
file->close();
|
||||
pass = deHashPasword(pass);
|
||||
return pass;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This is A functions that will init the tags file.
|
||||
* if it exist - do nothing
|
||||
* if there is no file, it will create it and run the deleteData function
|
||||
* so tags will be set.
|
||||
*/
|
||||
void SaveData::init()
|
||||
{
|
||||
QFile file(FILE_NAME);
|
||||
if(!file.exists())
|
||||
{
|
||||
file.open(QIODevice::ReadWrite | QIODevice::Text);
|
||||
file.close();
|
||||
deleteData();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function will return the vale of a given tag name.
|
||||
* NOTE: valid tag names are : "status", "username", "password"
|
||||
* if tag is invalid - will return "" - an empty QString!
|
||||
* @param tag - QString, the tag name
|
||||
* @param file - a QFile pointer
|
||||
* @return QString - the value in tag
|
||||
* NOTE: if NULL value, or an invalid tag name -> return "" (empty QString!)
|
||||
*/
|
||||
QString SaveData::getValViaTag(QString tag, QFile* file)
|
||||
{
|
||||
QString val, line , tmpTag;
|
||||
QTextStream textStream( file);
|
||||
while((line = textStream.readLine()) != NULL)
|
||||
{
|
||||
std::cout << "DEBUG: line => " << line.toStdString() << std::endl;
|
||||
for(int i = 0 ; i< line.length() ;++i)
|
||||
{
|
||||
if(line[i] == '[' && line[i+1] != '/') //get open tag at begining of line and not end of tag ("[/")
|
||||
{
|
||||
i++;
|
||||
tmpTag = line.mid(i, tag.length());
|
||||
if(tmpTag == tag)
|
||||
{
|
||||
i+= tag.length()+1; // i is now right after '['
|
||||
int j = i;
|
||||
while(line[j] != '[')// put j at the end of the value
|
||||
j++;
|
||||
/* Then... the value is :*/
|
||||
val = line.mid(i, j-i);
|
||||
std::cout << "DEBUG: ["<<tag.toStdString()<<"]"<<val.toStdString()<<"[/]"<<std::endl;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""; //this will be as NULL
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function will provide the user the most basic security of the stored password.
|
||||
* it is NOT an encryption! it will store every char of the password as ascii encoded,
|
||||
* separated by "-" for the deHsh func.
|
||||
* @param pass - a QString to "hash"
|
||||
* @return QString - The "hashed" password
|
||||
*/
|
||||
QString SaveData::hashPassword(QString pass)
|
||||
{
|
||||
QString hash="";
|
||||
int code;
|
||||
for(QChar c : pass)
|
||||
{
|
||||
code = (int)c.toLatin1();
|
||||
hash.append(QString::number(code));
|
||||
hash.append("-");
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function will "dehash" the "hashed" password.
|
||||
* uses standard c string.h strtok with the "-" as the choping points.
|
||||
* builds a QString from the ascii.
|
||||
* @param pass - The hashed password
|
||||
* @return QString - password uncoded
|
||||
*/
|
||||
QString SaveData::deHashPasword(QString pass)
|
||||
{
|
||||
char* cpyPass = strdup(pass.toStdString().c_str());
|
||||
char* tok;
|
||||
char* ch;
|
||||
int val;
|
||||
QString password;
|
||||
tok = strtok(cpyPass,"-");
|
||||
while (tok != NULL)
|
||||
{
|
||||
ch = tok;
|
||||
val = atoi(ch);
|
||||
password.append(val);
|
||||
tok = strtok(NULL, "-");
|
||||
}
|
||||
return password;
|
||||
}
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
#ifndef SAVEDATA_H
|
||||
#define SAVEDATA_H
|
||||
|
||||
/**
|
||||
* SaveData Class
|
||||
* --------------------------------------
|
||||
*
|
||||
* all functions in this class are static!
|
||||
* no need to create an object!
|
||||
*
|
||||
* provides all the needed functions
|
||||
* for saving user data for JCE login.
|
||||
*
|
||||
* the class will enteract with a file formated by tags for storing the valus.
|
||||
* the file format is as sutch:
|
||||
*
|
||||
* [status]Status Value[/]
|
||||
* [username]usernaem vale[/]
|
||||
* [password]hashed(not really) password vale[/]
|
||||
*
|
||||
* the class will create a file if not exists by calling Save Data::init() function.
|
||||
*
|
||||
* for more info about functions - see implantation
|
||||
*/
|
||||
|
||||
/* QT libs */
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
/* C/C++ libs */
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
|
||||
#define FILE_NAME "JAC_DB.dat"
|
||||
#define DEFAULT_DATA_EMPTY "[status]false[/]\n[username][/]\n[password][/]"
|
||||
|
||||
class SaveData
|
||||
{
|
||||
public:
|
||||
bool static isSaved();
|
||||
bool static save(QString username, QString password);
|
||||
bool static deleteData();
|
||||
QString static getUsername();
|
||||
QString static getPassword();
|
||||
void static init();
|
||||
private:
|
||||
QString static getValViaTag(QString tag, QFile *file);
|
||||
QString static hashPassword(QString pass);
|
||||
QString static deHashPasword(QString pass);
|
||||
};
|
||||
|
||||
#endif // SAVEDATA_H
|
||||
#ifndef SAVEDATA_H
|
||||
#define SAVEDATA_H
|
||||
|
||||
/**
|
||||
* SaveData Class
|
||||
* --------------------------------------
|
||||
*
|
||||
* all functions in this class are static!
|
||||
* no need to create an object!
|
||||
*
|
||||
* provides all the needed functions
|
||||
* for saving user data for JCE login.
|
||||
*
|
||||
* the class will enteract with a file formated by tags for storing the valus.
|
||||
* the file format is as sutch:
|
||||
*
|
||||
* [status]Status Value[/]
|
||||
* [username]usernaem vale[/]
|
||||
* [password]hashed(not really) password vale[/]
|
||||
*
|
||||
* the class will create a file if not exists by calling Save Data::init() function.
|
||||
*
|
||||
* for more info about functions - see implantation
|
||||
*/
|
||||
|
||||
/* QT libs */
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
/* C/C++ libs */
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
|
||||
#define FILE_NAME "JAC_DB.dat"
|
||||
#define DEFAULT_DATA_EMPTY "[status]false[/]\n[username][/]\n[password][/]"
|
||||
|
||||
class SaveData
|
||||
{
|
||||
public:
|
||||
bool static isSaved();
|
||||
bool static save(QString username, QString password);
|
||||
bool static deleteData();
|
||||
QString static getUsername();
|
||||
QString static getPassword();
|
||||
void static init();
|
||||
private:
|
||||
QString static getValViaTag(QString tag, QFile *file);
|
||||
QString static hashPassword(QString pass);
|
||||
QString static deHashPasword(QString pass);
|
||||
};
|
||||
|
||||
#endif // SAVEDATA_H
|
||||
|
|
|
@ -1,55 +1,55 @@
|
|||
#include "Course.h"
|
||||
|
||||
Course::Course(int serial, std::string name, std::string type, double points, double hours, double grade, std::string additions)
|
||||
{
|
||||
this->serialNum = serial;
|
||||
this->name = name;
|
||||
this->type = type;
|
||||
this->points = points;
|
||||
this->hours = hours;
|
||||
this->grade = grade;
|
||||
this->additions = additions;
|
||||
}
|
||||
|
||||
Course::~Course()
|
||||
{
|
||||
|
||||
}
|
||||
double Course::getGrade() const
|
||||
{
|
||||
double noGrade = NO_GRADE_YET;
|
||||
if (grade == noGrade)
|
||||
return 0;
|
||||
else
|
||||
return this->grade;
|
||||
}
|
||||
|
||||
void Course::setName(std::string name)
|
||||
{
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
void Course::setType(std::string type)
|
||||
{
|
||||
this->type = type;
|
||||
}
|
||||
|
||||
void Course::setPoints(double points)
|
||||
{
|
||||
this->points=points;
|
||||
}
|
||||
|
||||
void Course::setHours(double hours)
|
||||
{
|
||||
this->hours = hours;
|
||||
}
|
||||
|
||||
void Course::setGrade(double grade)
|
||||
{
|
||||
this->grade = grade;
|
||||
}
|
||||
|
||||
void Course::setAdditions(std::string additions)
|
||||
{
|
||||
this->additions = additions;
|
||||
}
|
||||
#include "Course.h"
|
||||
|
||||
Course::Course(int serial, std::string name, std::string type, double points, double hours, double grade, std::string additions)
|
||||
{
|
||||
this->serialNum = serial;
|
||||
this->name = name;
|
||||
this->type = type;
|
||||
this->points = points;
|
||||
this->hours = hours;
|
||||
this->grade = grade;
|
||||
this->additions = additions;
|
||||
}
|
||||
|
||||
Course::~Course()
|
||||
{
|
||||
|
||||
}
|
||||
double Course::getGrade() const
|
||||
{
|
||||
double noGrade = NO_GRADE_YET;
|
||||
if (grade == noGrade)
|
||||
return 0;
|
||||
else
|
||||
return this->grade;
|
||||
}
|
||||
|
||||
void Course::setName(std::string name)
|
||||
{
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
void Course::setType(std::string type)
|
||||
{
|
||||
this->type = type;
|
||||
}
|
||||
|
||||
void Course::setPoints(double points)
|
||||
{
|
||||
this->points=points;
|
||||
}
|
||||
|
||||
void Course::setHours(double hours)
|
||||
{
|
||||
this->hours = hours;
|
||||
}
|
||||
|
||||
void Course::setGrade(double grade)
|
||||
{
|
||||
this->grade = grade;
|
||||
}
|
||||
|
||||
void Course::setAdditions(std::string additions)
|
||||
{
|
||||
this->additions = additions;
|
||||
}
|
||||
|
|
|
@ -1,64 +1,64 @@
|
|||
#ifndef COURSE_H
|
||||
#define COURSE_H
|
||||
|
||||
/* This Code Made By Sagi Dayan
|
||||
* SagiDayan@gmail.com
|
||||
*
|
||||
* Minor changes has been made by Liran Ben Gida
|
||||
* LiranBG@gmail.com
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
|
||||
#define COURSE_FIELDS 7
|
||||
#define NO_GRADE_YET 101;
|
||||
|
||||
|
||||
class Course{
|
||||
|
||||
public:
|
||||
enum CourseScheme
|
||||
{
|
||||
SERIAL,
|
||||
NAME,
|
||||
TYPE,
|
||||
POINTS,
|
||||
HOURS,
|
||||
GRADE,
|
||||
ADDITION
|
||||
};
|
||||
|
||||
Course(int serial,std::string name, std::string type, double points, double hours, double grade, std::string additions);
|
||||
~Course();
|
||||
|
||||
int getSerialNum() const {return this->serialNum;}
|
||||
std::string getName() const {return this->name;}
|
||||
std::string getType() const {return this->type;}
|
||||
double getPoints() const {return this->points;}
|
||||
double getHours() const {return this->hours;}
|
||||
double getGrade() const ;
|
||||
std::string getAddidtions() const {return this->additions;}
|
||||
|
||||
void setName(std::string name);
|
||||
void setType(std::string type);
|
||||
void setPoints(double points);
|
||||
void setHours(double hours);
|
||||
void setGrade(double grade);
|
||||
void setAdditions(std::string additions);
|
||||
|
||||
private:
|
||||
|
||||
int serialNum;
|
||||
std::string name;
|
||||
std::string type;
|
||||
double points;
|
||||
double hours;
|
||||
double grade;
|
||||
std::string additions;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#ifndef COURSE_H
|
||||
#define COURSE_H
|
||||
|
||||
/* This Code Made By Sagi Dayan
|
||||
* SagiDayan@gmail.com
|
||||
*
|
||||
* Minor changes has been made by Liran Ben Gida
|
||||
* LiranBG@gmail.com
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
|
||||
#define COURSE_FIELDS 7
|
||||
#define NO_GRADE_YET 101;
|
||||
|
||||
|
||||
class Course{
|
||||
|
||||
public:
|
||||
enum CourseScheme
|
||||
{
|
||||
SERIAL,
|
||||
NAME,
|
||||
TYPE,
|
||||
POINTS,
|
||||
HOURS,
|
||||
GRADE,
|
||||
ADDITION
|
||||
};
|
||||
|
||||
Course(int serial,std::string name, std::string type, double points, double hours, double grade, std::string additions);
|
||||
~Course();
|
||||
|
||||
int getSerialNum() const {return this->serialNum;}
|
||||
std::string getName() const {return this->name;}
|
||||
std::string getType() const {return this->type;}
|
||||
double getPoints() const {return this->points;}
|
||||
double getHours() const {return this->hours;}
|
||||
double getGrade() const ;
|
||||
std::string getAddidtions() const {return this->additions;}
|
||||
|
||||
void setName(std::string name);
|
||||
void setType(std::string type);
|
||||
void setPoints(double points);
|
||||
void setHours(double hours);
|
||||
void setGrade(double grade);
|
||||
void setAdditions(std::string additions);
|
||||
|
||||
private:
|
||||
|
||||
int serialNum;
|
||||
std::string name;
|
||||
std::string type;
|
||||
double points;
|
||||
double hours;
|
||||
double grade;
|
||||
std::string additions;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,178 +1,178 @@
|
|||
#include "GradePage.h"
|
||||
|
||||
GradePage::GradePage(std::string html) : Page(html)
|
||||
{
|
||||
courses = new std::list<Course*>();
|
||||
tempHtml = getString();
|
||||
genList();
|
||||
|
||||
}
|
||||
GradePage::~GradePage()
|
||||
{
|
||||
for(Course* c : *courses)
|
||||
delete c;
|
||||
delete courses;
|
||||
}
|
||||
void GradePage::genList()
|
||||
{
|
||||
|
||||
this->tempHtml = tokenToLines( this->tempHtml , INFO_DATA_LINES_BEFORE_GRADES_DATA );
|
||||
|
||||
coursesListInit(this->tempHtml);
|
||||
|
||||
}
|
||||
void GradePage::addCourse(Course *a)
|
||||
{
|
||||
GradePage::courses->push_back(a);
|
||||
return;
|
||||
}
|
||||
|
||||
void GradePage::removeCourse(std::string courseSerialID)
|
||||
{
|
||||
for(Course* c : *courses)
|
||||
{
|
||||
if (c->getSerialNum() == stoi(courseSerialID))
|
||||
{
|
||||
courses->remove(c);
|
||||
delete c;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void GradePage::coursesListInit(std::string& linesTokinzedString)
|
||||
{
|
||||
std::list<std::string> stringHolder;
|
||||
std::string temp;
|
||||
Course* cTemp = NULL;
|
||||
char* tok;
|
||||
char* textToTok = strdup(linesTokinzedString.c_str());
|
||||
tok = strtok(textToTok,"\n");
|
||||
while (tok != NULL)
|
||||
{
|
||||
temp = tok;
|
||||
stringHolder.push_back(temp);
|
||||
tok = strtok(NULL, "\n");
|
||||
}
|
||||
for(std::string temp: stringHolder)
|
||||
{
|
||||
cTemp = lineToCourse(temp);
|
||||
if (cTemp != NULL)
|
||||
addCourse(cTemp);
|
||||
}
|
||||
}
|
||||
|
||||
std::string GradePage::tokenToLines(std::string& textToPhrase,int fromLine)
|
||||
{
|
||||
int ctr = 0;
|
||||
std::string temp = "";
|
||||
char *tok;
|
||||
char* textToTok = strdup(textToPhrase.c_str());
|
||||
tok = strtok(textToTok, "\n");
|
||||
while(tok != NULL)
|
||||
{
|
||||
//amount of data before the actual needed data and no empty lines
|
||||
if ((ctr >= fromLine) && (strcmp(tok," \t ") != 0))
|
||||
{
|
||||
temp += tok;
|
||||
temp += "\n";
|
||||
}
|
||||
ctr++;
|
||||
tok = strtok(NULL, "\n");
|
||||
}
|
||||
return temp;
|
||||
|
||||
}
|
||||
Course* GradePage::lineToCourse(std::string line)
|
||||
{
|
||||
Course *tempC = NULL;
|
||||
std::string templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions]
|
||||
int serial;
|
||||
double points,hours,grade;
|
||||
std::string name,type, additions;
|
||||
std::string tempS = "";
|
||||
int i = 0;
|
||||
char* tok;
|
||||
char* cLine = strdup(line.c_str());
|
||||
tok = strtok(cLine, "\t");
|
||||
while(tok != NULL)
|
||||
{
|
||||
|
||||
tempS = tok;
|
||||
if (i == 1) //skip the tokenizing loop just once
|
||||
{
|
||||
tempS = "";
|
||||
char *tokTemp;
|
||||
tokTemp = tok;
|
||||
|
||||
while (!(isdigit((int)*tokTemp)))
|
||||
tokTemp++;
|
||||
|
||||
while (isdigit((int)*tokTemp))
|
||||
{
|
||||
tempS += *tokTemp;
|
||||
tokTemp++;
|
||||
}
|
||||
templinearray[i-1] = tempS;
|
||||
templinearray[i] = tokTemp;
|
||||
|
||||
}
|
||||
else if (i > 1)
|
||||
templinearray[i] = tempS;
|
||||
i++;
|
||||
tok=strtok(NULL, "\t");
|
||||
}
|
||||
if (templinearray[0] == "") //empty phrasing
|
||||
return NULL;
|
||||
|
||||
serial = stoi(templinearray[Course::CourseScheme::SERIAL]);
|
||||
|
||||
name = templinearray[Course::CourseScheme::NAME];
|
||||
type = templinearray[Course::CourseScheme::TYPE];
|
||||
|
||||
points = stod(templinearray[Course::CourseScheme::POINTS]);
|
||||
hours = stod(templinearray[Course::CourseScheme::HOURS]);
|
||||
|
||||
if (isGradedYet(templinearray[Course::CourseScheme::GRADE]))
|
||||
grade = stod(templinearray[Course::CourseScheme::GRADE]);
|
||||
else
|
||||
grade = NO_GRADE_YET;
|
||||
|
||||
additions = templinearray[Course::CourseScheme::ADDITION];
|
||||
|
||||
tempC = new Course(serial,name,type,points,hours,grade,additions);
|
||||
return tempC;
|
||||
}
|
||||
|
||||
//checking if one of the chars inside grade is not a number
|
||||
bool GradePage::isGradedYet(std::string grade)
|
||||
{
|
||||
if (strlen(grade.c_str()) <= 1)
|
||||
return false;
|
||||
|
||||
for (char c: grade)
|
||||
{
|
||||
if (c == '\0')
|
||||
break;
|
||||
if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9
|
||||
return false;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
double GradePage::getAvg()
|
||||
{
|
||||
double avg = 0;
|
||||
double points = 0;
|
||||
for(Course* c : *courses)
|
||||
{
|
||||
if ((c->getGrade() != 0))
|
||||
{
|
||||
avg += c->getGrade() * c->getPoints();
|
||||
points += c->getPoints();
|
||||
}
|
||||
}
|
||||
|
||||
avg /= points;
|
||||
return avg;
|
||||
}
|
||||
#include "GradePage.h"
|
||||
|
||||
GradePage::GradePage(std::string html) : Page(html)
|
||||
{
|
||||
courses = new std::list<Course*>();
|
||||
tempHtml = getString();
|
||||
genList();
|
||||
|
||||
}
|
||||
GradePage::~GradePage()
|
||||
{
|
||||
for(Course* c : *courses)
|
||||
delete c;
|
||||
delete courses;
|
||||
}
|
||||
void GradePage::genList()
|
||||
{
|
||||
|
||||
this->tempHtml = tokenToLines( this->tempHtml , INFO_DATA_LINES_BEFORE_GRADES_DATA );
|
||||
|
||||
coursesListInit(this->tempHtml);
|
||||
|
||||
}
|
||||
void GradePage::addCourse(Course *a)
|
||||
{
|
||||
GradePage::courses->push_back(a);
|
||||
return;
|
||||
}
|
||||
|
||||
void GradePage::removeCourse(std::string courseSerialID)
|
||||
{
|
||||
for(Course* c : *courses)
|
||||
{
|
||||
if (c->getSerialNum() == stoi(courseSerialID))
|
||||
{
|
||||
courses->remove(c);
|
||||
delete c;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void GradePage::coursesListInit(std::string& linesTokinzedString)
|
||||
{
|
||||
std::list<std::string> stringHolder;
|
||||
std::string temp;
|
||||
Course* cTemp = NULL;
|
||||
char* tok;
|
||||
char* textToTok = strdup(linesTokinzedString.c_str());
|
||||
tok = strtok(textToTok,"\n");
|
||||
while (tok != NULL)
|
||||
{
|
||||
temp = tok;
|
||||
stringHolder.push_back(temp);
|
||||
tok = strtok(NULL, "\n");
|
||||
}
|
||||
for(std::string temp: stringHolder)
|
||||
{
|
||||
cTemp = lineToCourse(temp);
|
||||
if (cTemp != NULL)
|
||||
addCourse(cTemp);
|
||||
}
|
||||
}
|
||||
|
||||
std::string GradePage::tokenToLines(std::string& textToPhrase,int fromLine)
|
||||
{
|
||||
int ctr = 0;
|
||||
std::string temp = "";
|
||||
char *tok;
|
||||
char* textToTok = strdup(textToPhrase.c_str());
|
||||
tok = strtok(textToTok, "\n");
|
||||
while(tok != NULL)
|
||||
{
|
||||
//amount of data before the actual needed data and no empty lines
|
||||
if ((ctr >= fromLine) && (strcmp(tok," \t ") != 0))
|
||||
{
|
||||
temp += tok;
|
||||
temp += "\n";
|
||||
}
|
||||
ctr++;
|
||||
tok = strtok(NULL, "\n");
|
||||
}
|
||||
return temp;
|
||||
|
||||
}
|
||||
Course* GradePage::lineToCourse(std::string line)
|
||||
{
|
||||
Course *tempC = NULL;
|
||||
std::string templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions]
|
||||
int serial;
|
||||
double points,hours,grade;
|
||||
std::string name,type, additions;
|
||||
std::string tempS = "";
|
||||
int i = 0;
|
||||
char* tok;
|
||||
char* cLine = strdup(line.c_str());
|
||||
tok = strtok(cLine, "\t");
|
||||
while(tok != NULL)
|
||||
{
|
||||
|
||||
tempS = tok;
|
||||
if (i == 1) //skip the tokenizing loop just once
|
||||
{
|
||||
tempS = "";
|
||||
char *tokTemp;
|
||||
tokTemp = tok;
|
||||
|
||||
while (!(isdigit((int)*tokTemp)))
|
||||
tokTemp++;
|
||||
|
||||
while (isdigit((int)*tokTemp))
|
||||
{
|
||||
tempS += *tokTemp;
|
||||
tokTemp++;
|
||||
}
|
||||
templinearray[i-1] = tempS;
|
||||
templinearray[i] = tokTemp;
|
||||
|
||||
}
|
||||
else if (i > 1)
|
||||
templinearray[i] = tempS;
|
||||
i++;
|
||||
tok=strtok(NULL, "\t");
|
||||
}
|
||||
if (templinearray[0] == "") //empty phrasing
|
||||
return NULL;
|
||||
|
||||
serial = stoi(templinearray[Course::CourseScheme::SERIAL]);
|
||||
|
||||
name = templinearray[Course::CourseScheme::NAME];
|
||||
type = templinearray[Course::CourseScheme::TYPE];
|
||||
|
||||
points = stod(templinearray[Course::CourseScheme::POINTS]);
|
||||
hours = stod(templinearray[Course::CourseScheme::HOURS]);
|
||||
|
||||
if (isGradedYet(templinearray[Course::CourseScheme::GRADE]))
|
||||
grade = stod(templinearray[Course::CourseScheme::GRADE]);
|
||||
else
|
||||
grade = NO_GRADE_YET;
|
||||
|
||||
additions = templinearray[Course::CourseScheme::ADDITION];
|
||||
|
||||
tempC = new Course(serial,name,type,points,hours,grade,additions);
|
||||
return tempC;
|
||||
}
|
||||
|
||||
//checking if one of the chars inside grade is not a number
|
||||
bool GradePage::isGradedYet(std::string grade)
|
||||
{
|
||||
if (strlen(grade.c_str()) <= 1)
|
||||
return false;
|
||||
|
||||
for (char c: grade)
|
||||
{
|
||||
if (c == '\0')
|
||||
break;
|
||||
if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9
|
||||
return false;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
double GradePage::getAvg()
|
||||
{
|
||||
double avg = 0;
|
||||
double points = 0;
|
||||
for(Course* c : *courses)
|
||||
{
|
||||
if ((c->getGrade() != 0))
|
||||
{
|
||||
avg += c->getGrade() * c->getPoints();
|
||||
points += c->getPoints();
|
||||
}
|
||||
}
|
||||
|
||||
avg /= points;
|
||||
return avg;
|
||||
}
|
||||
|
|
|
@ -1,48 +1,48 @@
|
|||
#ifndef GRADE_PAGE_H
|
||||
#define GRADE_PAGE_H
|
||||
|
||||
/* This Code Made By Sagi Dayan
|
||||
* SagiDayan@gmail.com
|
||||
*
|
||||
* Minor changes has been made by Liran Ben Gida
|
||||
* LiranBG@gmail.com
|
||||
*/
|
||||
|
||||
#include "Page.h"
|
||||
#include "Course.h"
|
||||
|
||||
#include <list>
|
||||
#include <string.h> //strlen and strtok to phrase the html file
|
||||
#include <ctype.h> //checks if character is numeric
|
||||
|
||||
#define INFO_DATA_LINES_BEFORE_GRADES_DATA 5
|
||||
|
||||
class GradePage : public Page
|
||||
{
|
||||
|
||||
public:
|
||||
GradePage(std::string html);
|
||||
~GradePage();
|
||||
|
||||
void addCourse(Course *);
|
||||
void removeCourse(std::string courseSerialID);
|
||||
double getAvg();
|
||||
|
||||
std::list<Course*>* getCourses() { return courses; }
|
||||
|
||||
private:
|
||||
|
||||
void genList();
|
||||
std::string tokenToLines(std::string& textToPhrase,int fromLine = 0);
|
||||
void coursesListInit(std::string& linesTokinzedString);
|
||||
Course* lineToCourse(std::string line);
|
||||
|
||||
bool isGradedYet(std::string grade);
|
||||
|
||||
std::list<Course*>* courses;
|
||||
std::string tempHtml;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
#ifndef GRADE_PAGE_H
|
||||
#define GRADE_PAGE_H
|
||||
|
||||
/* This Code Made By Sagi Dayan
|
||||
* SagiDayan@gmail.com
|
||||
*
|
||||
* Minor changes has been made by Liran Ben Gida
|
||||
* LiranBG@gmail.com
|
||||
*/
|
||||
|
||||
#include "Page.h"
|
||||
#include "Course.h"
|
||||
|
||||
#include <list>
|
||||
#include <string.h> //strlen and strtok to phrase the html file
|
||||
#include <ctype.h> //checks if character is numeric
|
||||
|
||||
#define INFO_DATA_LINES_BEFORE_GRADES_DATA 5
|
||||
|
||||
class GradePage : public Page
|
||||
{
|
||||
|
||||
public:
|
||||
GradePage(std::string html);
|
||||
~GradePage();
|
||||
|
||||
void addCourse(Course *);
|
||||
void removeCourse(std::string courseSerialID);
|
||||
double getAvg();
|
||||
|
||||
std::list<Course*>* getCourses() { return courses; }
|
||||
|
||||
private:
|
||||
|
||||
void genList();
|
||||
std::string tokenToLines(std::string& textToPhrase,int fromLine = 0);
|
||||
void coursesListInit(std::string& linesTokinzedString);
|
||||
Course* lineToCourse(std::string line);
|
||||
|
||||
bool isGradedYet(std::string grade);
|
||||
|
||||
std::list<Course*>* courses;
|
||||
std::string tempHtml;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,164 +1,164 @@
|
|||
#include "Page.h"
|
||||
|
||||
Page::Page(std::string& html)
|
||||
{
|
||||
makeText(html);
|
||||
}
|
||||
void Page::makeText(std::string& html)
|
||||
{
|
||||
int index = 0;
|
||||
index = findTitle(html, index);
|
||||
index = runToActualText(html, index); //set index into the actual place where the data is
|
||||
manageTableContent(html, index);
|
||||
}
|
||||
|
||||
int Page::findTitle(std::string& from, int index)
|
||||
{
|
||||
std::string temp;
|
||||
while(index < (int)from.length())
|
||||
{
|
||||
if(from[index] == '<')
|
||||
{
|
||||
//title>
|
||||
index++;
|
||||
std::string titleTag = from.substr(index, 5); //legth of title
|
||||
if(titleTag == "title") //check if the tag is title
|
||||
{
|
||||
while(from[index] != '>')
|
||||
index++;
|
||||
index++;
|
||||
while(from[index] != '<')
|
||||
{
|
||||
temp += from[index];
|
||||
index++;
|
||||
}
|
||||
this->title = temp; //sets the title
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Page::runToActualText(std::string& from, int index)
|
||||
{
|
||||
while(index < (int)from.length())
|
||||
{
|
||||
if(from[index] == '<')
|
||||
{
|
||||
index++;
|
||||
if(from[index] == '!')
|
||||
{
|
||||
//!--FileName
|
||||
std::string bodyTag = from.substr(index, 11); //!--FileName
|
||||
|
||||
if(bodyTag == "!--FileName") //check if the tag is body tag
|
||||
{
|
||||
while(from[index] != '>')
|
||||
index++;
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Page::manageTableContent(std::string& html, int index)
|
||||
{
|
||||
std::string temp;
|
||||
for (int i = index; i < (int)html.length(); i++)
|
||||
{
|
||||
if(html[i] == '<')
|
||||
{
|
||||
//<tr> / <td> / <th>
|
||||
std::string endofTable = "</tbody>";
|
||||
std::string tableTag = html.substr(i, 4); //legth of "tr/td"
|
||||
if(tableTag == "<tr>")
|
||||
{
|
||||
temp += "\n"; //new row -> new line
|
||||
i = stitchText(html, temp, i+4);
|
||||
if(i == -1) //EOF
|
||||
break;
|
||||
}
|
||||
else if(tableTag == "<td>" || tableTag == "<th>")
|
||||
{
|
||||
temp += "\t"; // new cell -> tab between data
|
||||
i = stitchText(html, temp, i+4);
|
||||
if (i == -1) //EOF
|
||||
break;
|
||||
}
|
||||
else if(tableTag == "<td ") // a Year title (in grades table)
|
||||
{
|
||||
temp += "\t";
|
||||
while(html[i] != '>')
|
||||
i++;
|
||||
i = stitchText(html, temp, i+1);
|
||||
}
|
||||
else if (html.substr(i,(endofTable).length()) == endofTable) //is end of table
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this->text = temp;
|
||||
}
|
||||
|
||||
int Page::stitchText(std::string& from, std::string& to, int index)
|
||||
{
|
||||
if (from[index] == '<')
|
||||
{
|
||||
std::string bTag = from.substr(index, 3);
|
||||
if (bTag != "<b>")
|
||||
return index-1; //go back one step - for the main function to inc i
|
||||
index += 3;
|
||||
}
|
||||
|
||||
while (from[index] != '<' && index < (int)from.length())
|
||||
{
|
||||
if (from[index] == '&')
|
||||
{
|
||||
//
|
||||
std::string nbspChr = from.substr(index, 6);
|
||||
if (nbspChr == " ")
|
||||
{
|
||||
index += 5;
|
||||
from.at(index) = ' ';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (endOfString(index,(int) from.length()))
|
||||
return -1; //EOF
|
||||
|
||||
else if (from[index] == '<')
|
||||
return index - 1; //go back one step - for the main function to inc i
|
||||
|
||||
if (from[index] != '\n') //check the actuall data before continue
|
||||
to += from[index];
|
||||
index++;
|
||||
}
|
||||
|
||||
return index-1;
|
||||
}
|
||||
bool Page::endOfString(int index, int length)
|
||||
{
|
||||
if(index < length)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Page::getString()
|
||||
{
|
||||
return this->text;
|
||||
}
|
||||
|
||||
std::string Page::getTitle()
|
||||
{
|
||||
return this->title;
|
||||
}
|
||||
#include "Page.h"
|
||||
|
||||
Page::Page(std::string& html)
|
||||
{
|
||||
makeText(html);
|
||||
}
|
||||
void Page::makeText(std::string& html)
|
||||
{
|
||||
int index = 0;
|
||||
index = findTitle(html, index);
|
||||
index = runToActualText(html, index); //set index into the actual place where the data is
|
||||
manageTableContent(html, index);
|
||||
}
|
||||
|
||||
int Page::findTitle(std::string& from, int index)
|
||||
{
|
||||
std::string temp;
|
||||
while(index < (int)from.length())
|
||||
{
|
||||
if(from[index] == '<')
|
||||
{
|
||||
//title>
|
||||
index++;
|
||||
std::string titleTag = from.substr(index, 5); //legth of title
|
||||
if(titleTag == "title") //check if the tag is title
|
||||
{
|
||||
while(from[index] != '>')
|
||||
index++;
|
||||
index++;
|
||||
while(from[index] != '<')
|
||||
{
|
||||
temp += from[index];
|
||||
index++;
|
||||
}
|
||||
this->title = temp; //sets the title
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Page::runToActualText(std::string& from, int index)
|
||||
{
|
||||
while(index < (int)from.length())
|
||||
{
|
||||
if(from[index] == '<')
|
||||
{
|
||||
index++;
|
||||
if(from[index] == '!')
|
||||
{
|
||||
//!--FileName
|
||||
std::string bodyTag = from.substr(index, 11); //!--FileName
|
||||
|
||||
if(bodyTag == "!--FileName") //check if the tag is body tag
|
||||
{
|
||||
while(from[index] != '>')
|
||||
index++;
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Page::manageTableContent(std::string& html, int index)
|
||||
{
|
||||
std::string temp;
|
||||
for (int i = index; i < (int)html.length(); i++)
|
||||
{
|
||||
if(html[i] == '<')
|
||||
{
|
||||
//<tr> / <td> / <th>
|
||||
std::string endofTable = "</tbody>";
|
||||
std::string tableTag = html.substr(i, 4); //legth of "tr/td"
|
||||
if(tableTag == "<tr>")
|
||||
{
|
||||
temp += "\n"; //new row -> new line
|
||||
i = stitchText(html, temp, i+4);
|
||||
if(i == -1) //EOF
|
||||
break;
|
||||
}
|
||||
else if(tableTag == "<td>" || tableTag == "<th>")
|
||||
{
|
||||
temp += "\t"; // new cell -> tab between data
|
||||
i = stitchText(html, temp, i+4);
|
||||
if (i == -1) //EOF
|
||||
break;
|
||||
}
|
||||
else if(tableTag == "<td ") // a Year title (in grades table)
|
||||
{
|
||||
temp += "\t";
|
||||
while(html[i] != '>')
|
||||
i++;
|
||||
i = stitchText(html, temp, i+1);
|
||||
}
|
||||
else if (html.substr(i,(endofTable).length()) == endofTable) //is end of table
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this->text = temp;
|
||||
}
|
||||
|
||||
int Page::stitchText(std::string& from, std::string& to, int index)
|
||||
{
|
||||
if (from[index] == '<')
|
||||
{
|
||||
std::string bTag = from.substr(index, 3);
|
||||
if (bTag != "<b>")
|
||||
return index-1; //go back one step - for the main function to inc i
|
||||
index += 3;
|
||||
}
|
||||
|
||||
while (from[index] != '<' && index < (int)from.length())
|
||||
{
|
||||
if (from[index] == '&')
|
||||
{
|
||||
//
|
||||
std::string nbspChr = from.substr(index, 6);
|
||||
if (nbspChr == " ")
|
||||
{
|
||||
index += 5;
|
||||
from.at(index) = ' ';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (endOfString(index,(int) from.length()))
|
||||
return -1; //EOF
|
||||
|
||||
else if (from[index] == '<')
|
||||
return index - 1; //go back one step - for the main function to inc i
|
||||
|
||||
if (from[index] != '\n') //check the actuall data before continue
|
||||
to += from[index];
|
||||
index++;
|
||||
}
|
||||
|
||||
return index-1;
|
||||
}
|
||||
bool Page::endOfString(int index, int length)
|
||||
{
|
||||
if(index < length)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Page::getString()
|
||||
{
|
||||
return this->text;
|
||||
}
|
||||
|
||||
std::string Page::getTitle()
|
||||
{
|
||||
return this->title;
|
||||
}
|
||||
|
|
|
@ -1,42 +1,42 @@
|
|||
#ifndef PAGE_H
|
||||
#define PAGE_H
|
||||
|
||||
/* This Code Made By Sagi Dayan
|
||||
* SagiDayan@gmail.com
|
||||
*
|
||||
* Minor changes has been made by Liran Ben Gida
|
||||
* LiranBG@gmail.com
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
class Page
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
~Page() {}
|
||||
|
||||
protected:
|
||||
Page(std::string& html);
|
||||
std::string getString();
|
||||
std::string getTitle();
|
||||
void makeText(std::string& html);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
int findTitle(std::string& from, int index);
|
||||
int runToActualText(std::string& from, int index);
|
||||
void manageTableContent(std::string& html, int index);
|
||||
int stitchText(std::string& from, std::string& to, int index);
|
||||
bool endOfString(int index, int length);
|
||||
|
||||
std::string text;
|
||||
std::string title;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#ifndef PAGE_H
|
||||
#define PAGE_H
|
||||
|
||||
/* This Code Made By Sagi Dayan
|
||||
* SagiDayan@gmail.com
|
||||
*
|
||||
* Minor changes has been made by Liran Ben Gida
|
||||
* LiranBG@gmail.com
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
class Page
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
~Page() {}
|
||||
|
||||
protected:
|
||||
Page(std::string& html);
|
||||
std::string getString();
|
||||
std::string getTitle();
|
||||
void makeText(std::string& html);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
int findTitle(std::string& from, int index);
|
||||
int runToActualText(std::string& from, int index);
|
||||
void manageTableContent(std::string& html, int index);
|
||||
int stitchText(std::string& from, std::string& to, int index);
|
||||
bool endOfString(int index, int length);
|
||||
|
||||
std::string text;
|
||||
std::string title;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,72 +1,72 @@
|
|||
#ifndef JCELOGINHTMLSCRIPTS_H
|
||||
#define JCELOGINHTMLSCRIPTS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#define dst_host "yedion.jce.ac.il"
|
||||
#define dst_port 443
|
||||
|
||||
#include "../user.h"
|
||||
|
||||
class jceLoginHtmlScripts
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
jceLoginHtmlScripts();
|
||||
|
||||
public:
|
||||
|
||||
static std::string makeRequest(std::string parameters)
|
||||
{
|
||||
std::string msg;
|
||||
msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n";
|
||||
msg += "Host: " + std::string(dst_host) + "\r\n";
|
||||
msg += "Content-Type: application/x-www-form-urlencoded\r\n";
|
||||
msg += "Content-Length: " + to_string(parameters.length()) + "\r\n";
|
||||
msg += "Proxy-Connection: Keep-Alive\r\n";
|
||||
msg += "Accept-Charset: utf-8";
|
||||
msg += "Accept: text/plain\r\n";
|
||||
msg += "Connection: Keep-Alive\r\n";
|
||||
msg += "\r\n";
|
||||
msg += parameters;
|
||||
return msg;
|
||||
}
|
||||
|
||||
const static std::string getFirstValidationStep(const user &usr)
|
||||
{
|
||||
std::string parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N";
|
||||
parameters += usr.getUsername();
|
||||
parameters += ",-N";
|
||||
parameters += usr.getPassword();
|
||||
return parameters;
|
||||
}
|
||||
|
||||
const static std::string getSecondValidationStep(const user &usr)
|
||||
{
|
||||
std::string parameters;
|
||||
parameters = "prgname=LoginValidtion1&Arguments=-N";
|
||||
parameters += usr.getUserID();
|
||||
parameters += ",-A,-N";
|
||||
parameters += usr.getHashedPassword();
|
||||
parameters += ",-A,-A";
|
||||
return parameters;
|
||||
}
|
||||
const static std::string getGradesPath(const user &usr)
|
||||
{
|
||||
std::string parameters;
|
||||
parameters = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&";
|
||||
parameters += "TZ=" + usr.getUserID() + "&";
|
||||
parameters += "UNIQ=" + usr.getHashedPassword() + "&";
|
||||
parameters += "R1C2=" + usr.date->getFYear() + "&";
|
||||
parameters += "R1C1=" + usr.date->getTYear() + "&";
|
||||
parameters += "R1C3=" + usr.date->getTSemester() + "&";
|
||||
parameters += "R1C4=" + usr.date->getFSemester() + "&";
|
||||
parameters += "R1C5=0";
|
||||
return parameters;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // JCELOGINHTMLSCRIPTS_H
|
||||
#ifndef JCELOGINHTMLSCRIPTS_H
|
||||
#define JCELOGINHTMLSCRIPTS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#define dst_host "yedion.jce.ac.il"
|
||||
#define dst_port 443
|
||||
|
||||
#include "../user.h"
|
||||
|
||||
class jceLoginHtmlScripts
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
jceLoginHtmlScripts();
|
||||
|
||||
public:
|
||||
|
||||
static std::string makeRequest(std::string parameters)
|
||||
{
|
||||
std::string msg;
|
||||
msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n";
|
||||
msg += "Host: " + std::string(dst_host) + "\r\n";
|
||||
msg += "Content-Type: application/x-www-form-urlencoded\r\n";
|
||||
msg += "Content-Length: " + to_string(parameters.length()) + "\r\n";
|
||||
msg += "Proxy-Connection: Keep-Alive\r\n";
|
||||
msg += "Accept-Charset: utf-8";
|
||||
msg += "Accept: text/plain\r\n";
|
||||
msg += "Connection: Keep-Alive\r\n";
|
||||
msg += "\r\n";
|
||||
msg += parameters;
|
||||
return msg;
|
||||
}
|
||||
|
||||
const static std::string getFirstValidationStep(const user &usr)
|
||||
{
|
||||
std::string parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N";
|
||||
parameters += usr.getUsername();
|
||||
parameters += ",-N";
|
||||
parameters += usr.getPassword();
|
||||
return parameters;
|
||||
}
|
||||
|
||||
const static std::string getSecondValidationStep(const user &usr)
|
||||
{
|
||||
std::string parameters;
|
||||
parameters = "prgname=LoginValidtion1&Arguments=-N";
|
||||
parameters += usr.getUserID();
|
||||
parameters += ",-A,-N";
|
||||
parameters += usr.getHashedPassword();
|
||||
parameters += ",-A,-A";
|
||||
return parameters;
|
||||
}
|
||||
const static std::string getGradesPath(const user &usr)
|
||||
{
|
||||
std::string parameters;
|
||||
parameters = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&";
|
||||
parameters += "TZ=" + usr.getUserID() + "&";
|
||||
parameters += "UNIQ=" + usr.getHashedPassword() + "&";
|
||||
parameters += "R1C2=" + usr.date->getFYear() + "&";
|
||||
parameters += "R1C1=" + usr.date->getTYear() + "&";
|
||||
parameters += "R1C3=" + usr.date->getTSemester() + "&";
|
||||
parameters += "R1C4=" + usr.date->getFSemester() + "&";
|
||||
parameters += "R1C5=0";
|
||||
return parameters;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // JCELOGINHTMLSCRIPTS_H
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
#include "jcedate.h"
|
||||
|
||||
jceDate::jceDate(std::string fromYear,std::string fromSemester,std::string toYear,std::string toSemester)
|
||||
{
|
||||
this->fSemester = fromSemester;
|
||||
this->fYear = fromYear;
|
||||
this->tSemester = toSemester;
|
||||
this->tYear = toYear;
|
||||
}
|
||||
|
||||
void jceDate::setFYear(std::string fromYear)
|
||||
{
|
||||
this->fYear = fromYear;
|
||||
}
|
||||
|
||||
void jceDate::setTYear(std::string toYear)
|
||||
{
|
||||
this->tYear = toYear;
|
||||
}
|
||||
|
||||
void jceDate::setFSemester(std::string fromSemester)
|
||||
{
|
||||
this->fSemester = fromSemester;
|
||||
}
|
||||
|
||||
void jceDate::setTSemester(std::string toSemester)
|
||||
{
|
||||
this->tSemester = toSemester;
|
||||
}
|
||||
|
||||
jceDate::~jceDate()
|
||||
{
|
||||
|
||||
}
|
||||
#include "jcedate.h"
|
||||
|
||||
jceDate::jceDate(std::string fromYear,std::string fromSemester,std::string toYear,std::string toSemester)
|
||||
{
|
||||
this->fSemester = fromSemester;
|
||||
this->fYear = fromYear;
|
||||
this->tSemester = toSemester;
|
||||
this->tYear = toYear;
|
||||
}
|
||||
|
||||
void jceDate::setFYear(std::string fromYear)
|
||||
{
|
||||
this->fYear = fromYear;
|
||||
}
|
||||
|
||||
void jceDate::setTYear(std::string toYear)
|
||||
{
|
||||
this->tYear = toYear;
|
||||
}
|
||||
|
||||
void jceDate::setFSemester(std::string fromSemester)
|
||||
{
|
||||
this->fSemester = fromSemester;
|
||||
}
|
||||
|
||||
void jceDate::setTSemester(std::string toSemester)
|
||||
{
|
||||
this->tSemester = toSemester;
|
||||
}
|
||||
|
||||
jceDate::~jceDate()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
#ifndef JCEDATE_H
|
||||
#define JCEDATE_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class jceDate
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
jceDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester);
|
||||
~jceDate();
|
||||
|
||||
void setFYear(std::string fromYear);
|
||||
void setTYear(std::string toYear);
|
||||
void setFSemester(std::string fromSemester);
|
||||
void setTSemester(std::string toSemester);
|
||||
|
||||
std::string getFYear() { return this->fYear;}
|
||||
std::string getTYear() { return this->tYear;}
|
||||
std::string getFSemester() { return this->fSemester;}
|
||||
std::string getTSemester() { return this->tSemester;}
|
||||
|
||||
private:
|
||||
std::string fYear; //from
|
||||
std::string fSemester;
|
||||
|
||||
std::string tYear; //to
|
||||
std::string tSemester;
|
||||
|
||||
};
|
||||
|
||||
#endif // JCEDATE_H
|
||||
#ifndef JCEDATE_H
|
||||
#define JCEDATE_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class jceDate
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
jceDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester);
|
||||
~jceDate();
|
||||
|
||||
void setFYear(std::string fromYear);
|
||||
void setTYear(std::string toYear);
|
||||
void setFSemester(std::string fromSemester);
|
||||
void setTSemester(std::string toSemester);
|
||||
|
||||
std::string getFYear() { return this->fYear;}
|
||||
std::string getTYear() { return this->tYear;}
|
||||
std::string getFSemester() { return this->fSemester;}
|
||||
std::string getTSemester() { return this->tSemester;}
|
||||
|
||||
private:
|
||||
std::string fYear; //from
|
||||
std::string fSemester;
|
||||
|
||||
std::string tYear; //to
|
||||
std::string tSemester;
|
||||
|
||||
};
|
||||
|
||||
#endif // JCEDATE_H
|
||||
|
|
|
@ -1,187 +1,184 @@
|
|||
#include "jcelogin.h"
|
||||
|
||||
jceLogin::jceLogin(user * username)
|
||||
{
|
||||
this->recieverPage = new std::string();
|
||||
this->jceA = username;
|
||||
this->JceConnector = new qtsslsocket(dst_host, dst_port);
|
||||
}
|
||||
|
||||
jceLogin::~jceLogin()
|
||||
{
|
||||
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.
|
||||
* throws error upon the given error from JCE website or Socket error
|
||||
*/
|
||||
void jceLogin::makeConnection() throw (jceStatus)
|
||||
{
|
||||
jceStatus status = jceStatus::JCE_NOT_CONNECTED;
|
||||
|
||||
if (checkConnection() == true) //connected to host
|
||||
{
|
||||
if (makeFirstVisit() == true) //requst and send first validation
|
||||
{
|
||||
std::cout << "visit 1\n";
|
||||
std::cout << *(this->recieverPage);
|
||||
status = jceStatus::JCE_FIRST_VALIDATION_PASSED;
|
||||
if (checkValidation() == true) //check if username and password are matching
|
||||
{
|
||||
std::cout << "visit 2\n";
|
||||
std::cout << *(this->recieverPage);
|
||||
status = jceStatus::JCE_SECOND_VALIDATION_PASSED;
|
||||
if (makeSecondVisit() == true) //siging in the website
|
||||
{
|
||||
std::cout << "visit 3\n";
|
||||
std::cout << *(this->recieverPage);
|
||||
status = jceStatus::JCE_YOU_ARE_IN;
|
||||
setLoginFlag(true);
|
||||
}
|
||||
else
|
||||
status = jceStatus::ERROR_ON_VALIDATION;
|
||||
}
|
||||
else
|
||||
status = jceStatus::ERROR_ON_VALIDATION;
|
||||
|
||||
}
|
||||
else
|
||||
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
|
||||
|
||||
}
|
||||
else
|
||||
status = jceStatus::ERROR_ON_OPEN_SOCKET;
|
||||
|
||||
//we throw status even if we are IN!
|
||||
throw status;
|
||||
|
||||
}
|
||||
|
||||
bool jceLogin::checkConnection()
|
||||
{
|
||||
if (JceConnector->isCon())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void jceLogin::reConnect() throw (jceStatus)
|
||||
{
|
||||
closeAll();
|
||||
this->recieverPage = new std::string();
|
||||
this->JceConnector = new qtsslsocket(dst_host, dst_port);
|
||||
try
|
||||
{
|
||||
makeConnection();
|
||||
}
|
||||
catch (jceLogin::jceStatus &a)
|
||||
{
|
||||
throw a;
|
||||
}
|
||||
}
|
||||
|
||||
void jceLogin::closeAll()
|
||||
{
|
||||
delete recieverPage;
|
||||
recieverPage = NULL;
|
||||
JceConnector = NULL;
|
||||
|
||||
}
|
||||
|
||||
int jceLogin::makeFirstVisit()
|
||||
{
|
||||
std::string usr = jceA->getUsername();
|
||||
std::string psw = jceA->getPassword();
|
||||
if (JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
|
||||
{
|
||||
if (!JceConnector->recieve(*recieverPage))
|
||||
return jceLogin::ERROR_ON_GETTING_INFO;
|
||||
}
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int jceLogin::makeSecondVisit()
|
||||
{
|
||||
std::string usrid=jceA->getUserID();
|
||||
std::string pswid=jceA->getHashedPassword();
|
||||
if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
|
||||
{
|
||||
if (!(JceConnector->recieve(*recieverPage)))
|
||||
return jceLogin::ERROR_ON_GETTING_INFO;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int jceLogin::getGrades()
|
||||
{
|
||||
if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA)))))
|
||||
{
|
||||
if (!(JceConnector->recieve(*recieverPage)))
|
||||
return jceLogin::ERROR_ON_GETTING_GRADES;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void jceLogin::setLoginFlag(bool x)
|
||||
{
|
||||
this->loginFlag = x;
|
||||
}
|
||||
bool jceLogin::isLoginFlag() const
|
||||
{
|
||||
return this->loginFlag;
|
||||
}
|
||||
|
||||
std::string jceLogin::getPage()
|
||||
{
|
||||
return *recieverPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief jceLogin::checkValidation Made by Nadav Luzzato
|
||||
* @return true if second validation step is right
|
||||
*/
|
||||
bool jceLogin::checkValidation()
|
||||
{
|
||||
//finds the hashed password
|
||||
std::cout << *recieverPage << std::endl;
|
||||
|
||||
std::size_t hasspass_position1 = recieverPage->find("-A,-N");
|
||||
hasspass_position1 += 5;
|
||||
std::size_t hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1);
|
||||
if ((hasspass_position2 != std::string::npos) && (hasspass_position1 != std::string::npos))
|
||||
{
|
||||
std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1);
|
||||
jceA->setHashedPassword(hasspass);
|
||||
}
|
||||
//finds the user id
|
||||
std::size_t id_position1 = recieverPage->find("value=\"-N", 0);
|
||||
id_position1 += 9;
|
||||
std::size_t id_position2 = recieverPage->find(",-A", id_position1);
|
||||
if ((id_position2 != std::string::npos) && (id_position1 != std::string::npos))
|
||||
{
|
||||
std::string hassid = recieverPage->substr(id_position1,id_position2-id_position1);
|
||||
jceA->setUserID(hassid);
|
||||
}
|
||||
if (((jceA->getUserID()).empty()) || ((jceA->getHashedPassword()).empty()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
#include "jcelogin.h"
|
||||
|
||||
jceLogin::jceLogin(user * username)
|
||||
{
|
||||
this->recieverPage = new std::string();
|
||||
this->jceA = username;
|
||||
this->JceConnector = new qtsslsocket();
|
||||
}
|
||||
|
||||
jceLogin::~jceLogin()
|
||||
{
|
||||
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.
|
||||
* throws error upon the given error from JCE website or Socket error
|
||||
*/
|
||||
void jceLogin::makeConnection() throw (jceStatus)
|
||||
{
|
||||
if (JceConnector->makeConnect(dst_host,dst_port) == false)
|
||||
throw jceStatus::ERROR_ON_OPEN_SOCKET;
|
||||
|
||||
jceStatus status = jceStatus::JCE_NOT_CONNECTED;
|
||||
|
||||
if (checkConnection() == true) //connected to host
|
||||
{
|
||||
if (makeFirstVisit() == true) //requst and send first validation
|
||||
{
|
||||
status = jceStatus::JCE_FIRST_VALIDATION_PASSED;
|
||||
if (checkValidation() == true) //check if username and password are matching
|
||||
{
|
||||
status = jceStatus::JCE_SECOND_VALIDATION_PASSED;
|
||||
if (makeSecondVisit() == true) //siging in the website
|
||||
{
|
||||
status = jceStatus::JCE_YOU_ARE_IN;
|
||||
setLoginFlag(true);
|
||||
}
|
||||
else
|
||||
status = jceStatus::ERROR_ON_VALIDATION;
|
||||
}
|
||||
else
|
||||
status = jceStatus::ERROR_ON_VALIDATION;
|
||||
|
||||
}
|
||||
else
|
||||
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
|
||||
|
||||
}
|
||||
else
|
||||
status = jceStatus::ERROR_ON_OPEN_SOCKET;
|
||||
|
||||
//we throw status even if we are IN!
|
||||
throw status;
|
||||
|
||||
}
|
||||
|
||||
bool jceLogin::checkConnection()
|
||||
{
|
||||
if (JceConnector->isCon())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void jceLogin::reConnect() throw (jceStatus)
|
||||
{
|
||||
closeAll();
|
||||
if (this->JceConnector != NULL)
|
||||
delete JceConnector;
|
||||
this->recieverPage = new std::string();
|
||||
this->JceConnector = new qtsslsocket();
|
||||
try
|
||||
{
|
||||
makeConnection();
|
||||
}
|
||||
catch (jceLogin::jceStatus &a)
|
||||
{
|
||||
throw a;
|
||||
}
|
||||
}
|
||||
|
||||
void jceLogin::closeAll()
|
||||
{
|
||||
delete recieverPage;
|
||||
recieverPage = NULL;
|
||||
JceConnector = NULL;
|
||||
|
||||
}
|
||||
|
||||
int jceLogin::makeFirstVisit()
|
||||
{
|
||||
std::string usr = jceA->getUsername();
|
||||
std::string psw = jceA->getPassword();
|
||||
if (JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
|
||||
{
|
||||
if (!JceConnector->recieve(*recieverPage))
|
||||
return jceLogin::ERROR_ON_GETTING_INFO;
|
||||
}
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int jceLogin::makeSecondVisit()
|
||||
{
|
||||
std::string usrid=jceA->getUserID();
|
||||
std::string pswid=jceA->getHashedPassword();
|
||||
if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
|
||||
{
|
||||
if (!(JceConnector->recieve(*recieverPage)))
|
||||
return jceLogin::ERROR_ON_GETTING_INFO;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int jceLogin::getGrades()
|
||||
{
|
||||
if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA)))))
|
||||
{
|
||||
if (!(JceConnector->recieve(*recieverPage)))
|
||||
return jceLogin::ERROR_ON_GETTING_GRADES;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void jceLogin::setLoginFlag(bool x)
|
||||
{
|
||||
this->loginFlag = x;
|
||||
}
|
||||
bool jceLogin::isLoginFlag() const
|
||||
{
|
||||
return this->loginFlag;
|
||||
}
|
||||
|
||||
std::string jceLogin::getPage()
|
||||
{
|
||||
return *recieverPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief jceLogin::checkValidation Made by Nadav Luzzato
|
||||
* @return true if second validation step is right
|
||||
*/
|
||||
bool jceLogin::checkValidation()
|
||||
{
|
||||
//finds the hashed password
|
||||
std::size_t hasspass_position1 = recieverPage->find("-A,-N");
|
||||
hasspass_position1 += 5;
|
||||
std::size_t hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1);
|
||||
if ((hasspass_position2 != std::string::npos) && (hasspass_position1 != std::string::npos))
|
||||
{
|
||||
std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1);
|
||||
jceA->setHashedPassword(hasspass);
|
||||
}
|
||||
//finds the user id
|
||||
std::size_t id_position1 = recieverPage->find("value=\"-N", 0);
|
||||
id_position1 += 9;
|
||||
std::size_t id_position2 = recieverPage->find(",-A", id_position1);
|
||||
if ((id_position2 != std::string::npos) && (id_position1 != std::string::npos))
|
||||
{
|
||||
std::string hassid = recieverPage->substr(id_position1,id_position2-id_position1);
|
||||
jceA->setUserID(hassid);
|
||||
}
|
||||
if (((jceA->getUserID()).empty()) || ((jceA->getHashedPassword()).empty()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,61 +1,61 @@
|
|||
#ifndef JCELOGIN_H
|
||||
#define JCELOGIN_H
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
#include "../connection/qtsslsocket.h"
|
||||
#include "../user.h"
|
||||
#include "jceLoginHtmlScripts.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class jceLogin
|
||||
{
|
||||
public:
|
||||
|
||||
enum jceStatus {
|
||||
JCE_NOT_CONNECTED,
|
||||
ERROR_ON_VALIDATION,
|
||||
ERROR_ON_VALIDATION_USER_BLOCKED,
|
||||
ERROR_ON_INPUT,
|
||||
ERROR_ON_CONNECTING,
|
||||
ERROR_ON_OPEN_SOCKET,
|
||||
ERROR_ON_GETTING_INFO,
|
||||
ERROR_ON_GETTING_GRADES,
|
||||
ERROR_ON_SEND_REQUEST,
|
||||
JCE_START_VALIDATING_PROGRESS,
|
||||
JCE_FIRST_VALIDATION_PASSED,
|
||||
JCE_SECOND_VALIDATION_PASSED,
|
||||
JCE_YOU_ARE_IN,
|
||||
JCE_GRADE_PAGE_PASSED
|
||||
};
|
||||
|
||||
jceLogin(user* username);
|
||||
~jceLogin();
|
||||
void makeConnection() throw (jceStatus);
|
||||
bool checkConnection();
|
||||
void reConnect() throw (jceStatus);
|
||||
void closeAll();
|
||||
int getGrades();
|
||||
bool isLoginFlag() const;
|
||||
|
||||
std::string getPage();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
int makeFirstVisit();
|
||||
bool checkValidation();
|
||||
int makeSecondVisit();
|
||||
void setLoginFlag(bool x);
|
||||
|
||||
bool loginFlag;
|
||||
std::string * recieverPage;
|
||||
user * jceA;
|
||||
qtsslsocket * JceConnector;
|
||||
|
||||
};
|
||||
|
||||
#endif // JCELOGIN_H
|
||||
#ifndef JCELOGIN_H
|
||||
#define JCELOGIN_H
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
#include "../connection/qtsslsocket.h"
|
||||
#include "../user.h"
|
||||
#include "jceLoginHtmlScripts.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class jceLogin
|
||||
{
|
||||
public:
|
||||
|
||||
enum jceStatus {
|
||||
JCE_NOT_CONNECTED,
|
||||
ERROR_ON_VALIDATION,
|
||||
ERROR_ON_VALIDATION_USER_BLOCKED,
|
||||
ERROR_ON_INPUT,
|
||||
ERROR_ON_CONNECTING,
|
||||
ERROR_ON_OPEN_SOCKET,
|
||||
ERROR_ON_GETTING_INFO,
|
||||
ERROR_ON_GETTING_GRADES,
|
||||
ERROR_ON_SEND_REQUEST,
|
||||
JCE_START_VALIDATING_PROGRESS,
|
||||
JCE_FIRST_VALIDATION_PASSED,
|
||||
JCE_SECOND_VALIDATION_PASSED,
|
||||
JCE_YOU_ARE_IN,
|
||||
JCE_GRADE_PAGE_PASSED
|
||||
};
|
||||
|
||||
jceLogin(user* username);
|
||||
~jceLogin();
|
||||
void makeConnection() throw (jceStatus);
|
||||
bool checkConnection();
|
||||
void reConnect() throw (jceStatus);
|
||||
void closeAll();
|
||||
int getGrades();
|
||||
bool isLoginFlag() const;
|
||||
|
||||
std::string getPage();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
int makeFirstVisit();
|
||||
bool checkValidation();
|
||||
int makeSecondVisit();
|
||||
void setLoginFlag(bool x);
|
||||
|
||||
bool loginFlag;
|
||||
std::string * recieverPage;
|
||||
user * jceA;
|
||||
qtsslsocket * JceConnector;
|
||||
|
||||
};
|
||||
|
||||
#endif // JCELOGIN_H
|
||||
|
|
104
src/user.cpp
104
src/user.cpp
|
@ -1,52 +1,52 @@
|
|||
#include "user.h"
|
||||
|
||||
|
||||
user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false)
|
||||
{
|
||||
|
||||
this->username = username;
|
||||
this->password = password;
|
||||
}
|
||||
user::~user()
|
||||
{
|
||||
delete date;
|
||||
}
|
||||
void user::setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester)
|
||||
{
|
||||
date->setFYear(fromYear);
|
||||
date->setFSemester(fromSemester);
|
||||
date->setTYear(toYear);
|
||||
date->setTSemester(toSemester);
|
||||
}
|
||||
|
||||
void user::setInfluenceCourseOnly(bool status)
|
||||
{
|
||||
this->influenceCourseOnly = status;
|
||||
}
|
||||
|
||||
bool user::getInfluenceCourseOnly() const
|
||||
{
|
||||
return this->influenceCourseOnly;
|
||||
}
|
||||
|
||||
void user::setUsername(string& username) {
|
||||
this->username=username;
|
||||
}
|
||||
|
||||
void user::setPassword(string& password) {
|
||||
this->password=password;
|
||||
}
|
||||
|
||||
void user::setUserID(string& ID)
|
||||
{
|
||||
this->userID = ID;
|
||||
}
|
||||
void user::setHashedPassword(string& hashpass)
|
||||
{
|
||||
this->hashedPassword = hashpass;
|
||||
}
|
||||
|
||||
string user::getPassword() const { return password; }
|
||||
string user::getUsername() const { return username; }
|
||||
string user::getUserID() const { return userID; }
|
||||
string user::getHashedPassword() const { return hashedPassword; }
|
||||
#include "user.h"
|
||||
|
||||
|
||||
user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false)
|
||||
{
|
||||
|
||||
this->username = username;
|
||||
this->password = password;
|
||||
}
|
||||
user::~user()
|
||||
{
|
||||
delete date;
|
||||
}
|
||||
void user::setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester)
|
||||
{
|
||||
date->setFYear(fromYear);
|
||||
date->setFSemester(fromSemester);
|
||||
date->setTYear(toYear);
|
||||
date->setTSemester(toSemester);
|
||||
}
|
||||
|
||||
void user::setInfluenceCourseOnly(bool status)
|
||||
{
|
||||
this->influenceCourseOnly = status;
|
||||
}
|
||||
|
||||
bool user::getInfluenceCourseOnly() const
|
||||
{
|
||||
return this->influenceCourseOnly;
|
||||
}
|
||||
|
||||
void user::setUsername(string& username) {
|
||||
this->username=username;
|
||||
}
|
||||
|
||||
void user::setPassword(string& password) {
|
||||
this->password=password;
|
||||
}
|
||||
|
||||
void user::setUserID(string& ID)
|
||||
{
|
||||
this->userID = ID;
|
||||
}
|
||||
void user::setHashedPassword(string& hashpass)
|
||||
{
|
||||
this->hashedPassword = hashpass;
|
||||
}
|
||||
|
||||
string user::getPassword() const { return password; }
|
||||
string user::getUsername() const { return username; }
|
||||
string user::getUserID() const { return userID; }
|
||||
string user::getHashedPassword() const { return hashedPassword; }
|
||||
|
|
96
src/user.h
96
src/user.h
|
@ -1,48 +1,48 @@
|
|||
#ifndef user_H
|
||||
#define user_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "jce/jcedate.h"
|
||||
|
||||
using namespace std;
|
||||
class user
|
||||
{
|
||||
public:
|
||||
user(string username,string password);
|
||||
~user();
|
||||
void setUsername(string& username);
|
||||
void setPassword(string& password);
|
||||
|
||||
string getPassword() const;
|
||||
string getUsername() const;
|
||||
|
||||
void setUserID(string& ID);
|
||||
void setHashedPassword(string& hashpass);
|
||||
|
||||
string getUserID() const;
|
||||
string getHashedPassword() const;
|
||||
|
||||
void setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester);
|
||||
|
||||
void setInfluenceCourseOnly(bool status);
|
||||
bool getInfluenceCourseOnly() const;
|
||||
|
||||
jceDate * const date = new jceDate("","","",""); //we do not change the pointer
|
||||
|
||||
private:
|
||||
|
||||
string username;
|
||||
string password;
|
||||
|
||||
string hashedPassword;
|
||||
string userID;
|
||||
|
||||
bool influenceCourseOnly;
|
||||
|
||||
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef user_H
|
||||
#define user_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "jce/jcedate.h"
|
||||
|
||||
using namespace std;
|
||||
class user
|
||||
{
|
||||
public:
|
||||
user(string username,string password);
|
||||
~user();
|
||||
void setUsername(string& username);
|
||||
void setPassword(string& password);
|
||||
|
||||
string getPassword() const;
|
||||
string getUsername() const;
|
||||
|
||||
void setUserID(string& ID);
|
||||
void setHashedPassword(string& hashpass);
|
||||
|
||||
string getUserID() const;
|
||||
string getHashedPassword() const;
|
||||
|
||||
void setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester);
|
||||
|
||||
void setInfluenceCourseOnly(bool status);
|
||||
bool getInfluenceCourseOnly() const;
|
||||
|
||||
jceDate * const date = new jceDate("","","",""); //we do not change the pointer
|
||||
|
||||
private:
|
||||
|
||||
string username;
|
||||
string password;
|
||||
|
||||
string hashedPassword;
|
||||
string userID;
|
||||
|
||||
bool influenceCourseOnly;
|
||||
|
||||
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue