fixed bugs, added option to keep login

This commit is contained in:
liranbg 2014-06-19 02:44:46 +03:00
parent 050fb21e1d
commit 1980efe130
29 changed files with 3434 additions and 3392 deletions

1006
LICENSE

File diff suppressed because it is too large Load diff

View file

@ -1,29 +1,29 @@
jceAverageCalculator jceAverageCalculator
==================== ====================
Compile with QT Compile with QT
Launch, insert your JCE username and password.<br> Launch, insert your JCE username and password.<br>
Once your logged in, go to Coure Tab and hit "ADD"<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> Now you will see all your courses in a table content<br>
<br> <br>
Edit your grade and see the average difference.<br> Edit your grade and see the average difference.<br>
Optional: <br> Optional: <br>
hit setting tab to select the date interval<br> hit setting tab to select the date interval<br>
p.s -> you need to clear the table before.<br> p.s -> you need to clear the table before.<br>
Thanks to <br> Thanks to <br>
<ul> <ul>
<li><a href='mailto:sagidayan@gmail.com'>Sagi Dayan</a></li> <li><a href='mailto:sagidayan@gmail.com'>Sagi Dayan</a></li>
<li><a href='mailto:nadav2051@gmail.com'>Nadav Luzzato</a></li> <li><a href='mailto:nadav2051@gmail.com'>Nadav Luzzato</a></li>
</ul> </ul>
Made by Made by
<ul> <ul>
<li><a href='mailto:liranbg@gmail.com'>Liran Ben Gida</a></li> <li><a href='mailto:liranbg@gmail.com'>Liran Ben Gida</a></li>
</ul> </ul>

View file

@ -1,51 +1,51 @@
#------------------------------------------------- #-------------------------------------------------
# #
# Project created by QtCreator 2014-05-31T19:49:42 # Project created by QtCreator 2014-05-31T19:49:42
# #
#------------------------------------------------- #-------------------------------------------------
QT += core gui network QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = jceGrade TARGET = jceGrade
TEMPLATE = app TEMPLATE = app
RC_FILE = appConfigure.rc RC_FILE = appConfigure.rc
CONFIG += c++11 static console CONFIG += c++11 static
SOURCES += main/coursestablemanager.cpp \ SOURCES += main/coursestablemanager.cpp \
main/loginhandler.cpp \ main/loginhandler.cpp \
main/main.cpp \ main/main.cpp \
main/mainscreen.cpp \ main/mainscreen.cpp \
src/connection/qtsslsocket.cpp \ src/connection/qtsslsocket.cpp \
src/user.cpp \ src/user.cpp \
src/grades/Course.cpp \ src/grades/Course.cpp \
src/grades/GradePage.cpp \ src/grades/GradePage.cpp \
src/grades/Page.cpp \ src/grades/Page.cpp \
src/jce/jcedate.cpp \ src/jce/jcedate.cpp \
src/jce/jcelogin.cpp \ src/jce/jcelogin.cpp \
src/data/savedata.cpp src/data/savedata.cpp
HEADERS += main/coursestablemanager.h \ HEADERS += main/coursestablemanager.h \
main/loginhandler.h \ main/loginhandler.h \
main/mainscreen.h \ main/mainscreen.h \
src/connection/qtsslsocket.h \ src/connection/qtsslsocket.h \
src/user.h \ src/user.h \
src/grades/Course.h \ src/grades/Course.h \
src/grades/GradePage.h \ src/grades/GradePage.h \
src/grades/Page.h \ src/grades/Page.h \
src/jce/jcedate.h \ src/jce/jcedate.h \
src/jce/jcelogin.h \ src/jce/jcelogin.h \
src/jce/jceLoginHtmlScripts.h \ src/jce/jceLoginHtmlScripts.h \
src/data/savedata.h src/data/savedata.h
FORMS += \ FORMS += \
main/mainscreen.ui main/mainscreen.ui
OTHER_FILES += OTHER_FILES +=
RESOURCES += \ RESOURCES += \
resources/connectionstatus.qrc resources/connectionstatus.qrc

View file

@ -1,252 +1,252 @@
#include "coursestablemanager.h" #include "coursestablemanager.h"
coursesTableManager::coursesTableManager(QTableWidget *ptr, user *usrPtr) coursesTableManager::coursesTableManager(QTableWidget *ptr, user *usrPtr)
{ {
this->gp = NULL; this->gp = NULL;
this->us = usrPtr; this->us = usrPtr;
this->courseTBL = ptr; this->courseTBL = ptr;
/* /*
* Initilizing Table * Initilizing Table
*/ */
courseTBL->setRowCount(0); courseTBL->setRowCount(0);
courseTBL->setColumnCount(COURSE_FIELDS); courseTBL->setColumnCount(COURSE_FIELDS);
QStringList mz; QStringList mz;
mz << "Serial" << "Name" << "Type" << "Points" << "Hours" << "Grade" << "Additions"; mz << "Serial" << "Name" << "Type" << "Points" << "Hours" << "Grade" << "Additions";
courseTBL->setHorizontalHeaderLabels(mz); courseTBL->setHorizontalHeaderLabels(mz);
courseTBL->verticalHeader()->setVisible(true); courseTBL->verticalHeader()->setVisible(true);
courseTBL->setSelectionMode(QAbstractItemView::SingleSelection); courseTBL->setSelectionMode(QAbstractItemView::SingleSelection);
courseTBL->setShowGrid(true); courseTBL->setShowGrid(true);
courseTBL->setStyleSheet("QTableView {selection-background-color: red;}"); courseTBL->setStyleSheet("QTableView {selection-background-color: red;}");
} }
coursesTableManager::~coursesTableManager() coursesTableManager::~coursesTableManager()
{ {
courseTBL = NULL; courseTBL = NULL;
delete gp; delete gp;
gp=NULL; gp=NULL;
} }
/** /**
* @brief coursesTableManager::insertJceCoursesIntoTable phrasing the course list to rows in table * @brief coursesTableManager::insertJceCoursesIntoTable phrasing the course list to rows in table
*/ */
void coursesTableManager::insertJceCoursesIntoTable() void coursesTableManager::insertJceCoursesIntoTable()
{ {
for (Course *c: *gp->getCourses()) for (Course *c: *gp->getCourses())
{ {
if (us->getInfluenceCourseOnly()) if (us->getInfluenceCourseOnly())
{ {
if (isCourseInfluence(c)) if (isCourseInfluence(c))
addRow(c); addRow(c);
} }
else else
addRow(c); addRow(c);
} }
} }
/** /**
* @brief coursesTableManager::setCoursesList creating courses list with given html page * @brief coursesTableManager::setCoursesList creating courses list with given html page
* @param html * @param html
*/ */
void coursesTableManager::setCoursesList(std::string &html) void coursesTableManager::setCoursesList(std::string &html)
{ {
gp = new GradePage(html); gp = new GradePage(html);
} }
/** /**
* @brief coursesTableManager::changes when user changes the table manually it updates it * @brief coursesTableManager::changes when user changes the table manually it updates it
* @param change string change * @param change string change
* @param row row index * @param row row index
* @param col col index * @param col col index
* @return if change has been done * @return if change has been done
*/ */
bool coursesTableManager::changes(QString change, int row, int col) bool coursesTableManager::changes(QString change, int row, int col)
{ {
bool isNumFlag = true; bool isNumFlag = true;
int serialCourse = courseTBL->item(row,Course::CourseScheme::SERIAL)->text().toInt(); int serialCourse = courseTBL->item(row,Course::CourseScheme::SERIAL)->text().toInt();
for (Course *c: *gp->getCourses()) for (Course *c: *gp->getCourses())
{ {
if (c->getSerialNum() == serialCourse) if (c->getSerialNum() == serialCourse)
{ {
switch (col) switch (col)
{ {
case (Course::CourseScheme::NAME): case (Course::CourseScheme::NAME):
c->setName(change.toStdString()); c->setName(change.toStdString());
break; break;
case (Course::CourseScheme::TYPE): case (Course::CourseScheme::TYPE):
c->setType(change.toStdString()); c->setType(change.toStdString());
break; break;
case (Course::CourseScheme::POINTS): case (Course::CourseScheme::POINTS):
{ {
change.toDouble(&isNumFlag); change.toDouble(&isNumFlag);
if (!isNumFlag) if (!isNumFlag)
{ {
courseTBL->item(row,col)->setText(QString::number(c->getPoints())); courseTBL->item(row,col)->setText(QString::number(c->getPoints()));
} }
else else
c->setPoints(change.toDouble()); c->setPoints(change.toDouble());
break; break;
} }
case (Course::CourseScheme::HOURS): case (Course::CourseScheme::HOURS):
{ {
change.toDouble(&isNumFlag); change.toDouble(&isNumFlag);
if (!isNumFlag) if (!isNumFlag)
{ {
courseTBL->item(row,col)->setText(QString::number(c->getHours())); courseTBL->item(row,col)->setText(QString::number(c->getHours()));
} }
else else
c->setHours(change.toDouble()); c->setHours(change.toDouble());
break; break;
} }
case (Course::CourseScheme::GRADE): case (Course::CourseScheme::GRADE):
{ {
change.toDouble(&isNumFlag); change.toDouble(&isNumFlag);
if (!isNumFlag) if (!isNumFlag)
{ {
courseTBL->item(row,col)->setText(QString::number(c->getGrade())); courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
} }
else else
{ {
if ((change.toDouble() >= 0) && (change.toDouble() <= 100)) if ((change.toDouble() >= 0) && (change.toDouble() <= 100))
c->setGrade(change.toDouble()); c->setGrade(change.toDouble());
else else
courseTBL->item(row,col)->setText(QString::number(c->getGrade())); courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
} }
break; break;
} }
case (Course::CourseScheme::ADDITION): case (Course::CourseScheme::ADDITION):
c->setAdditions(change.toStdString()); c->setAdditions(change.toStdString());
break; break;
} }
break; break;
} }
} }
return isNumFlag; return isNumFlag;
} }
/** /**
* @brief coursesTableManager::addRow adds row with given information * @brief coursesTableManager::addRow adds row with given information
* @param courseToAdd if exists, add its information to table * @param courseToAdd if exists, add its information to table
*/ */
void coursesTableManager::addRow(const Course *courseToAdd) void coursesTableManager::addRow(const Course *courseToAdd)
{ {
int i,j; int i,j;
i = courseTBL->rowCount(); i = courseTBL->rowCount();
j = 0; j = 0;
QTableWidgetItem *serial,*name,*type,*points,*hours,*grade,*addition; QTableWidgetItem *serial,*name,*type,*points,*hours,*grade,*addition;
const Course * c; const Course * c;
if (courseToAdd != NULL) if (courseToAdd != NULL)
{ {
c = courseToAdd; c = courseToAdd;
if (!isCourseAlreadyInserted(c->getSerialNum())) if (!isCourseAlreadyInserted(c->getSerialNum()))
{ {
courseTBL->setRowCount(courseTBL->rowCount()+1); courseTBL->setRowCount(courseTBL->rowCount()+1);
serial = new QTableWidgetItem(QString::number(c->getSerialNum())); serial = new QTableWidgetItem(QString::number(c->getSerialNum()));
serial->setFlags(serial->flags() & ~Qt::ItemIsEditable); serial->setFlags(serial->flags() & ~Qt::ItemIsEditable);
points = new QTableWidgetItem(QString::number(c->getPoints())); points = new QTableWidgetItem(QString::number(c->getPoints()));
points->setFlags(serial->flags() & ~Qt::ItemIsEditable); points->setFlags(serial->flags() & ~Qt::ItemIsEditable);
hours = new QTableWidgetItem(QString::number(c->getHours())); hours = new QTableWidgetItem(QString::number(c->getHours()));
hours->setFlags(serial->flags() & ~Qt::ItemIsEditable); hours->setFlags(serial->flags() & ~Qt::ItemIsEditable);
grade = new QTableWidgetItem(QString::number(c->getGrade())); grade = new QTableWidgetItem(QString::number(c->getGrade()));
name = new QTableWidgetItem(QString::fromStdString(c->getName())); name = new QTableWidgetItem(QString::fromStdString(c->getName()));
name->setFlags(serial->flags() & ~Qt::ItemIsEditable); name->setFlags(serial->flags() & ~Qt::ItemIsEditable);
type = new QTableWidgetItem(QString::fromStdString(c->getType())); type = new QTableWidgetItem(QString::fromStdString(c->getType()));
type->setFlags(serial->flags() & ~Qt::ItemIsEditable); type->setFlags(serial->flags() & ~Qt::ItemIsEditable);
addition = new QTableWidgetItem(QString::fromStdString(c->getAddidtions())); addition = new QTableWidgetItem(QString::fromStdString(c->getAddidtions()));
courseTBL->setItem(i,j++,serial); courseTBL->setItem(i,j++,serial);
courseTBL->setItem(i,j++,name); courseTBL->setItem(i,j++,name);
courseTBL->setItem(i,j++,type); courseTBL->setItem(i,j++,type);
courseTBL->setItem(i,j++,points); courseTBL->setItem(i,j++,points);
courseTBL->setItem(i,j++,hours); courseTBL->setItem(i,j++,hours);
courseTBL->setItem(i,j++,grade); courseTBL->setItem(i,j++,grade);
courseTBL->setItem(i,j,addition); courseTBL->setItem(i,j,addition);
} }
} }
else else
{ {
} }
courseTBL->resizeColumnsToContents(); courseTBL->resizeColumnsToContents();
} }
double coursesTableManager::getAvg() double coursesTableManager::getAvg()
{ {
if (this->gp != NULL) if (this->gp != NULL)
return gp->getAvg(); return gp->getAvg();
return 0; return 0;
} }
void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus) void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus)
{ {
if (ignoreCourseStatus) if (ignoreCourseStatus)
{ {
int i = 0; int i = 0;
while (i < courseTBL->rowCount()) while (i < courseTBL->rowCount())
{ {
if (courseTBL->item(i,Course::CourseScheme::POINTS)->text().compare("0") == 0) if (courseTBL->item(i,Course::CourseScheme::POINTS)->text().compare("0") == 0)
courseTBL->removeRow(i--); courseTBL->removeRow(i--);
i++; i++;
} }
} }
else else
{ {
for (Course *c: *gp->getCourses()) for (Course *c: *gp->getCourses())
{ {
if (!(isCourseAlreadyInserted(c->getSerialNum()))) if (!(isCourseAlreadyInserted(c->getSerialNum())))
if (c->getPoints() == 0) if (c->getPoints() == 0)
addRow(c); addRow(c);
} }
} }
} }
void coursesTableManager::clearTable() void coursesTableManager::clearTable()
{ {
if (courseTBL->rowCount() == 0) if (courseTBL->rowCount() == 0)
return; return;
int i = 0; //starting point int i = 0; //starting point
while (courseTBL->rowCount() > i) while (courseTBL->rowCount() > i)
{ {
gp->removeCourse(courseTBL->item(i,Course::CourseScheme::SERIAL)->text().toStdString()); gp->removeCourse(courseTBL->item(i,Course::CourseScheme::SERIAL)->text().toStdString());
courseTBL->removeRow(i); courseTBL->removeRow(i);
} }
gp = NULL; gp = NULL;
courseTBL->repaint(); courseTBL->repaint();
} }
Course *coursesTableManager::getCourseByRow(int row) Course *coursesTableManager::getCourseByRow(int row)
{ {
QString courseSerial = courseTBL->item(row,Course::CourseScheme::SERIAL)->text(); QString courseSerial = courseTBL->item(row,Course::CourseScheme::SERIAL)->text();
for (Course *c: *gp->getCourses()) for (Course *c: *gp->getCourses())
{ {
if (c->getSerialNum() == courseSerial.toDouble()) if (c->getSerialNum() == courseSerial.toDouble())
return c; return c;
} }
return NULL; return NULL;
} }
bool coursesTableManager::isCourseAlreadyInserted(double courseID) bool coursesTableManager::isCourseAlreadyInserted(double courseID)
{ {
int i=0; int i=0;
for (i = 0; i < courseTBL->rowCount(); ++i) for (i = 0; i < courseTBL->rowCount(); ++i)
{ {
QString courseSerial = courseTBL->item(i,Course::CourseScheme::SERIAL)->text(); QString courseSerial = courseTBL->item(i,Course::CourseScheme::SERIAL)->text();
if (QString::number(courseID) == courseSerial) if (QString::number(courseID) == courseSerial)
return true; return true;
} }
return false; return false;
} }
bool coursesTableManager::isCourseInfluence(const Course *courseToCheck) bool coursesTableManager::isCourseInfluence(const Course *courseToCheck)
{ {
if (courseToCheck->getPoints() > 0) if (courseToCheck->getPoints() > 0)
return true; return true;
return false; return false;
} }

View file

@ -1,44 +1,44 @@
#ifndef COURSESTABLEMANAGER_H #ifndef COURSESTABLEMANAGER_H
#define COURSESTABLEMANAGER_H #define COURSESTABLEMANAGER_H
#include <QApplication> #include <QApplication>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include <QHeaderView> #include <QHeaderView>
#include <QMessageBox> #include <QMessageBox>
#include <QTableWidget> #include <QTableWidget>
#include <QString> #include <QString>
#include <QMessageBox> #include <QMessageBox>
#include <list> #include <list>
#include "src/grades/Course.h" #include "src/grades/Course.h"
#include "src/grades/GradePage.h" #include "src/grades/GradePage.h"
#include "src/user.h" #include "src/user.h"
class coursesTableManager class coursesTableManager
{ {
public: public:
coursesTableManager(QTableWidget *, user *usrPtr); coursesTableManager(QTableWidget *, user *usrPtr);
~coursesTableManager(); ~coursesTableManager();
void insertJceCoursesIntoTable(); void insertJceCoursesIntoTable();
void setCoursesList(std::string &htmlPage); void setCoursesList(std::string &htmlPage);
bool changes(QString change, int row, int col); bool changes(QString change, int row, int col);
void addRow(const Course * courseToAdd = 0); void addRow(const Course * courseToAdd = 0);
double getAvg(); double getAvg();
void influnceCourseChanged(bool status); void influnceCourseChanged(bool status);
void clearTable(); void clearTable();
private: private:
QTableWidget *courseTBL; QTableWidget *courseTBL;
GradePage *gp; GradePage *gp;
user *us; user *us;
Course * getCourseByRow(int row); Course * getCourseByRow(int row);
bool isCourseAlreadyInserted(double courseID); bool isCourseAlreadyInserted(double courseID);
bool isCourseInfluence(const Course *courseToCheck); bool isCourseInfluence(const Course *courseToCheck);
}; };
#endif // COURSESTABLEMANAGER_H #endif // COURSESTABLEMANAGER_H

View file

@ -1,67 +1,67 @@
#include "loginhandler.h" #include "loginhandler.h"
loginHandler::loginHandler(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr) loginHandler::loginHandler()
{ {
this->jceLog = ptr;
this->statusLabelPtr = statusLabelPtr; }
this->pswdEditPtr = pswdEditPtr; void loginHandler::setPointers(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr)
this->usrnmEditPtr = usrnmEditPtr; {
} this->jceLog = ptr;
this->statusLabelPtr = statusLabelPtr;
bool loginHandler::makeConnection() this->pswdEditPtr = pswdEditPtr;
{ this->usrnmEditPtr = usrnmEditPtr;
if (this->jceLog == NULL) }
{
return false; bool loginHandler::makeConnection()
} {
try if (this->jceLog == NULL)
{ return false;
jceLog->makeConnection();
} try
catch (jceLogin::jceStatus &a) {
{ jceLog->makeConnection();
}
if (a == jceLogin::JCE_YOU_ARE_IN) catch (jceLogin::jceStatus &a)
{ {
return true;
} if (a == jceLogin::JCE_YOU_ARE_IN)
else if (a == jceLogin::ERROR_ON_VALIDATION) {
{ return true;
popMessage("check your password"); }
else if (a == jceLogin::ERROR_ON_VALIDATION)
usrnmEditPtr->setDisabled(false); {
pswdEditPtr->setDisabled(false); popMessage("check your password");
pswdEditPtr->selectAll(); usrnmEditPtr->setDisabled(false);
pswdEditPtr->setFocus(); pswdEditPtr->setDisabled(false);
return false;
} pswdEditPtr->selectAll();
else if (a == jceLogin::ERROR_ON_OPEN_SOCKET) pswdEditPtr->setFocus();
{ return false;
popMessage("Please check your internet status"); }
else if (a == jceLogin::ERROR_ON_OPEN_SOCKET)
jceLog->closeAll(); {
popMessage("Please check your Internet status");
return false; jceLog->closeAll();
} return false;
else if (a == jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED) }
{ 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"); popMessage("You were blocked, please wait couple of minutes or contact JCE");
jceLog->closeAll(); jceLog->closeAll();
return false; return false;
} }
} }
return false; return false;
} }
void loginHandler::popMessage(QString message) void loginHandler::popMessage(QString message)
{ {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setWindowTitle("Error"); msgBox.setWindowTitle("Error");
msgBox.setText(message); msgBox.setText(message);
msgBox.exec(); msgBox.exec();
msgBox.setFocus(); msgBox.setFocus();
} }

View file

@ -1,29 +1,31 @@
#ifndef LOGINHANDLER_H #ifndef LOGINHANDLER_H
#define LOGINHANDLER_H #define LOGINHANDLER_H
#include <QString> #include <QString>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QMessageBox> #include <QMessageBox>
#include <QPixmap> #include <QPixmap>
#include "src/jce/jcelogin.h" #include "src/jce/jcelogin.h"
#include "./src/data/savedata.h"
class loginHandler
{ class loginHandler
public: {
loginHandler(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr); public:
bool makeConnection(); loginHandler();
void setPointers(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr);
private: bool makeConnection();
void popMessage(QString message); private:
void popMessage(QString message);
jceLogin *jceLog;
QLabel *statusLabelPtr; jceLogin *jceLog;
QLineEdit *pswdEditPtr;
QLineEdit *usrnmEditPtr; QLabel *statusLabelPtr;
}; QLineEdit *pswdEditPtr;
QLineEdit *usrnmEditPtr;
#endif // LOGINHANDLER_H };
#endif // LOGINHANDLER_H

View file

@ -1,11 +1,11 @@
#include "mainscreen.h" #include "mainscreen.h"
#include <QApplication> #include <QApplication>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
MainScreen w; MainScreen w;
w.show(); w.show();
return a.exec(); return a.exec();
} }

View file

@ -1,268 +1,286 @@
#include "mainscreen.h" #include "mainscreen.h"
#include "ui_mainscreen.h" #include "ui_mainscreen.h"
MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScreen) MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScreen)
{ {
ui->setupUi(this); ui->setupUi(this);
this->setFixedSize(this->size()); //main not resizeable this->setFixedSize(this->size()); //main not resizeable
//Login Tab //Login Tab
ui->pswdLineEdit->setEchoMode((QLineEdit::Password)); ui->pswdLineEdit->setEchoMode((QLineEdit::Password));
//Status Bar //Status Bar
ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };"); ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };");
ButtomStatusLabel = new QLabel(this); ButtomStatusLabel = new QLabel(this);
statusLabel = new QLabel(this); statusLabel = new QLabel(this);
ui->statusBar->setMaximumSize(this->geometry().width(),StatusIconHeight); ui->statusBar->setMaximumSize(this->geometry().width(),StatusIconHeight);
ui->statusBar->addPermanentWidget(ButtomStatusLabel,0); ui->statusBar->addPermanentWidget(ButtomStatusLabel,0);
ui->statusBar->addPermanentWidget(statusLabel,1); ui->statusBar->addPermanentWidget(statusLabel,1);
setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
//Course and Setting Tab //Course and Setting Tab
ui->CoursesTab->setDisabled(true); ui->CoursesTab->setDisabled(true);
ui->SettingsTab->setDisabled(true); ui->SettingsTab->setDisabled(true);
ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue)); ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue));
//Pointer allocating //Pointer allocating
this->jceLog = NULL; this->jceLog = NULL;
this->userLoginSetting = new user("",""); this->userLoginSetting = new user("","");
this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting); this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting);
this->loginHandel = new loginHandler();
updateDates(); updateDates();
} //check login File
SaveData::init();
MainScreen::~MainScreen() if (SaveData::isSaved())
{ {
delete userLoginSetting; ui->usrnmLineEdit->setText(SaveData::getUsername());
delete jceLog; ui->pswdLineEdit->setText(SaveData::getPassword());
delete ui; ui->keepLogin->setChecked(true);
} }
void MainScreen::on_ratesButton_clicked() }
{
QTextEdit phrase; MainScreen::~MainScreen()
std::string pageString; {
if (this->jceLog != NULL) delete userLoginSetting;
{ delete jceLog;
if (jceLog->getGrades()) delete loginHandel;
{ delete ui;
phrase.setText(QString::fromStdString(jceLog->getPage())); }
pageString = phrase.toPlainText().toStdString(); void MainScreen::on_ratesButton_clicked()
courseTableMgr->setCoursesList(pageString); {
courseTableMgr->insertJceCoursesIntoTable(); QTextEdit phrase;
} std::string pageString;
} if (this->jceLog != NULL)
{
} if (jceLog->getGrades())
{
void MainScreen::on_spinBoxFromYear_editingFinished() phrase.setText(QString::fromStdString(jceLog->getPage()));
{ pageString = phrase.toPlainText().toStdString();
if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value()) courseTableMgr->setCoursesList(pageString);
{ courseTableMgr->insertJceCoursesIntoTable();
ui->spinBoxFromYear->setValue(ui->spinBoxToYear->value()); }
ui->spinBoxFromYear->setFocus(); }
updateDates();
} }
else
updateDates(); void MainScreen::on_spinBoxFromYear_editingFinished()
} {
void MainScreen::on_spinBoxToYear_editingFinished() if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value())
{ {
if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value()) ui->spinBoxFromYear->setValue(ui->spinBoxToYear->value());
{ ui->spinBoxFromYear->setFocus();
ui->spinBoxToYear->setValue(ui->spinBoxFromYear->value()); updateDates();
ui->spinBoxToYear->setFocus(); }
updateDates(); else
} updateDates();
else }
updateDates(); void MainScreen::on_spinBoxToYear_editingFinished()
} {
void MainScreen::on_spinBoxFromSem_editingFinished() if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value())
{ {
if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value()) ui->spinBoxToYear->setValue(ui->spinBoxFromYear->value());
{ ui->spinBoxToYear->setFocus();
if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value()) updateDates();
{ }
ui->spinBoxFromSem->setValue(ui->spinBoxToSemester->value()); else
ui->spinBoxFromSem->setFocus(); updateDates();
} }
} void MainScreen::on_spinBoxFromSem_editingFinished()
updateDates(); {
} if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value())
void MainScreen::on_spinBoxToSemester_editingFinished() {
{ if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value())
if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value()) {
{ ui->spinBoxFromSem->setValue(ui->spinBoxToSemester->value());
if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value()) ui->spinBoxFromSem->setFocus();
{ }
ui->spinBoxToSemester->setValue(ui->spinBoxFromSem->value()); }
ui->spinBoxToSemester->setFocus(); updateDates();
} }
} void MainScreen::on_spinBoxToSemester_editingFinished()
updateDates(); {
} if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value())
{
void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item) if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value())
{ {
if (this->courseTableMgr->changes(item->text(),item->row(),item->column())) ui->spinBoxToSemester->setValue(ui->spinBoxFromSem->value());
ui->avgLCD->display(courseTableMgr->getAvg()); ui->spinBoxToSemester->setFocus();
else }
QMessageBox::critical(this,"Error","Missmatching data"); }
} updateDates();
}
void MainScreen::on_loginButton_clicked()
{ void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item)
if (this->jceLog == NULL) {
uiSetConnectMode(); if (this->courseTableMgr->changes(item->text(),item->row(),item->column()))
else ui->avgLCD->display(courseTableMgr->getAvg());
{ else
if (jceLog->isLoginFlag() == true) QMessageBox::critical(this,"Error","Missmatching data");
uiSetDisconnectMode(); }
else
uiSetConnectMode(); void MainScreen::on_loginButton_clicked()
} {
if (this->jceLog == NULL)
} uiSetConnectMode();
else
void MainScreen::on_checkBox_toggled(bool checked) {
{ if (jceLog->isLoginFlag() == true)
this->userLoginSetting->setInfluenceCourseOnly(checked); uiSetDisconnectMode();
this->courseTableMgr->influnceCourseChanged(checked); else
} uiSetConnectMode();
void MainScreen::on_usrnmLineEdit_editingFinished() }
{
ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); }
}
void MainScreen::updateDates() void MainScreen::on_checkBox_toggled(bool checked)
{ {
std::string fy,ty,fs,ts; this->userLoginSetting->setInfluenceCourseOnly(checked);
fy = std::to_string(ui->spinBoxFromYear->value()); this->courseTableMgr->influnceCourseChanged(checked);
ty = std::to_string(ui->spinBoxToYear->value()); }
fs = std::to_string(ui->spinBoxFromSem->value()); void MainScreen::on_usrnmLineEdit_editingFinished()
ts = std::to_string(ui->spinBoxToSemester->value()); {
userLoginSetting->setDate(fy,fs,ty,ts); ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower());
} }
void MainScreen::updateDates()
void MainScreen::uiSetDisconnectMode() {
{ std::string fy,ty,fs,ts;
setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); fy = std::to_string(ui->spinBoxFromYear->value());
ui->usrnmLineEdit->setText(""); ty = std::to_string(ui->spinBoxToYear->value());
ui->pswdLineEdit->setText(""); fs = std::to_string(ui->spinBoxFromSem->value());
ui->usrnmLineEdit->setEnabled(true); ts = std::to_string(ui->spinBoxToSemester->value());
ui->pswdLineEdit->setEnabled(true); userLoginSetting->setDate(fy,fs,ty,ts);
}
delete jceLog;
jceLog = NULL; void MainScreen::uiSetDisconnectMode()
ui->loginButton->setText("&Login"); {
this->ui->ratesButton->setDisabled(true); setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
return; ui->usrnmLineEdit->setText("");
} ui->pswdLineEdit->setText("");
ui->usrnmLineEdit->setEnabled(true);
void MainScreen::uiSetConnectMode() ui->pswdLineEdit->setEnabled(true);
{
std::string page; delete jceLog;
jceLog = NULL;
if (this->jceLog != NULL) ui->loginButton->setText("&Login");
delete jceLog; this->ui->ratesButton->setDisabled(true);
return;
string username; }
string password;
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) void MainScreen::uiSetConnectMode() //fix before distrbute
{ {
//add icon near to username and password to mark it std::string page;
return;
} if (this->jceLog != NULL)
setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS); delete jceLog;
username = ui->usrnmLineEdit->text().toStdString(); string username;
password = ui->pswdLineEdit->text().toStdString(); string password;
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty()))
ui->usrnmLineEdit->setDisabled(true); {
ui->pswdLineEdit->setDisabled(true); //add icon near to username and password to mark it
return;
userLoginSetting->setUsername(username); }
userLoginSetting->setPassword(password); setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS);
this->repaint(); username = ui->usrnmLineEdit->text().toStdString();
page = "connecting with username "; password = ui->pswdLineEdit->text().toStdString();
page = username;
page += "and password: "; ui->usrnmLineEdit->setDisabled(true);
page += password; ui->pswdLineEdit->setDisabled(true);
ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page));
userLoginSetting->setUsername(username);
jceLog = new jceLogin(userLoginSetting); userLoginSetting->setPassword(password);
this->loginHandel = new loginHandler(jceLog,statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit);
this->repaint();
if (loginHandel->makeConnection() == true) page = "connecting with username ";
{ page = username;
page = this->jceLog->getPage(); page += "and password: ";
ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page)); page += password;
setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN); ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page));
ui->loginButton->setText("&Logout");
this->ui->ratesButton->setEnabled(true); jceLog = new jceLogin(userLoginSetting);
ui->CoursesTab->setEnabled(true); this->loginHandel->setPointers(jceLog,statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit);
ui->SettingsTab->setEnabled(true);
} if (loginHandel->makeConnection() == true)
else {
{ page = this->jceLog->getPage();
uiSetDisconnectMode(); ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page));
} setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN);
} ui->loginButton->setText("&Logout");
void MainScreen::setLabelConnectionStatus(jceLogin::jceStatus statusDescription) this->ui->ratesButton->setEnabled(true);
{ ui->CoursesTab->setEnabled(true);
QPixmap iconPix; ui->SettingsTab->setEnabled(true);
switch (statusDescription) }
{ else
{
case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS: uiSetDisconnectMode();
iconPix.load(":/icons/blueStatusIcon.png"); }
statusLabel->setText("Connecting"); }
break; void MainScreen::setLabelConnectionStatus(jceLogin::jceStatus statusDescription)
case jceLogin::jceStatus::JCE_YOU_ARE_IN: {
iconPix.load(":/icons/greenStatusIcon.png"); QPixmap iconPix;
statusLabel->setText("Connected"); switch (statusDescription)
break; {
default:
iconPix.load(":/icons/redStatusIcon.png"); case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS:
statusLabel->setText("Disconnected"); iconPix.load(":/icons/blueStatusIcon.png");
break; statusLabel->setText("Connecting");
} break;
ButtomStatusLabel->setPixmap(iconPix); case jceLogin::jceStatus::JCE_YOU_ARE_IN:
iconPix.load(":/icons/greenStatusIcon.png");
this->repaint(); statusLabel->setText("Connected");
} break;
void MainScreen::on_actionCredits_triggered() default:
{ iconPix.load(":/icons/redStatusIcon.png");
QMessageBox::about(this, "About", "A tiny application to calculate your grades average. <br><br>" statusLabel->setText("Disconnected");
"This software is licensed under Qt5's <br>GNU LESSER GENERAL PUBLIC LICENSE V2<br>" break;
"The source code is available at github:<br>" }
"<a href='https://github.com/liranbg/jceAverageCalculator'>jceAverageCalculator Repository</a>" ButtomStatusLabel->setPixmap(iconPix);
"<br><br>This front end is Powered by <a href='https://github.com/liranbg/jceConnection'>Jce Connection</a><br><br>"
"Made by:" this->repaint();
"<ul>" }
"<li><a href='mailto:liranbg@gmail.com'>Liran Ben Gida</a></li>" void MainScreen::on_actionCredits_triggered()
"</ul>" {
"Thanks to: " QMessageBox::about(this, "About", "A tiny application to calculate your grades average. <br><br>"
"<ul>" "This software is licensed under Qt5's <br>GNU LESSER GENERAL PUBLIC LICENSE V2<br>"
"<li><a href='mailto:sagidayan@gmail.com'>Sagi Dayan</a></li>" "The source code is available at github:<br>"
"<li><a href='mailto:nadav2051@gmail.com'>Nadav Luzzato</a></li>" "<a href='https://github.com/liranbg/jceAverageCalculator'>jceAverageCalculator Repository</a>"
"</ul>"); "<br><br>This front end is Powered by <a href='https://github.com/liranbg/jceConnection'>Jce Connection</a><br><br>"
} "Made by:"
"<ul>"
void MainScreen::on_clearTableButton_clicked() "<li><a href='mailto:liranbg@gmail.com'>Liran Ben Gida</a></li>"
{ "</ul>"
"Thanks to: "
courseTableMgr->clearTable(); "<ul>"
ui->avgLCD->display(courseTableMgr->getAvg()); "<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_actionExit_triggered() }
{
exit(0); 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();
}

View file

@ -1,78 +1,80 @@
#ifndef MAINSCREEN_H #ifndef MAINSCREEN_H
#define MAINSCREEN_H #define MAINSCREEN_H
#include <QMainWindow> #include <QMainWindow>
#include <QApplication> #include <QApplication>
#include <QString> #include <QString>
#include <QMessageBox> #include <QMessageBox>
#include <QTextEdit> #include <QTextEdit>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include "src/grades/GradePage.h" #include "src/grades/GradePage.h"
#include "src/jce/jcelogin.h" #include "src/jce/jcelogin.h"
#include "coursestablemanager.h" #include "coursestablemanager.h"
#include "loginhandler.h" #include "loginhandler.h"
#define StatusIconHeight 35 #define StatusIconHeight 35
namespace Ui { namespace Ui {
class MainScreen; class MainScreen;
} }
class MainScreen : public QMainWindow class MainScreen : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
MainScreen(QWidget *parent = 0); MainScreen(QWidget *parent = 0);
~MainScreen(); ~MainScreen();
private slots: private slots:
void on_ratesButton_clicked(); void on_ratesButton_clicked();
void on_spinBoxFromYear_editingFinished(); void on_spinBoxFromYear_editingFinished();
void on_spinBoxFromSem_editingFinished(); void on_spinBoxFromSem_editingFinished();
void on_spinBoxToYear_editingFinished(); void on_spinBoxToYear_editingFinished();
void on_spinBoxToSemester_editingFinished(); void on_spinBoxToSemester_editingFinished();
void on_loginButton_clicked(); void on_loginButton_clicked();
void on_checkBox_toggled(bool checked); void on_checkBox_toggled(bool checked);
void on_usrnmLineEdit_editingFinished(); void on_usrnmLineEdit_editingFinished();
void on_actionCredits_triggered(); void on_actionCredits_triggered();
void on_clearTableButton_clicked(); void on_clearTableButton_clicked();
void on_actionExit_triggered(); void on_actionExit_triggered();
void on_coursesTable_itemChanged(QTableWidgetItem *item); void on_coursesTable_itemChanged(QTableWidgetItem *item);
private: void on_keepLogin_clicked();
void updateDates(); private:
void uiSetDisconnectMode();
void uiSetConnectMode(); void updateDates();
void setLabelConnectionStatus(jceLogin::jceStatus statusDescription); void uiSetDisconnectMode();
void uiSetConnectMode();
Ui::MainScreen *ui; void setLabelConnectionStatus(jceLogin::jceStatus statusDescription);
jceLogin *jceLog; Ui::MainScreen *ui;
user *userLoginSetting;
jceLogin *jceLog;
coursesTableManager *courseTableMgr; user *userLoginSetting;
loginHandler *loginHandel;
coursesTableManager *courseTableMgr;
QLabel *ButtomStatusLabel; loginHandler *loginHandel;
QLabel *statusLabel;
QLabel *ButtomStatusLabel;
}; QLabel *statusLabel;
#endif // MAINSCREEN_H };
#endif // MAINSCREEN_H

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,8 @@
<RCC> <RCC>
<qresource prefix="/icons"> <qresource prefix="/icons">
<file>blueStatusIcon.png</file> <file>blueStatusIcon.png</file>
<file>greenStatusIcon.png</file> <file>greenStatusIcon.png</file>
<file>redStatusIcon.png</file> <file>redStatusIcon.png</file>
<file>icon.png</file> <file>icon.png</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -1,37 +1,66 @@
#include "qtsslsocket.h" #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 = new QSslSocket();
socket->connectToHostEncrypted(server.c_str(), port); }
if (socket->waitForEncrypted())
flag = true;
qtsslsocket::~qtsslsocket() {
socket->close();
socket = NULL;
} }
bool qtsslsocket::isCon() bool qtsslsocket::isCon()
{ {
return flag; return ((flag) && (this->socket != NULL));
} }
//need to fix the method
bool qtsslsocket::send(std::string str) bool qtsslsocket::send(std::string str)
{ {
int status;
bool flag = isCon(); bool flag = isCon();
if (flag) if (flag) //if connected
this->socket->write(str.c_str()); {
status = socket->write(str.c_str(),str.length());
while (socket->waitForBytesWritten());
}
return flag; return flag;
} }
bool qtsslsocket::recieve(std::string &str) bool qtsslsocket::recieve(std::string &str)
{ {
bool flag = false; bool flag = false;
QString s = ""; QString s = "";
while (socket->waitForReadyRead(milisTimeOut)) while (socket->waitForReadyRead(milisTimeOut))
s.append((socket->readAll().data())); s.append(socket->readAll());
str = s.toStdString(); str = s.toStdString();
if (s.size() > 0) if (s.size() > 0)
flag = true; flag = true;
return flag; return flag;
} }

View file

@ -7,24 +7,24 @@
#include <QString> #include <QString>
#include <iostream> #include <iostream>
#include <string> #include <string>
#define milisTimeOut 5000 #define milisTimeOut 3000
class qtsslsocket : public QObject class qtsslsocket : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
qtsslsocket(std::string server,int port); qtsslsocket();
~qtsslsocket() { ~qtsslsocket();
socket->close();
socket = NULL; bool makeConnect(std::string server,int port);
}
bool isCon(); bool isCon();
bool send(std::string str); bool send(std::string str);
bool recieve(std::string &str); bool recieve(std::string &str);
private: private:
QSslSocket *socket; QSslSocket *socket;
bool flag; bool flag;
}; };

View file

@ -1,200 +1,200 @@
#include "savedata.h" #include "savedata.h"
/** /**
* @brief Checks the status tag in the file * @brief Checks the status tag in the file
* @return boolean the status * @return boolean the status
*/ */
bool SaveData::isSaved() bool SaveData::isSaved()
{ {
QString status; QString status;
QFile* file = new QFile(FILE_NAME); QFile* file = new QFile(FILE_NAME);
/* Opening file for read */ /* Opening file for read */
if(file->open(QIODevice::ReadOnly|QIODevice::Text)) if(file->open(QIODevice::ReadOnly|QIODevice::Text))
{ {
status = getValViaTag("status", file); status = getValViaTag("status", file);
if(status == "true") if(status == "true")
{ {
file->close(); //close & return file->close(); //close & return
return true; return true;
} }
return false; //close & return return false; //close & return
file->close(); file->close();
} }
/* If Faild to open */ /* If Faild to open */
std::cout << "Faild To Accsess file: " << FILE_NAME << std::endl; std::cout << "Faild To Accsess file: " << FILE_NAME << std::endl;
return false; return false;
} }
/** /**
* @brief This Function will modify the file, and save the data. * @brief This Function will modify the file, and save the data.
* @param username - QString * @param username - QString
* @param password - QString * @param password - QString
* @return true if saved - false if error * @return true if saved - false if error
*/ */
bool SaveData::save(QString username, QString password) bool SaveData::save(QString username, QString password)
{ {
std::cout << "Trying to save data..." << std::endl; std::cout << "Trying to save data..." << std::endl;
QFile file(FILE_NAME); QFile file(FILE_NAME);
if(!file.open(QIODevice::WriteOnly|QIODevice::Text)) if(!file.open(QIODevice::WriteOnly|QIODevice::Text))
return false; /* IO Error! */ return false; /* IO Error! */
QTextStream output(&file); QTextStream output(&file);
QString hash_pass = hashPassword(password); QString hash_pass = hashPassword(password);
output << "[status]true[/]\n[username]"<<username<<"[/]\n"<<"[password]"<<hash_pass<<"[/]"; //Un Hashed Password in string! output << "[status]true[/]\n[username]"<<username<<"[/]\n"<<"[password]"<<hash_pass<<"[/]"; //Un Hashed Password in string!
file.close(); file.close();
std::cout << "Saved!" << std::endl; std::cout << "Saved!" << std::endl;
return true; return true;
} }
/** /**
* @brief Deletes the data from file, and sets status tag to false. * @brief Deletes the data from file, and sets status tag to false.
* @return true if success * @return true if success
*/ */
bool SaveData::deleteData() bool SaveData::deleteData()
{ {
QFile file(FILE_NAME); QFile file(FILE_NAME);
if(!file.open(QIODevice::WriteOnly|QIODevice::Text)) if(!file.open(QIODevice::WriteOnly|QIODevice::Text))
return false; /* IO Error! */ return false; /* IO Error! */
QTextStream output(&file); QTextStream output(&file);
output << DEFAULT_DATA_EMPTY; output << DEFAULT_DATA_EMPTY;
file.close(); file.close();
return true; return true;
} }
/** /**
* @brief username getter * @brief username getter
* @return QString - username * @return QString - username
*/ */
QString SaveData::getUsername() QString SaveData::getUsername()
{ {
QString username = ""; QString username = "";
QFile* file = new QFile(FILE_NAME); QFile* file = new QFile(FILE_NAME);
/* Opening file for read */ /* Opening file for read */
if(file->open(QIODevice::ReadOnly|QIODevice::Text)) if(file->open(QIODevice::ReadOnly|QIODevice::Text))
username = getValViaTag("username", file); username = getValViaTag("username", file);
file->close(); file->close();
return username; return username;
} }
/** /**
* @brief getter for password * @brief getter for password
* @return QString - password * @return QString - password
*/ */
QString SaveData::getPassword() QString SaveData::getPassword()
{ {
QString pass = ""; QString pass = "";
QFile* file = new QFile(FILE_NAME); QFile* file = new QFile(FILE_NAME);
/* Opening file for read */ /* Opening file for read */
if(file->open(QIODevice::ReadOnly|QIODevice::Text)) if(file->open(QIODevice::ReadOnly|QIODevice::Text))
pass = getValViaTag("password", file); pass = getValViaTag("password", file);
file->close(); file->close();
pass = deHashPasword(pass); pass = deHashPasword(pass);
return pass; return pass;
} }
/** /**
* @brief This is A functions that will init the tags file. * @brief This is A functions that will init the tags file.
* if it exist - do nothing * if it exist - do nothing
* if there is no file, it will create it and run the deleteData function * if there is no file, it will create it and run the deleteData function
* so tags will be set. * so tags will be set.
*/ */
void SaveData::init() void SaveData::init()
{ {
QFile file(FILE_NAME); QFile file(FILE_NAME);
if(!file.exists()) if(!file.exists())
{ {
file.open(QIODevice::ReadWrite | QIODevice::Text); file.open(QIODevice::ReadWrite | QIODevice::Text);
file.close(); file.close();
deleteData(); deleteData();
} }
} }
/** /**
* @brief This function will return the vale of a given tag name. * @brief This function will return the vale of a given tag name.
* NOTE: valid tag names are : "status", "username", "password" * NOTE: valid tag names are : "status", "username", "password"
* if tag is invalid - will return "" - an empty QString! * if tag is invalid - will return "" - an empty QString!
* @param tag - QString, the tag name * @param tag - QString, the tag name
* @param file - a QFile pointer * @param file - a QFile pointer
* @return QString - the value in tag * @return QString - the value in tag
* NOTE: if NULL value, or an invalid tag name -> return "" (empty QString!) * NOTE: if NULL value, or an invalid tag name -> return "" (empty QString!)
*/ */
QString SaveData::getValViaTag(QString tag, QFile* file) QString SaveData::getValViaTag(QString tag, QFile* file)
{ {
QString val, line , tmpTag; QString val, line , tmpTag;
QTextStream textStream( file); QTextStream textStream( file);
while((line = textStream.readLine()) != NULL) while((line = textStream.readLine()) != NULL)
{ {
std::cout << "DEBUG: line => " << line.toStdString() << std::endl; std::cout << "DEBUG: line => " << line.toStdString() << std::endl;
for(int i = 0 ; i< line.length() ;++i) 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 ("[/") if(line[i] == '[' && line[i+1] != '/') //get open tag at begining of line and not end of tag ("[/")
{ {
i++; i++;
tmpTag = line.mid(i, tag.length()); tmpTag = line.mid(i, tag.length());
if(tmpTag == tag) if(tmpTag == tag)
{ {
i+= tag.length()+1; // i is now right after '[' i+= tag.length()+1; // i is now right after '['
int j = i; int j = i;
while(line[j] != '[')// put j at the end of the value while(line[j] != '[')// put j at the end of the value
j++; j++;
/* Then... the value is :*/ /* Then... the value is :*/
val = line.mid(i, j-i); val = line.mid(i, j-i);
std::cout << "DEBUG: ["<<tag.toStdString()<<"]"<<val.toStdString()<<"[/]"<<std::endl; std::cout << "DEBUG: ["<<tag.toStdString()<<"]"<<val.toStdString()<<"[/]"<<std::endl;
return val; return val;
} }
} }
} }
} }
return ""; //this will be as NULL return ""; //this will be as NULL
} }
/** /**
* @brief This function will provide the user the most basic security of the stored password. * @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, * it is NOT an encryption! it will store every char of the password as ascii encoded,
* separated by "-" for the deHsh func. * separated by "-" for the deHsh func.
* @param pass - a QString to "hash" * @param pass - a QString to "hash"
* @return QString - The "hashed" password * @return QString - The "hashed" password
*/ */
QString SaveData::hashPassword(QString pass) QString SaveData::hashPassword(QString pass)
{ {
QString hash=""; QString hash="";
int code; int code;
for(QChar c : pass) for(QChar c : pass)
{ {
code = (int)c.toLatin1(); code = (int)c.toLatin1();
hash.append(QString::number(code)); hash.append(QString::number(code));
hash.append("-"); hash.append("-");
} }
return hash; return hash;
} }
/** /**
* @brief This function will "dehash" the "hashed" password. * @brief This function will "dehash" the "hashed" password.
* uses standard c string.h strtok with the "-" as the choping points. * uses standard c string.h strtok with the "-" as the choping points.
* builds a QString from the ascii. * builds a QString from the ascii.
* @param pass - The hashed password * @param pass - The hashed password
* @return QString - password uncoded * @return QString - password uncoded
*/ */
QString SaveData::deHashPasword(QString pass) QString SaveData::deHashPasword(QString pass)
{ {
char* cpyPass = strdup(pass.toStdString().c_str()); char* cpyPass = strdup(pass.toStdString().c_str());
char* tok; char* tok;
char* ch; char* ch;
int val; int val;
QString password; QString password;
tok = strtok(cpyPass,"-"); tok = strtok(cpyPass,"-");
while (tok != NULL) while (tok != NULL)
{ {
ch = tok; ch = tok;
val = atoi(ch); val = atoi(ch);
password.append(val); password.append(val);
tok = strtok(NULL, "-"); tok = strtok(NULL, "-");
} }
return password; return password;
} }

View file

@ -1,54 +1,54 @@
#ifndef SAVEDATA_H #ifndef SAVEDATA_H
#define SAVEDATA_H #define SAVEDATA_H
/** /**
* SaveData Class * SaveData Class
* -------------------------------------- * --------------------------------------
* *
* all functions in this class are static! * all functions in this class are static!
* no need to create an object! * no need to create an object!
* *
* provides all the needed functions * provides all the needed functions
* for saving user data for JCE login. * for saving user data for JCE login.
* *
* the class will enteract with a file formated by tags for storing the valus. * the class will enteract with a file formated by tags for storing the valus.
* the file format is as sutch: * the file format is as sutch:
* *
* [status]Status Value[/] * [status]Status Value[/]
* [username]usernaem vale[/] * [username]usernaem vale[/]
* [password]hashed(not really) password vale[/] * [password]hashed(not really) password vale[/]
* *
* the class will create a file if not exists by calling Save Data::init() function. * the class will create a file if not exists by calling Save Data::init() function.
* *
* for more info about functions - see implantation * for more info about functions - see implantation
*/ */
/* QT libs */ /* QT libs */
#include <QString> #include <QString>
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
/* C/C++ libs */ /* C/C++ libs */
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <iostream> #include <iostream>
#define FILE_NAME "JAC_DB.dat" #define FILE_NAME "JAC_DB.dat"
#define DEFAULT_DATA_EMPTY "[status]false[/]\n[username][/]\n[password][/]" #define DEFAULT_DATA_EMPTY "[status]false[/]\n[username][/]\n[password][/]"
class SaveData class SaveData
{ {
public: public:
bool static isSaved(); bool static isSaved();
bool static save(QString username, QString password); bool static save(QString username, QString password);
bool static deleteData(); bool static deleteData();
QString static getUsername(); QString static getUsername();
QString static getPassword(); QString static getPassword();
void static init(); void static init();
private: private:
QString static getValViaTag(QString tag, QFile *file); QString static getValViaTag(QString tag, QFile *file);
QString static hashPassword(QString pass); QString static hashPassword(QString pass);
QString static deHashPasword(QString pass); QString static deHashPasword(QString pass);
}; };
#endif // SAVEDATA_H #endif // SAVEDATA_H

View file

@ -1,55 +1,55 @@
#include "Course.h" #include "Course.h"
Course::Course(int serial, std::string name, std::string type, double points, double hours, double grade, std::string additions) Course::Course(int serial, std::string name, std::string type, double points, double hours, double grade, std::string additions)
{ {
this->serialNum = serial; this->serialNum = serial;
this->name = name; this->name = name;
this->type = type; this->type = type;
this->points = points; this->points = points;
this->hours = hours; this->hours = hours;
this->grade = grade; this->grade = grade;
this->additions = additions; this->additions = additions;
} }
Course::~Course() Course::~Course()
{ {
} }
double Course::getGrade() const double Course::getGrade() const
{ {
double noGrade = NO_GRADE_YET; double noGrade = NO_GRADE_YET;
if (grade == noGrade) if (grade == noGrade)
return 0; return 0;
else else
return this->grade; return this->grade;
} }
void Course::setName(std::string name) void Course::setName(std::string name)
{ {
this->name = name; this->name = name;
} }
void Course::setType(std::string type) void Course::setType(std::string type)
{ {
this->type = type; this->type = type;
} }
void Course::setPoints(double points) void Course::setPoints(double points)
{ {
this->points=points; this->points=points;
} }
void Course::setHours(double hours) void Course::setHours(double hours)
{ {
this->hours = hours; this->hours = hours;
} }
void Course::setGrade(double grade) void Course::setGrade(double grade)
{ {
this->grade = grade; this->grade = grade;
} }
void Course::setAdditions(std::string additions) void Course::setAdditions(std::string additions)
{ {
this->additions = additions; this->additions = additions;
} }

View file

@ -1,64 +1,64 @@
#ifndef COURSE_H #ifndef COURSE_H
#define COURSE_H #define COURSE_H
/* This Code Made By Sagi Dayan /* This Code Made By Sagi Dayan
* SagiDayan@gmail.com * SagiDayan@gmail.com
* *
* Minor changes has been made by Liran Ben Gida * Minor changes has been made by Liran Ben Gida
* LiranBG@gmail.com * LiranBG@gmail.com
*/ */
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <list> #include <list>
#define COURSE_FIELDS 7 #define COURSE_FIELDS 7
#define NO_GRADE_YET 101; #define NO_GRADE_YET 101;
class Course{ class Course{
public: public:
enum CourseScheme enum CourseScheme
{ {
SERIAL, SERIAL,
NAME, NAME,
TYPE, TYPE,
POINTS, POINTS,
HOURS, HOURS,
GRADE, GRADE,
ADDITION ADDITION
}; };
Course(int serial,std::string name, std::string type, double points, double hours, double grade, std::string additions); Course(int serial,std::string name, std::string type, double points, double hours, double grade, std::string additions);
~Course(); ~Course();
int getSerialNum() const {return this->serialNum;} int getSerialNum() const {return this->serialNum;}
std::string getName() const {return this->name;} std::string getName() const {return this->name;}
std::string getType() const {return this->type;} std::string getType() const {return this->type;}
double getPoints() const {return this->points;} double getPoints() const {return this->points;}
double getHours() const {return this->hours;} double getHours() const {return this->hours;}
double getGrade() const ; double getGrade() const ;
std::string getAddidtions() const {return this->additions;} std::string getAddidtions() const {return this->additions;}
void setName(std::string name); void setName(std::string name);
void setType(std::string type); void setType(std::string type);
void setPoints(double points); void setPoints(double points);
void setHours(double hours); void setHours(double hours);
void setGrade(double grade); void setGrade(double grade);
void setAdditions(std::string additions); void setAdditions(std::string additions);
private: private:
int serialNum; int serialNum;
std::string name; std::string name;
std::string type; std::string type;
double points; double points;
double hours; double hours;
double grade; double grade;
std::string additions; std::string additions;
}; };
#endif #endif

View file

@ -1,178 +1,178 @@
#include "GradePage.h" #include "GradePage.h"
GradePage::GradePage(std::string html) : Page(html) GradePage::GradePage(std::string html) : Page(html)
{ {
courses = new std::list<Course*>(); courses = new std::list<Course*>();
tempHtml = getString(); tempHtml = getString();
genList(); genList();
} }
GradePage::~GradePage() GradePage::~GradePage()
{ {
for(Course* c : *courses) for(Course* c : *courses)
delete c; delete c;
delete courses; delete courses;
} }
void GradePage::genList() void GradePage::genList()
{ {
this->tempHtml = tokenToLines( this->tempHtml , INFO_DATA_LINES_BEFORE_GRADES_DATA ); this->tempHtml = tokenToLines( this->tempHtml , INFO_DATA_LINES_BEFORE_GRADES_DATA );
coursesListInit(this->tempHtml); coursesListInit(this->tempHtml);
} }
void GradePage::addCourse(Course *a) void GradePage::addCourse(Course *a)
{ {
GradePage::courses->push_back(a); GradePage::courses->push_back(a);
return; return;
} }
void GradePage::removeCourse(std::string courseSerialID) void GradePage::removeCourse(std::string courseSerialID)
{ {
for(Course* c : *courses) for(Course* c : *courses)
{ {
if (c->getSerialNum() == stoi(courseSerialID)) if (c->getSerialNum() == stoi(courseSerialID))
{ {
courses->remove(c); courses->remove(c);
delete c; delete c;
return; return;
} }
} }
} }
void GradePage::coursesListInit(std::string& linesTokinzedString) void GradePage::coursesListInit(std::string& linesTokinzedString)
{ {
std::list<std::string> stringHolder; std::list<std::string> stringHolder;
std::string temp; std::string temp;
Course* cTemp = NULL; Course* cTemp = NULL;
char* tok; char* tok;
char* textToTok = strdup(linesTokinzedString.c_str()); char* textToTok = strdup(linesTokinzedString.c_str());
tok = strtok(textToTok,"\n"); tok = strtok(textToTok,"\n");
while (tok != NULL) while (tok != NULL)
{ {
temp = tok; temp = tok;
stringHolder.push_back(temp); stringHolder.push_back(temp);
tok = strtok(NULL, "\n"); tok = strtok(NULL, "\n");
} }
for(std::string temp: stringHolder) for(std::string temp: stringHolder)
{ {
cTemp = lineToCourse(temp); cTemp = lineToCourse(temp);
if (cTemp != NULL) if (cTemp != NULL)
addCourse(cTemp); addCourse(cTemp);
} }
} }
std::string GradePage::tokenToLines(std::string& textToPhrase,int fromLine) std::string GradePage::tokenToLines(std::string& textToPhrase,int fromLine)
{ {
int ctr = 0; int ctr = 0;
std::string temp = ""; std::string temp = "";
char *tok; char *tok;
char* textToTok = strdup(textToPhrase.c_str()); char* textToTok = strdup(textToPhrase.c_str());
tok = strtok(textToTok, "\n"); tok = strtok(textToTok, "\n");
while(tok != NULL) while(tok != NULL)
{ {
//amount of data before the actual needed data and no empty lines //amount of data before the actual needed data and no empty lines
if ((ctr >= fromLine) && (strcmp(tok," \t ") != 0)) if ((ctr >= fromLine) && (strcmp(tok," \t ") != 0))
{ {
temp += tok; temp += tok;
temp += "\n"; temp += "\n";
} }
ctr++; ctr++;
tok = strtok(NULL, "\n"); tok = strtok(NULL, "\n");
} }
return temp; return temp;
} }
Course* GradePage::lineToCourse(std::string line) Course* GradePage::lineToCourse(std::string line)
{ {
Course *tempC = NULL; Course *tempC = NULL;
std::string templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions] std::string templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions]
int serial; int serial;
double points,hours,grade; double points,hours,grade;
std::string name,type, additions; std::string name,type, additions;
std::string tempS = ""; std::string tempS = "";
int i = 0; int i = 0;
char* tok; char* tok;
char* cLine = strdup(line.c_str()); char* cLine = strdup(line.c_str());
tok = strtok(cLine, "\t"); tok = strtok(cLine, "\t");
while(tok != NULL) while(tok != NULL)
{ {
tempS = tok; tempS = tok;
if (i == 1) //skip the tokenizing loop just once if (i == 1) //skip the tokenizing loop just once
{ {
tempS = ""; tempS = "";
char *tokTemp; char *tokTemp;
tokTemp = tok; tokTemp = tok;
while (!(isdigit((int)*tokTemp))) while (!(isdigit((int)*tokTemp)))
tokTemp++; tokTemp++;
while (isdigit((int)*tokTemp)) while (isdigit((int)*tokTemp))
{ {
tempS += *tokTemp; tempS += *tokTemp;
tokTemp++; tokTemp++;
} }
templinearray[i-1] = tempS; templinearray[i-1] = tempS;
templinearray[i] = tokTemp; templinearray[i] = tokTemp;
} }
else if (i > 1) else if (i > 1)
templinearray[i] = tempS; templinearray[i] = tempS;
i++; i++;
tok=strtok(NULL, "\t"); tok=strtok(NULL, "\t");
} }
if (templinearray[0] == "") //empty phrasing if (templinearray[0] == "") //empty phrasing
return NULL; return NULL;
serial = stoi(templinearray[Course::CourseScheme::SERIAL]); serial = stoi(templinearray[Course::CourseScheme::SERIAL]);
name = templinearray[Course::CourseScheme::NAME]; name = templinearray[Course::CourseScheme::NAME];
type = templinearray[Course::CourseScheme::TYPE]; type = templinearray[Course::CourseScheme::TYPE];
points = stod(templinearray[Course::CourseScheme::POINTS]); points = stod(templinearray[Course::CourseScheme::POINTS]);
hours = stod(templinearray[Course::CourseScheme::HOURS]); hours = stod(templinearray[Course::CourseScheme::HOURS]);
if (isGradedYet(templinearray[Course::CourseScheme::GRADE])) if (isGradedYet(templinearray[Course::CourseScheme::GRADE]))
grade = stod(templinearray[Course::CourseScheme::GRADE]); grade = stod(templinearray[Course::CourseScheme::GRADE]);
else else
grade = NO_GRADE_YET; grade = NO_GRADE_YET;
additions = templinearray[Course::CourseScheme::ADDITION]; additions = templinearray[Course::CourseScheme::ADDITION];
tempC = new Course(serial,name,type,points,hours,grade,additions); tempC = new Course(serial,name,type,points,hours,grade,additions);
return tempC; return tempC;
} }
//checking if one of the chars inside grade is not a number //checking if one of the chars inside grade is not a number
bool GradePage::isGradedYet(std::string grade) bool GradePage::isGradedYet(std::string grade)
{ {
if (strlen(grade.c_str()) <= 1) if (strlen(grade.c_str()) <= 1)
return false; return false;
for (char c: grade) for (char c: grade)
{ {
if (c == '\0') if (c == '\0')
break; break;
if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9 if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9
return false; return false;
} }
return true; return true;
} }
double GradePage::getAvg() double GradePage::getAvg()
{ {
double avg = 0; double avg = 0;
double points = 0; double points = 0;
for(Course* c : *courses) for(Course* c : *courses)
{ {
if ((c->getGrade() != 0)) if ((c->getGrade() != 0))
{ {
avg += c->getGrade() * c->getPoints(); avg += c->getGrade() * c->getPoints();
points += c->getPoints(); points += c->getPoints();
} }
} }
avg /= points; avg /= points;
return avg; return avg;
} }

View file

@ -1,48 +1,48 @@
#ifndef GRADE_PAGE_H #ifndef GRADE_PAGE_H
#define GRADE_PAGE_H #define GRADE_PAGE_H
/* This Code Made By Sagi Dayan /* This Code Made By Sagi Dayan
* SagiDayan@gmail.com * SagiDayan@gmail.com
* *
* Minor changes has been made by Liran Ben Gida * Minor changes has been made by Liran Ben Gida
* LiranBG@gmail.com * LiranBG@gmail.com
*/ */
#include "Page.h" #include "Page.h"
#include "Course.h" #include "Course.h"
#include <list> #include <list>
#include <string.h> //strlen and strtok to phrase the html file #include <string.h> //strlen and strtok to phrase the html file
#include <ctype.h> //checks if character is numeric #include <ctype.h> //checks if character is numeric
#define INFO_DATA_LINES_BEFORE_GRADES_DATA 5 #define INFO_DATA_LINES_BEFORE_GRADES_DATA 5
class GradePage : public Page class GradePage : public Page
{ {
public: public:
GradePage(std::string html); GradePage(std::string html);
~GradePage(); ~GradePage();
void addCourse(Course *); void addCourse(Course *);
void removeCourse(std::string courseSerialID); void removeCourse(std::string courseSerialID);
double getAvg(); double getAvg();
std::list<Course*>* getCourses() { return courses; } std::list<Course*>* getCourses() { return courses; }
private: private:
void genList(); void genList();
std::string tokenToLines(std::string& textToPhrase,int fromLine = 0); std::string tokenToLines(std::string& textToPhrase,int fromLine = 0);
void coursesListInit(std::string& linesTokinzedString); void coursesListInit(std::string& linesTokinzedString);
Course* lineToCourse(std::string line); Course* lineToCourse(std::string line);
bool isGradedYet(std::string grade); bool isGradedYet(std::string grade);
std::list<Course*>* courses; std::list<Course*>* courses;
std::string tempHtml; std::string tempHtml;
}; };
#endif #endif

View file

@ -1,164 +1,164 @@
#include "Page.h" #include "Page.h"
Page::Page(std::string& html) Page::Page(std::string& html)
{ {
makeText(html); makeText(html);
} }
void Page::makeText(std::string& html) void Page::makeText(std::string& html)
{ {
int index = 0; int index = 0;
index = findTitle(html, index); index = findTitle(html, index);
index = runToActualText(html, index); //set index into the actual place where the data is index = runToActualText(html, index); //set index into the actual place where the data is
manageTableContent(html, index); manageTableContent(html, index);
} }
int Page::findTitle(std::string& from, int index) int Page::findTitle(std::string& from, int index)
{ {
std::string temp; std::string temp;
while(index < (int)from.length()) while(index < (int)from.length())
{ {
if(from[index] == '<') if(from[index] == '<')
{ {
//title> //title>
index++; index++;
std::string titleTag = from.substr(index, 5); //legth of title std::string titleTag = from.substr(index, 5); //legth of title
if(titleTag == "title") //check if the tag is title if(titleTag == "title") //check if the tag is title
{ {
while(from[index] != '>') while(from[index] != '>')
index++; index++;
index++; index++;
while(from[index] != '<') while(from[index] != '<')
{ {
temp += from[index]; temp += from[index];
index++; index++;
} }
this->title = temp; //sets the title this->title = temp; //sets the title
return index; return index;
} }
} }
index++; index++;
} }
return -1; return -1;
} }
int Page::runToActualText(std::string& from, int index) int Page::runToActualText(std::string& from, int index)
{ {
while(index < (int)from.length()) while(index < (int)from.length())
{ {
if(from[index] == '<') if(from[index] == '<')
{ {
index++; index++;
if(from[index] == '!') if(from[index] == '!')
{ {
//!--FileName //!--FileName
std::string bodyTag = from.substr(index, 11); //!--FileName std::string bodyTag = from.substr(index, 11); //!--FileName
if(bodyTag == "!--FileName") //check if the tag is body tag if(bodyTag == "!--FileName") //check if the tag is body tag
{ {
while(from[index] != '>') while(from[index] != '>')
index++; index++;
return index; return index;
} }
} }
} }
index++; index++;
} }
return -1; return -1;
} }
void Page::manageTableContent(std::string& html, int index) void Page::manageTableContent(std::string& html, int index)
{ {
std::string temp; std::string temp;
for (int i = index; i < (int)html.length(); i++) for (int i = index; i < (int)html.length(); i++)
{ {
if(html[i] == '<') if(html[i] == '<')
{ {
//<tr> / <td> / <th> //<tr> / <td> / <th>
std::string endofTable = "</tbody>"; std::string endofTable = "</tbody>";
std::string tableTag = html.substr(i, 4); //legth of "tr/td" std::string tableTag = html.substr(i, 4); //legth of "tr/td"
if(tableTag == "<tr>") if(tableTag == "<tr>")
{ {
temp += "\n"; //new row -> new line temp += "\n"; //new row -> new line
i = stitchText(html, temp, i+4); i = stitchText(html, temp, i+4);
if(i == -1) //EOF if(i == -1) //EOF
break; break;
} }
else if(tableTag == "<td>" || tableTag == "<th>") else if(tableTag == "<td>" || tableTag == "<th>")
{ {
temp += "\t"; // new cell -> tab between data temp += "\t"; // new cell -> tab between data
i = stitchText(html, temp, i+4); i = stitchText(html, temp, i+4);
if (i == -1) //EOF if (i == -1) //EOF
break; break;
} }
else if(tableTag == "<td ") // a Year title (in grades table) else if(tableTag == "<td ") // a Year title (in grades table)
{ {
temp += "\t"; temp += "\t";
while(html[i] != '>') while(html[i] != '>')
i++; i++;
i = stitchText(html, temp, i+1); i = stitchText(html, temp, i+1);
} }
else if (html.substr(i,(endofTable).length()) == endofTable) //is end of table else if (html.substr(i,(endofTable).length()) == endofTable) //is end of table
{ {
break; break;
} }
} }
} }
this->text = temp; this->text = temp;
} }
int Page::stitchText(std::string& from, std::string& to, int index) int Page::stitchText(std::string& from, std::string& to, int index)
{ {
if (from[index] == '<') if (from[index] == '<')
{ {
std::string bTag = from.substr(index, 3); std::string bTag = from.substr(index, 3);
if (bTag != "<b>") if (bTag != "<b>")
return index-1; //go back one step - for the main function to inc i return index-1; //go back one step - for the main function to inc i
index += 3; index += 3;
} }
while (from[index] != '<' && index < (int)from.length()) while (from[index] != '<' && index < (int)from.length())
{ {
if (from[index] == '&') if (from[index] == '&')
{ {
//&nbsp; //&nbsp;
std::string nbspChr = from.substr(index, 6); std::string nbspChr = from.substr(index, 6);
if (nbspChr == "&nbsp;") if (nbspChr == "&nbsp;")
{ {
index += 5; index += 5;
from.at(index) = ' '; from.at(index) = ' ';
} }
} }
if (endOfString(index,(int) from.length())) if (endOfString(index,(int) from.length()))
return -1; //EOF return -1; //EOF
else if (from[index] == '<') else if (from[index] == '<')
return index - 1; //go back one step - for the main function to inc i return index - 1; //go back one step - for the main function to inc i
if (from[index] != '\n') //check the actuall data before continue if (from[index] != '\n') //check the actuall data before continue
to += from[index]; to += from[index];
index++; index++;
} }
return index-1; return index-1;
} }
bool Page::endOfString(int index, int length) bool Page::endOfString(int index, int length)
{ {
if(index < length) if(index < length)
return false; return false;
return true; return true;
} }
std::string Page::getString() std::string Page::getString()
{ {
return this->text; return this->text;
} }
std::string Page::getTitle() std::string Page::getTitle()
{ {
return this->title; return this->title;
} }

View file

@ -1,42 +1,42 @@
#ifndef PAGE_H #ifndef PAGE_H
#define PAGE_H #define PAGE_H
/* This Code Made By Sagi Dayan /* This Code Made By Sagi Dayan
* SagiDayan@gmail.com * SagiDayan@gmail.com
* *
* Minor changes has been made by Liran Ben Gida * Minor changes has been made by Liran Ben Gida
* LiranBG@gmail.com * LiranBG@gmail.com
*/ */
#include <iostream> #include <iostream>
#include <string> #include <string>
class Page class Page
{ {
public: public:
~Page() {} ~Page() {}
protected: protected:
Page(std::string& html); Page(std::string& html);
std::string getString(); std::string getString();
std::string getTitle(); std::string getTitle();
void makeText(std::string& html); void makeText(std::string& html);
private: private:
int findTitle(std::string& from, int index); int findTitle(std::string& from, int index);
int runToActualText(std::string& from, int index); int runToActualText(std::string& from, int index);
void manageTableContent(std::string& html, int index); void manageTableContent(std::string& html, int index);
int stitchText(std::string& from, std::string& to, int index); int stitchText(std::string& from, std::string& to, int index);
bool endOfString(int index, int length); bool endOfString(int index, int length);
std::string text; std::string text;
std::string title; std::string title;
}; };
#endif #endif

View file

@ -1,72 +1,72 @@
#ifndef JCELOGINHTMLSCRIPTS_H #ifndef JCELOGINHTMLSCRIPTS_H
#define JCELOGINHTMLSCRIPTS_H #define JCELOGINHTMLSCRIPTS_H
#include <string> #include <string>
#define dst_host "yedion.jce.ac.il" #define dst_host "yedion.jce.ac.il"
#define dst_port 443 #define dst_port 443
#include "../user.h" #include "../user.h"
class jceLoginHtmlScripts class jceLoginHtmlScripts
{ {
private: private:
jceLoginHtmlScripts(); jceLoginHtmlScripts();
public: public:
static std::string makeRequest(std::string parameters) static std::string makeRequest(std::string parameters)
{ {
std::string msg; std::string msg;
msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n"; msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n";
msg += "Host: " + std::string(dst_host) + "\r\n"; msg += "Host: " + std::string(dst_host) + "\r\n";
msg += "Content-Type: application/x-www-form-urlencoded\r\n"; msg += "Content-Type: application/x-www-form-urlencoded\r\n";
msg += "Content-Length: " + to_string(parameters.length()) + "\r\n"; msg += "Content-Length: " + to_string(parameters.length()) + "\r\n";
msg += "Proxy-Connection: Keep-Alive\r\n"; msg += "Proxy-Connection: Keep-Alive\r\n";
msg += "Accept-Charset: utf-8"; msg += "Accept-Charset: utf-8";
msg += "Accept: text/plain\r\n"; msg += "Accept: text/plain\r\n";
msg += "Connection: Keep-Alive\r\n"; msg += "Connection: Keep-Alive\r\n";
msg += "\r\n"; msg += "\r\n";
msg += parameters; msg += parameters;
return msg; return msg;
} }
const static std::string getFirstValidationStep(const user &usr) const static std::string getFirstValidationStep(const user &usr)
{ {
std::string parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N"; std::string parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N";
parameters += usr.getUsername(); parameters += usr.getUsername();
parameters += ",-N"; parameters += ",-N";
parameters += usr.getPassword(); parameters += usr.getPassword();
return parameters; return parameters;
} }
const static std::string getSecondValidationStep(const user &usr) const static std::string getSecondValidationStep(const user &usr)
{ {
std::string parameters; std::string parameters;
parameters = "prgname=LoginValidtion1&Arguments=-N"; parameters = "prgname=LoginValidtion1&Arguments=-N";
parameters += usr.getUserID(); parameters += usr.getUserID();
parameters += ",-A,-N"; parameters += ",-A,-N";
parameters += usr.getHashedPassword(); parameters += usr.getHashedPassword();
parameters += ",-A,-A"; parameters += ",-A,-A";
return parameters; return parameters;
} }
const static std::string getGradesPath(const user &usr) const static std::string getGradesPath(const user &usr)
{ {
std::string parameters; std::string parameters;
parameters = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&"; parameters = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&";
parameters += "TZ=" + usr.getUserID() + "&"; parameters += "TZ=" + usr.getUserID() + "&";
parameters += "UNIQ=" + usr.getHashedPassword() + "&"; parameters += "UNIQ=" + usr.getHashedPassword() + "&";
parameters += "R1C2=" + usr.date->getFYear() + "&"; parameters += "R1C2=" + usr.date->getFYear() + "&";
parameters += "R1C1=" + usr.date->getTYear() + "&"; parameters += "R1C1=" + usr.date->getTYear() + "&";
parameters += "R1C3=" + usr.date->getTSemester() + "&"; parameters += "R1C3=" + usr.date->getTSemester() + "&";
parameters += "R1C4=" + usr.date->getFSemester() + "&"; parameters += "R1C4=" + usr.date->getFSemester() + "&";
parameters += "R1C5=0"; parameters += "R1C5=0";
return parameters; return parameters;
} }
}; };
#endif // JCELOGINHTMLSCRIPTS_H #endif // JCELOGINHTMLSCRIPTS_H

View file

@ -1,34 +1,34 @@
#include "jcedate.h" #include "jcedate.h"
jceDate::jceDate(std::string fromYear,std::string fromSemester,std::string toYear,std::string toSemester) jceDate::jceDate(std::string fromYear,std::string fromSemester,std::string toYear,std::string toSemester)
{ {
this->fSemester = fromSemester; this->fSemester = fromSemester;
this->fYear = fromYear; this->fYear = fromYear;
this->tSemester = toSemester; this->tSemester = toSemester;
this->tYear = toYear; this->tYear = toYear;
} }
void jceDate::setFYear(std::string fromYear) void jceDate::setFYear(std::string fromYear)
{ {
this->fYear = fromYear; this->fYear = fromYear;
} }
void jceDate::setTYear(std::string toYear) void jceDate::setTYear(std::string toYear)
{ {
this->tYear = toYear; this->tYear = toYear;
} }
void jceDate::setFSemester(std::string fromSemester) void jceDate::setFSemester(std::string fromSemester)
{ {
this->fSemester = fromSemester; this->fSemester = fromSemester;
} }
void jceDate::setTSemester(std::string toSemester) void jceDate::setTSemester(std::string toSemester)
{ {
this->tSemester = toSemester; this->tSemester = toSemester;
} }
jceDate::~jceDate() jceDate::~jceDate()
{ {
} }

View file

@ -1,33 +1,33 @@
#ifndef JCEDATE_H #ifndef JCEDATE_H
#define JCEDATE_H #define JCEDATE_H
#include <iostream> #include <iostream>
class jceDate class jceDate
{ {
public: public:
jceDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester); jceDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester);
~jceDate(); ~jceDate();
void setFYear(std::string fromYear); void setFYear(std::string fromYear);
void setTYear(std::string toYear); void setTYear(std::string toYear);
void setFSemester(std::string fromSemester); void setFSemester(std::string fromSemester);
void setTSemester(std::string toSemester); void setTSemester(std::string toSemester);
std::string getFYear() { return this->fYear;} std::string getFYear() { return this->fYear;}
std::string getTYear() { return this->tYear;} std::string getTYear() { return this->tYear;}
std::string getFSemester() { return this->fSemester;} std::string getFSemester() { return this->fSemester;}
std::string getTSemester() { return this->tSemester;} std::string getTSemester() { return this->tSemester;}
private: private:
std::string fYear; //from std::string fYear; //from
std::string fSemester; std::string fSemester;
std::string tYear; //to std::string tYear; //to
std::string tSemester; std::string tSemester;
}; };
#endif // JCEDATE_H #endif // JCEDATE_H

View file

@ -1,187 +1,184 @@
#include "jcelogin.h" #include "jcelogin.h"
jceLogin::jceLogin(user * username) jceLogin::jceLogin(user * username)
{ {
this->recieverPage = new std::string(); this->recieverPage = new std::string();
this->jceA = username; this->jceA = username;
this->JceConnector = new qtsslsocket(dst_host, dst_port); this->JceConnector = new qtsslsocket();
} }
jceLogin::~jceLogin() jceLogin::~jceLogin()
{ {
this->jceA = NULL; this->jceA = NULL;
delete recieverPage; delete recieverPage;
delete JceConnector; delete JceConnector;
JceConnector = NULL; JceConnector = NULL;
recieverPage = NULL; recieverPage = NULL;
} }
/** /**
* @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it. * @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 * throws error upon the given error from JCE website or Socket error
*/ */
void jceLogin::makeConnection() throw (jceStatus) void jceLogin::makeConnection() throw (jceStatus)
{ {
jceStatus status = jceStatus::JCE_NOT_CONNECTED; if (JceConnector->makeConnect(dst_host,dst_port) == false)
throw jceStatus::ERROR_ON_OPEN_SOCKET;
if (checkConnection() == true) //connected to host
{ jceStatus status = jceStatus::JCE_NOT_CONNECTED;
if (makeFirstVisit() == true) //requst and send first validation
{ if (checkConnection() == true) //connected to host
std::cout << "visit 1\n"; {
std::cout << *(this->recieverPage); 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_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;
status = jceStatus::JCE_SECOND_VALIDATION_PASSED; if (makeSecondVisit() == true) //siging in the website
if (makeSecondVisit() == true) //siging in the website {
{ status = jceStatus::JCE_YOU_ARE_IN;
std::cout << "visit 3\n"; setLoginFlag(true);
std::cout << *(this->recieverPage); }
status = jceStatus::JCE_YOU_ARE_IN; else
setLoginFlag(true); status = jceStatus::ERROR_ON_VALIDATION;
} }
else else
status = jceStatus::ERROR_ON_VALIDATION; status = jceStatus::ERROR_ON_VALIDATION;
}
else }
status = jceStatus::ERROR_ON_VALIDATION; else
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
}
else }
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED; else
status = jceStatus::ERROR_ON_OPEN_SOCKET;
}
else //we throw status even if we are IN!
status = jceStatus::ERROR_ON_OPEN_SOCKET; throw status;
//we throw status even if we are IN! }
throw status;
bool jceLogin::checkConnection()
} {
if (JceConnector->isCon())
bool jceLogin::checkConnection() return true;
{
if (JceConnector->isCon()) return false;
return true; }
return false; void jceLogin::reConnect() throw (jceStatus)
} {
closeAll();
void jceLogin::reConnect() throw (jceStatus) if (this->JceConnector != NULL)
{ delete JceConnector;
closeAll(); this->recieverPage = new std::string();
this->recieverPage = new std::string(); this->JceConnector = new qtsslsocket();
this->JceConnector = new qtsslsocket(dst_host, dst_port); try
try {
{ makeConnection();
makeConnection(); }
} catch (jceLogin::jceStatus &a)
catch (jceLogin::jceStatus &a) {
{ throw a;
throw a; }
} }
}
void jceLogin::closeAll()
void jceLogin::closeAll() {
{ delete recieverPage;
delete recieverPage; recieverPage = NULL;
recieverPage = NULL; JceConnector = NULL;
JceConnector = NULL;
}
}
int jceLogin::makeFirstVisit()
int jceLogin::makeFirstVisit() {
{ std::string usr = jceA->getUsername();
std::string usr = jceA->getUsername(); std::string psw = jceA->getPassword();
std::string psw = jceA->getPassword(); if (JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
if (JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA)))) {
{ if (!JceConnector->recieve(*recieverPage))
if (!JceConnector->recieve(*recieverPage)) return jceLogin::ERROR_ON_GETTING_INFO;
return jceLogin::ERROR_ON_GETTING_INFO; }
} else
else return jceLogin::ERROR_ON_SEND_REQUEST;
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
return true; }
}
int jceLogin::makeSecondVisit()
int jceLogin::makeSecondVisit() {
{ std::string usrid=jceA->getUserID();
std::string usrid=jceA->getUserID(); std::string pswid=jceA->getHashedPassword();
std::string pswid=jceA->getHashedPassword(); if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA))))) {
{ if (!(JceConnector->recieve(*recieverPage)))
if (!(JceConnector->recieve(*recieverPage))) return jceLogin::ERROR_ON_GETTING_INFO;
return jceLogin::ERROR_ON_GETTING_INFO;
return true;
return true; }
} else
else return jceLogin::ERROR_ON_SEND_REQUEST;
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
return true; }
}
int jceLogin::getGrades()
int jceLogin::getGrades() {
{ if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA)))))
if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA))))) {
{ if (!(JceConnector->recieve(*recieverPage)))
if (!(JceConnector->recieve(*recieverPage))) return jceLogin::ERROR_ON_GETTING_GRADES;
return jceLogin::ERROR_ON_GETTING_GRADES;
return true;
return true; }
} else
else return jceLogin::ERROR_ON_SEND_REQUEST;
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
return true;
}
}
void jceLogin::setLoginFlag(bool x)
void jceLogin::setLoginFlag(bool x) {
{ this->loginFlag = x;
this->loginFlag = x; }
} bool jceLogin::isLoginFlag() const
bool jceLogin::isLoginFlag() const {
{ return this->loginFlag;
return this->loginFlag; }
}
std::string jceLogin::getPage()
std::string jceLogin::getPage() {
{ return *recieverPage;
return *recieverPage; }
}
/**
/** * @brief jceLogin::checkValidation Made by Nadav Luzzato
* @brief jceLogin::checkValidation Made by Nadav Luzzato * @return true if second validation step is right
* @return true if second validation step is right */
*/ bool jceLogin::checkValidation()
bool jceLogin::checkValidation() {
{ //finds the hashed password
//finds the hashed password std::size_t hasspass_position1 = recieverPage->find("-A,-N");
std::cout << *recieverPage << std::endl; hasspass_position1 += 5;
std::size_t hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1);
std::size_t hasspass_position1 = recieverPage->find("-A,-N"); if ((hasspass_position2 != std::string::npos) && (hasspass_position1 != std::string::npos))
hasspass_position1 += 5; {
std::size_t hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1); std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1);
if ((hasspass_position2 != std::string::npos) && (hasspass_position1 != std::string::npos)) jceA->setHashedPassword(hasspass);
{ }
std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1); //finds the user id
jceA->setHashedPassword(hasspass); std::size_t id_position1 = recieverPage->find("value=\"-N", 0);
} id_position1 += 9;
//finds the user id std::size_t id_position2 = recieverPage->find(",-A", id_position1);
std::size_t id_position1 = recieverPage->find("value=\"-N", 0); if ((id_position2 != std::string::npos) && (id_position1 != std::string::npos))
id_position1 += 9; {
std::size_t id_position2 = recieverPage->find(",-A", id_position1); std::string hassid = recieverPage->substr(id_position1,id_position2-id_position1);
if ((id_position2 != std::string::npos) && (id_position1 != std::string::npos)) jceA->setUserID(hassid);
{ }
std::string hassid = recieverPage->substr(id_position1,id_position2-id_position1); if (((jceA->getUserID()).empty()) || ((jceA->getHashedPassword()).empty()))
jceA->setUserID(hassid); return false;
}
if (((jceA->getUserID()).empty()) || ((jceA->getHashedPassword()).empty())) return true;
return false; }
return true;
}

View file

@ -1,61 +1,61 @@
#ifndef JCELOGIN_H #ifndef JCELOGIN_H
#define JCELOGIN_H #define JCELOGIN_H
#include <string> #include <string>
#include <fstream> #include <fstream>
#include "../connection/qtsslsocket.h" #include "../connection/qtsslsocket.h"
#include "../user.h" #include "../user.h"
#include "jceLoginHtmlScripts.h" #include "jceLoginHtmlScripts.h"
class jceLogin class jceLogin
{ {
public: public:
enum jceStatus { enum jceStatus {
JCE_NOT_CONNECTED, JCE_NOT_CONNECTED,
ERROR_ON_VALIDATION, ERROR_ON_VALIDATION,
ERROR_ON_VALIDATION_USER_BLOCKED, ERROR_ON_VALIDATION_USER_BLOCKED,
ERROR_ON_INPUT, ERROR_ON_INPUT,
ERROR_ON_CONNECTING, ERROR_ON_CONNECTING,
ERROR_ON_OPEN_SOCKET, ERROR_ON_OPEN_SOCKET,
ERROR_ON_GETTING_INFO, ERROR_ON_GETTING_INFO,
ERROR_ON_GETTING_GRADES, ERROR_ON_GETTING_GRADES,
ERROR_ON_SEND_REQUEST, ERROR_ON_SEND_REQUEST,
JCE_START_VALIDATING_PROGRESS, JCE_START_VALIDATING_PROGRESS,
JCE_FIRST_VALIDATION_PASSED, JCE_FIRST_VALIDATION_PASSED,
JCE_SECOND_VALIDATION_PASSED, JCE_SECOND_VALIDATION_PASSED,
JCE_YOU_ARE_IN, JCE_YOU_ARE_IN,
JCE_GRADE_PAGE_PASSED JCE_GRADE_PAGE_PASSED
}; };
jceLogin(user* username); jceLogin(user* username);
~jceLogin(); ~jceLogin();
void makeConnection() throw (jceStatus); void makeConnection() throw (jceStatus);
bool checkConnection(); bool checkConnection();
void reConnect() throw (jceStatus); void reConnect() throw (jceStatus);
void closeAll(); void closeAll();
int getGrades(); int getGrades();
bool isLoginFlag() const; bool isLoginFlag() const;
std::string getPage(); std::string getPage();
private: private:
int makeFirstVisit(); int makeFirstVisit();
bool checkValidation(); bool checkValidation();
int makeSecondVisit(); int makeSecondVisit();
void setLoginFlag(bool x); void setLoginFlag(bool x);
bool loginFlag; bool loginFlag;
std::string * recieverPage; std::string * recieverPage;
user * jceA; user * jceA;
qtsslsocket * JceConnector; qtsslsocket * JceConnector;
}; };
#endif // JCELOGIN_H #endif // JCELOGIN_H

View file

@ -1,52 +1,52 @@
#include "user.h" #include "user.h"
user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false) user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false)
{ {
this->username = username; this->username = username;
this->password = password; this->password = password;
} }
user::~user() user::~user()
{ {
delete date; delete date;
} }
void user::setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester) void user::setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester)
{ {
date->setFYear(fromYear); date->setFYear(fromYear);
date->setFSemester(fromSemester); date->setFSemester(fromSemester);
date->setTYear(toYear); date->setTYear(toYear);
date->setTSemester(toSemester); date->setTSemester(toSemester);
} }
void user::setInfluenceCourseOnly(bool status) void user::setInfluenceCourseOnly(bool status)
{ {
this->influenceCourseOnly = status; this->influenceCourseOnly = status;
} }
bool user::getInfluenceCourseOnly() const bool user::getInfluenceCourseOnly() const
{ {
return this->influenceCourseOnly; return this->influenceCourseOnly;
} }
void user::setUsername(string& username) { void user::setUsername(string& username) {
this->username=username; this->username=username;
} }
void user::setPassword(string& password) { void user::setPassword(string& password) {
this->password=password; this->password=password;
} }
void user::setUserID(string& ID) void user::setUserID(string& ID)
{ {
this->userID = ID; this->userID = ID;
} }
void user::setHashedPassword(string& hashpass) void user::setHashedPassword(string& hashpass)
{ {
this->hashedPassword = hashpass; this->hashedPassword = hashpass;
} }
string user::getPassword() const { return password; } string user::getPassword() const { return password; }
string user::getUsername() const { return username; } string user::getUsername() const { return username; }
string user::getUserID() const { return userID; } string user::getUserID() const { return userID; }
string user::getHashedPassword() const { return hashedPassword; } string user::getHashedPassword() const { return hashedPassword; }

View file

@ -1,48 +1,48 @@
#ifndef user_H #ifndef user_H
#define user_H #define user_H
#include <string> #include <string>
#include <iostream> #include <iostream>
#include "jce/jcedate.h" #include "jce/jcedate.h"
using namespace std; using namespace std;
class user class user
{ {
public: public:
user(string username,string password); user(string username,string password);
~user(); ~user();
void setUsername(string& username); void setUsername(string& username);
void setPassword(string& password); void setPassword(string& password);
string getPassword() const; string getPassword() const;
string getUsername() const; string getUsername() const;
void setUserID(string& ID); void setUserID(string& ID);
void setHashedPassword(string& hashpass); void setHashedPassword(string& hashpass);
string getUserID() const; string getUserID() const;
string getHashedPassword() const; string getHashedPassword() const;
void setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester); void setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester);
void setInfluenceCourseOnly(bool status); void setInfluenceCourseOnly(bool status);
bool getInfluenceCourseOnly() const; bool getInfluenceCourseOnly() const;
jceDate * const date = new jceDate("","","",""); //we do not change the pointer jceDate * const date = new jceDate("","","",""); //we do not change the pointer
private: private:
string username; string username;
string password; string password;
string hashedPassword; string hashedPassword;
string userID; string userID;
bool influenceCourseOnly; bool influenceCourseOnly;
}; };
#endif #endif