diff --git a/jceGrade.pro b/jceGrade.pro new file mode 100644 index 0000000..36ac194 --- /dev/null +++ b/jceGrade.pro @@ -0,0 +1,49 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-05-31T19:49:42 +# +#------------------------------------------------- + +QT += core gui network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +TARGET = jceGrade +TEMPLATE = app + +CONFIG += c++11 + +SOURCES += main/coursestablemanager.cpp \ + main/loginhandler.cpp \ + main/main.cpp \ + main/mainscreen.cpp \ + src/connection/qtsslsocket.cpp \ + src/user.cpp \ + src/grades/Course.cpp \ + src/grades/GradePage.cpp \ + src/grades/Page.cpp \ + src/jce/jcedate.cpp \ + src/jce/jcelogin.cpp + + + +HEADERS += main/coursestablemanager.h \ + main/loginhandler.h \ + main/mainscreen.h \ + src/connection/qtsslsocket.h \ + src/user.h \ + src/grades/Course.h \ + src/grades/GradePage.h \ + src/grades/Page.h \ + src/jce/jcedate.h \ + src/jce/jcelogin.h \ + src/jce/jceLoginHtmlScripts.h \ + + + +FORMS += \ + main/mainscreen.ui + +OTHER_FILES += + +RESOURCES += \ + resources/connectionstatus.qrc diff --git a/main/coursestablemanager.cpp b/main/coursestablemanager.cpp new file mode 100644 index 0000000..b877956 --- /dev/null +++ b/main/coursestablemanager.cpp @@ -0,0 +1,215 @@ +#include "coursestablemanager.h" + +coursesTableManager::coursesTableManager(QTableWidget *ptr, user *usrPtr) +{ + this->gp = NULL; + this->us = usrPtr; + this->courseTBL = ptr; + + /* + * Initilizing Table + */ + courseTBL->setRowCount(0); + courseTBL->setColumnCount(COURSE_FIELDS); + QStringList mz; + mz << "Serial" << "Name" << "Type" << "Points" << "Hours" << "Grade" << "Additions"; + courseTBL->setHorizontalHeaderLabels(mz); + courseTBL->verticalHeader()->setVisible(true); + courseTBL->setSelectionMode(QAbstractItemView::SingleSelection); + courseTBL->setShowGrid(true); + courseTBL->setStyleSheet("QTableView {selection-background-color: red;}"); + +} + +coursesTableManager::~coursesTableManager() +{ + courseTBL = NULL; + delete gp; + gp=NULL; +} +/** + * @brief coursesTableManager::insertJceCoursesIntoTable phrasing the course list to rows in table + */ +void coursesTableManager::insertJceCoursesIntoTable() +{ + for (Course *c: *gp->getCourses()) + { + if (us->getInfluenceCourseOnly()) + { + if (isCourseInfluence(c)) + addRow(c); + } + else + addRow(c); + } +} +/** + * @brief coursesTableManager::setCoursesList creating courses list with given html page + * @param html + */ +void coursesTableManager::setCoursesList(std::string &html) +{ + gp = new GradePage(html); +} +/** + * @brief coursesTableManager::changes when user changes the table manually it updates it + * @param change string change + * @param row row index + * @param col col index + */ +void coursesTableManager::changes(std::string change, int row, int col) +{ + int serialCourse = courseTBL->item(row,Course::CourseScheme::SERIAL)->text().toInt(); + for (Course *c: *gp->getCourses()) + { + if (c->getSerialNum() == serialCourse) + { + switch (col) + { + case (Course::CourseScheme::NAME): + c->setName(change); + break; + case (Course::CourseScheme::TYPE): + c->setType(change); + break; + case (Course::CourseScheme::POINTS): + c->setPoints(stod(change)); + break; + case (Course::CourseScheme::HOURS): + c->setHours(stod(change)); + break; + case (Course::CourseScheme::GRADE): + c->setGrade(stod(change)); + break; + case (Course::CourseScheme::ADDITION): + c->setAdditions(change); + break; + } + break; + } + } + +} +/** + * @brief coursesTableManager::addRow adds row with given information + * @param courseToAdd if exists, add its information to table + */ +void coursesTableManager::addRow(const Course *courseToAdd) +{ + int i,j; + i = courseTBL->rowCount(); + j = 0; + QTableWidgetItem *serial,*name,*type,*points,*hours,*grade,*addition; + const Course * c; + if (courseToAdd != NULL) + { + c = courseToAdd; + if (!isCourseAlreadyInserted(c->getSerialNum())) + { + courseTBL->setRowCount(courseTBL->rowCount()+1); + serial = new QTableWidgetItem(QString::number(c->getSerialNum())); + serial->setFlags(serial->flags() & ~Qt::ItemIsEditable); + points = new QTableWidgetItem(QString::number(c->getPoints())); + points->setFlags(serial->flags() & ~Qt::ItemIsEditable); + hours = new QTableWidgetItem(QString::number(c->getHours())); + hours->setFlags(serial->flags() & ~Qt::ItemIsEditable); + grade = new QTableWidgetItem(QString::number(c->getGrade())); + name = new QTableWidgetItem(QString::fromStdString(c->getName())); + name->setFlags(serial->flags() & ~Qt::ItemIsEditable); + type = new QTableWidgetItem(QString::fromStdString(c->getType())); + type->setFlags(serial->flags() & ~Qt::ItemIsEditable); + addition = new QTableWidgetItem(QString::fromStdString(c->getAddidtions())); + + courseTBL->setItem(i,j++,serial); + courseTBL->setItem(i,j++,name); + courseTBL->setItem(i,j++,type); + courseTBL->setItem(i,j++,points); + courseTBL->setItem(i,j++,hours); + courseTBL->setItem(i,j++,grade); + courseTBL->setItem(i,j,addition); + + } + } + else + { + } + courseTBL->resizeColumnsToContents(); + +} +double coursesTableManager::getAvg() +{ + if (this->gp != NULL) + return gp->getAvg(); + return 0; +} + + +void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus) +{ + if (ignoreCourseStatus) + { + int i = 0; + while (i < courseTBL->rowCount()) + { + if (courseTBL->item(i,Course::CourseScheme::POINTS)->text().compare("0") == 0) + courseTBL->removeRow(i--); + i++; + } + } + else + { + for (Course *c: *gp->getCourses()) + { + if (!(isCourseAlreadyInserted(c->getSerialNum()))) + if (c->getPoints() == 0) + addRow(c); + } + } + +} + +void coursesTableManager::clearTable() +{ + if (courseTBL->rowCount() == 0) + return; + + int i = 0; //starting point + while (courseTBL->rowCount() > i) + { + gp->removeCourse(courseTBL->item(i,Course::CourseScheme::SERIAL)->text().toStdString()); + courseTBL->removeRow(i); + } + gp = NULL; + courseTBL->repaint(); +} + +Course *coursesTableManager::getCourseByRow(int row) +{ + QString courseSerial = courseTBL->item(row,Course::CourseScheme::SERIAL)->text(); + for (Course *c: *gp->getCourses()) + { + if (c->getSerialNum() == courseSerial.toDouble()) + return c; + } + return NULL; +} + +bool coursesTableManager::isCourseAlreadyInserted(double courseID) +{ + int i=0; + for (i = 0; i < courseTBL->rowCount(); ++i) + { + QString courseSerial = courseTBL->item(i,Course::CourseScheme::SERIAL)->text(); + if (QString::number(courseID) == courseSerial) + return true; + } + return false; +} + +bool coursesTableManager::isCourseInfluence(const Course *courseToCheck) +{ + if (courseToCheck->getPoints() > 0) + return true; + return false; + +} diff --git a/main/coursestablemanager.h b/main/coursestablemanager.h new file mode 100644 index 0000000..0748947 --- /dev/null +++ b/main/coursestablemanager.h @@ -0,0 +1,43 @@ +#ifndef COURSESTABLEMANAGER_H +#define COURSESTABLEMANAGER_H + + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "src/grades/Course.h" +#include "src/grades/GradePage.h" +#include "src/user.h" + +class coursesTableManager +{ +public: + coursesTableManager(QTableWidget *, user *usrPtr); + ~coursesTableManager(); + void insertJceCoursesIntoTable(); + void setCoursesList(std::string &htmlPage); + void changes(std::string change, int row, int col); + void addRow(const Course * courseToAdd = 0); + double getAvg(); + + void influnceCourseChanged(bool status); + void clearTable(); + +private: + QTableWidget *courseTBL; + GradePage *gp; + user *us; + + Course * getCourseByRow(int row); + bool isCourseAlreadyInserted(double courseID); + bool isCourseInfluence(const Course *courseToCheck); +}; + +#endif // COURSESTABLEMANAGER_H diff --git a/main/loginhandler.cpp b/main/loginhandler.cpp new file mode 100644 index 0000000..4b2d736 --- /dev/null +++ b/main/loginhandler.cpp @@ -0,0 +1,66 @@ +#include "loginhandler.h" + +loginHandler::loginHandler(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr) +{ + this->jceLog = ptr; + this->statusLabelPtr = statusLabelPtr; + this->pswdEditPtr = pswdEditPtr; + this->usrnmEditPtr = usrnmEditPtr; +} + +bool loginHandler::makeConnection() +{ + if (this->jceLog == NULL) + { + return false; + } + try + { + jceLog->makeConnection(); + } + catch (jceLogin::jceStatus &a) + { + + if (a == jceLogin::JCE_YOU_ARE_IN) + { + return true; + } + else if (a == jceLogin::ERROR_ON_VALIDATION) + { + popMessage("check your password"); + + usrnmEditPtr->setDisabled(false); + pswdEditPtr->setDisabled(false); + + pswdEditPtr->selectAll(); + pswdEditPtr->setFocus(); + return false; + } + else if (a == jceLogin::ERROR_ON_OPEN_SOCKET) + { + popMessage("Please check your internet status"); + + jceLog->closeAll(); + + return false; + } + else if (a == jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED) + { + popMessage("You were blocked, please wait couple of minutes or contact JCE"); + jceLog->closeAll(); + + return false; + } + } + return false; +} +void loginHandler::popMessage(QString message) +{ + QMessageBox msgBox; + msgBox.setWindowTitle("Error"); + msgBox.setText(message); + msgBox.exec(); + msgBox.setFocus(); +} + + diff --git a/main/loginhandler.h b/main/loginhandler.h new file mode 100644 index 0000000..2e88fa8 --- /dev/null +++ b/main/loginhandler.h @@ -0,0 +1,29 @@ +#ifndef LOGINHANDLER_H +#define LOGINHANDLER_H +#include +#include +#include +#include +#include + +#include "src/jce/jcelogin.h" + +class loginHandler +{ +public: + loginHandler(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr); + bool makeConnection(); + +private: + + void popMessage(QString message); + + + jceLogin *jceLog; + + QLabel *statusLabelPtr; + QLineEdit *pswdEditPtr; + QLineEdit *usrnmEditPtr; +}; + +#endif // LOGINHANDLER_H diff --git a/main/main.cpp b/main/main.cpp new file mode 100644 index 0000000..5637ce8 --- /dev/null +++ b/main/main.cpp @@ -0,0 +1,13 @@ +#include "mainscreen.h" +#include + + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainScreen w; + w.show(); + + + return a.exec(); +} diff --git a/main/mainscreen.cpp b/main/mainscreen.cpp new file mode 100644 index 0000000..72eacbc --- /dev/null +++ b/main/mainscreen.cpp @@ -0,0 +1,237 @@ +#include "mainscreen.h" +#include "ui_mainscreen.h" + + +MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScreen) +{ + ui->setupUi(this); + // this->setWindowFlags(this->windowFlags() | Qt::MSWindowsFixedSizeDialogHint); + + this->setFixedSize(this->size()); //main not resizeable + ui->pswdLineEdit->setEchoMode((QLineEdit::Password)); + ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };"); + ButtomStatusLabel = new QLabel(this); + statusLabel = new QLabel(this); + + + + ui->CoursesTab->setDisabled(true); + ui->SettingsTab->setDisabled(true); + ui->statusBar->setMaximumSize(this->geometry().width(),StatusIconHeight); + ui->statusBar->addPermanentWidget(ButtomStatusLabel,0); + ui->statusBar->addPermanentWidget(statusLabel,1); + + this->jceLog = NULL; + this->userLoginSetting = new user("",""); + + this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting); + + updateDates(); + setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); + +} + +MainScreen::~MainScreen() +{ + delete userLoginSetting; + delete jceLog; + delete ui; +} +void MainScreen::on_ratesButton_clicked() +{ + QTextEdit phrase; + std::string pageString; + if (this->jceLog != NULL) + { + if (jceLog->getGrades()) + { + phrase.setText(QString::fromStdString(jceLog->getPage())); + pageString = phrase.toPlainText().toStdString(); + courseTableMgr->setCoursesList(pageString); + courseTableMgr->insertJceCoursesIntoTable(); + } + } + +} + +void MainScreen::on_spinBoxFromYear_editingFinished() +{ + if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value()) + { + ui->spinBoxFromYear->setValue(ui->spinBoxToYear->value()); + ui->spinBoxFromYear->setFocus(); + updateDates(); + } + else + updateDates(); +} +void MainScreen::on_spinBoxToYear_editingFinished() +{ + if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value()) + { + ui->spinBoxToYear->setValue(ui->spinBoxFromYear->value()); + ui->spinBoxToYear->setFocus(); + updateDates(); + } + else + updateDates(); +} +void MainScreen::on_spinBoxFromSem_editingFinished() +{ + if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value()) + { + if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value()) + { + ui->spinBoxFromSem->setValue(ui->spinBoxToSemester->value()); + ui->spinBoxFromSem->setFocus(); + } + } + updateDates(); +} +void MainScreen::on_spinBoxToSemester_editingFinished() +{ + if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value()) + { + if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value()) + { + ui->spinBoxToSemester->setValue(ui->spinBoxFromSem->value()); + ui->spinBoxToSemester->setFocus(); + } + } + updateDates(); +} + +void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item) +{ + this->courseTableMgr->changes(item->text().toStdString(),item->row(),item->column()); + ui->avgLCD->display(courseTableMgr->getAvg()); +} + +void MainScreen::on_loginButton_clicked() +{ + setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS); + + + if (this->jceLog == NULL) + uiSetConnectMode(); + else + { + if (jceLog->isLoginFlag() == true) + uiSetDisconnectMode(); + else + uiSetConnectMode(); + } + +} + +void MainScreen::on_checkBox_toggled(bool checked) +{ + this->userLoginSetting->setInfluenceCourseOnly(checked); + this->courseTableMgr->influnceCourseChanged(checked); +} +void MainScreen::on_usrnmLineEdit_editingFinished() +{ + ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); +} +void MainScreen::updateDates() +{ + std::string fy,ty,fs,ts; + fy = std::to_string(ui->spinBoxFromYear->value()); + ty = std::to_string(ui->spinBoxToYear->value()); + fs = std::to_string(ui->spinBoxFromSem->value()); + ts = std::to_string(ui->spinBoxToSemester->value()); + userLoginSetting->setDate(fy,fs,ty,ts); +} + +void MainScreen::uiSetDisconnectMode() +{ + setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); + ui->usrnmLineEdit->setText(""); + ui->pswdLineEdit->setText(""); + ui->usrnmLineEdit->setEnabled(true); + ui->pswdLineEdit->setEnabled(true); + + delete jceLog; + jceLog = NULL; + ui->loginButton->setText("&Login"); + this->ui->ratesButton->setDisabled(true); + return; +} + +void MainScreen::uiSetConnectMode() +{ + string username; + string password; + if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) + { + //add icon near to username and password to mark it + return; + } + username = ui->usrnmLineEdit->text().toStdString(); + password = ui->pswdLineEdit->text().toStdString(); + + ui->usrnmLineEdit->setDisabled(true); + ui->pswdLineEdit->setDisabled(true); + + userLoginSetting->setUsername(username); + userLoginSetting->setPassword(password); + + this->repaint(); + + jceLog = new jceLogin(userLoginSetting); + this->loginHandel = new loginHandler(jceLog,statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit); + + if (loginHandel->makeConnection() == true) + { + setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN); + ui->loginButton->setText("&Logout"); + this->ui->ratesButton->setEnabled(true); + ui->CoursesTab->setEnabled(true); + ui->SettingsTab->setEnabled(true); + } + else + { + uiSetDisconnectMode(); + } +} +void MainScreen::setLabelConnectionStatus(jceLogin::jceStatus statusDescription) +{ + QPixmap iconPix; + switch (statusDescription) + { + + case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS: + iconPix.load(":/icons/blueStatusIcon.png"); + statusLabel->setText("Connecting"); + break; + case jceLogin::jceStatus::JCE_YOU_ARE_IN: + iconPix.load(":/icons/greenStatusIcon.png"); + statusLabel->setText("Connected"); + break; + default: + iconPix.load(":/icons/redStatusIcon.png"); + statusLabel->setText("Disconnected"); + break; + } + ButtomStatusLabel->setPixmap(iconPix); + + this->repaint(); +} +void MainScreen::on_actionCredits_triggered() +{ + QMessageBox credits; + credits.setText(" A tiny application to calculate your grades average. \n Made by Liran Ben Gida \n Thanks to: Sagi Dayan, Nadav Luzzato"); + credits.exec(); +} + +void MainScreen::on_clearTableButton_clicked() +{ + + courseTableMgr->clearTable(); + ui->avgLCD->display(courseTableMgr->getAvg()); +} + +void MainScreen::on_actionExit_triggered() +{ + exit(0); +} diff --git a/main/mainscreen.h b/main/mainscreen.h new file mode 100644 index 0000000..fd44226 --- /dev/null +++ b/main/mainscreen.h @@ -0,0 +1,78 @@ +#ifndef MAINSCREEN_H +#define MAINSCREEN_H + +#include +#include +#include +#include +#include + +#include +#include + + +#include "src/grades/GradePage.h" +#include "src/jce/jcelogin.h" +#include "coursestablemanager.h" +#include "loginhandler.h" + +#define StatusIconHeight 35 +namespace Ui { +class MainScreen; +} + +class MainScreen : public QMainWindow +{ + Q_OBJECT + +public: + MainScreen(QWidget *parent = 0); + ~MainScreen(); + +private slots: + + void on_ratesButton_clicked(); + + void on_spinBoxFromYear_editingFinished(); + + void on_spinBoxFromSem_editingFinished(); + + void on_spinBoxToYear_editingFinished(); + + void on_spinBoxToSemester_editingFinished(); + + void on_coursesTable_itemChanged(QTableWidgetItem *item); + + void on_loginButton_clicked(); + + void on_checkBox_toggled(bool checked); + + void on_usrnmLineEdit_editingFinished(); + + void on_actionCredits_triggered(); + + void on_clearTableButton_clicked(); + + void on_actionExit_triggered(); + +private: + + void updateDates(); + void uiSetDisconnectMode(); + void uiSetConnectMode(); + void setLabelConnectionStatus(jceLogin::jceStatus statusDescription); + + Ui::MainScreen *ui; + + jceLogin *jceLog; + user *userLoginSetting; + + coursesTableManager *courseTableMgr; + loginHandler *loginHandel; + + QLabel *ButtomStatusLabel; + QLabel *statusLabel; + +}; + +#endif // MAINSCREEN_H diff --git a/main/mainscreen.ui b/main/mainscreen.ui new file mode 100644 index 0000000..d62519b --- /dev/null +++ b/main/mainscreen.ui @@ -0,0 +1,691 @@ + + + MainScreen + + + + 0 + 0 + 737 + 500 + + + + + 0 + 0 + + + + JCE Avg Calculator + + + + :/icons/icon.png:/icons/icon.png + + + #centralWidget +{ +background: qlineargradient(spread:pad, x1:0.496, y1:0, x2:0.508, y2:1, stop:0 rgba(195, 231, 224, 218), stop:1 rgba(255, 255, 255, 255)); +} + + + + 48 + 48 + + + + false + + + false + + + + + + + + + + true + + + #CoursesTab { +background: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #eef, stop: 1 #ccf); +border: none; +} +#LoginTab { +background: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #eef, stop: 1 #ccf); +border: none; +} +#SettingsTab { +background: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #eef, stop: 1 #ccf); +border: none; +} +#DebugTab { +background: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #eef, stop: 1 #ccf); +border: none; +} + + + QTabWidget::North + + + QTabWidget::Rounded + + + 0 + + + false + + + false + + + false + + + + + + + Login + + + + QFormLayout::AllNonFixedFieldsGrow + + + 200 + + + 80 + + + 200 + + + 80 + + + + + + 0 + 0 + + + + #LoginFrame { +border: 3px solid rgb(160, 165, 170); +border-radius: 40px; + +} +#loginButton { +color: white; +background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #88d, stop: 0.1 #99e, stop: 0.49 #77c, stop: 0.5 #66b, stop: 1 #77c); +border-width: 1px; +border-color: #339; +border-style: solid; +border-radius: 7; +padding: 3px; +font-size: 12px; +padding-left: 5px; +padding-right: 5px; +min-width: 60px; +max-width: 60px; +min-height: 20px; +max-height: 20px; +} +#loginButton:pressed { +background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #88d, stop: 0.1 #99e, stop: 0.49 #88c, stop: 0.5 #77b, stop: 1 #88c); +} + +#pswdLabel { +font-weight: bold; +font-size: 15px; +} +#usrnmLabel { +font-weight: bold; +font-size: 15px; +} + + + QFrame::StyledPanel + + + QFrame::Raised + + + + QLayout::SetDefaultConstraint + + + 20 + + + 15 + + + 20 + + + 15 + + + + + 0 + + + + + 10 + + + + + + 0 + 0 + + + + Username + + + + + + + + 0 + 0 + + + + Qt::ImhLatinOnly|Qt::ImhNoPredictiveText + + + 20 + + + true + + + + + + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Password + + + + + + + + 0 + 0 + + + + Qt::ImhHiddenText|Qt::ImhNoAutoUppercase|Qt::ImhNoPredictiveText|Qt::ImhSensitiveData + + + 20 + + + QLineEdit::Password + + + true + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + + + Login + + + + + + + + + + + + + false + + + + + + Courses + + + + + 2 + 5 + 711 + 371 + + + + + 0 + + + + + + 0 + 0 + + + + Qt::RightToLeft + + + QAbstractItemView::SingleSelection + + + true + + + + + + + + + + + false + + + Add + + + + + + + Clear + + + + + + + + + Qt::Horizontal + + + + 378 + 20 + + + + + + + + + + Average: + + + + + + + + + + + + + + + + false + + + Settings + + + + + 10 + 180 + 201 + 26 + + + + Only influences Courses + + + false + + + + + + 10 + 40 + 231 + 121 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 10 + + + 10 + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 48 + 20 + + + + + + + + + + Semester + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + Year + + + + + + + + + + + + + + + From + + + + + + + To + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 3 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + false + + + false + + + 2009 + + + 2015 + + + 2009 + + + + + + + + + + + 3 + + + 3 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + 2010 + + + 2026 + + + 2015 + + + + + + + + + + + + + + + + + + + + + + + 0 + 0 + 737 + 29 + + + + + &About + + + + + + + + + + 0 + 0 + + + + + 16777215 + 50 + + + + + + Credits + + + + + Exit + + + + + + + + + diff --git a/resources/blueStatusIcon.png b/resources/blueStatusIcon.png new file mode 100644 index 0000000..1f70d90 Binary files /dev/null and b/resources/blueStatusIcon.png differ diff --git a/resources/connectionstatus.qrc b/resources/connectionstatus.qrc new file mode 100644 index 0000000..61cb0fd --- /dev/null +++ b/resources/connectionstatus.qrc @@ -0,0 +1,8 @@ + + + blueStatusIcon.png + greenStatusIcon.png + redStatusIcon.png + icon.png + + diff --git a/resources/greenStatusIcon.png b/resources/greenStatusIcon.png new file mode 100644 index 0000000..fcb16a4 Binary files /dev/null and b/resources/greenStatusIcon.png differ diff --git a/resources/icon.png b/resources/icon.png new file mode 100644 index 0000000..efa2f5c Binary files /dev/null and b/resources/icon.png differ diff --git a/resources/redStatusIcon.png b/resources/redStatusIcon.png new file mode 100644 index 0000000..5be6f08 Binary files /dev/null and b/resources/redStatusIcon.png differ diff --git a/src/connection/qtsslsocket.cpp b/src/connection/qtsslsocket.cpp new file mode 100644 index 0000000..8a9e76e --- /dev/null +++ b/src/connection/qtsslsocket.cpp @@ -0,0 +1,56 @@ +#include "qtsslsocket.h" + +qtsslsocket::qtsslsocket(std::string server,int port) : flag(false) +{ + socket = new QSslSocket(); + socket->connectToHostEncrypted(server.c_str(), port); + if (socket->waitForEncrypted()) + flag = true; + +} + +bool qtsslsocket::isCon() +{ + return flag; + +} + +bool qtsslsocket::send(std::string str) +{ + bool flag = true; + this->socket->write(str.c_str()); + + return flag; +} + +bool qtsslsocket::recieve(std::string &str) +{ + bool flag = false; + QString s = ""; + while (socket->waitForReadyRead(milisTimeOut)) + s.append((socket->readAll().data())); + str = s.toStdString(); + if (s.size() > 0) + flag = true; + return flag; +} + +void qtsslsocket::setProgressBar(QProgressBar *ptr) +{ + if (ptr != NULL) + { + this->pb=ptr; + connect(this->socket,SIGNAL(encryptedBytesWritten(qint64)),this,SLOT(on_read())); + //connect(this->socket,SIGNAL(readChannelFinished()),this,SLOT(on_read())); + } + +} + +void qtsslsocket::on_read() +{ + if (this->pb != NULL) + { + if (pb->value() <= 90) + pb->setValue(pb->value() + 10); + } +} diff --git a/src/connection/qtsslsocket.h b/src/connection/qtsslsocket.h new file mode 100644 index 0000000..6a53416 --- /dev/null +++ b/src/connection/qtsslsocket.h @@ -0,0 +1,40 @@ +#ifndef QTSSLSOCKET_H +#define QTSSLSOCKET_H +#include + +#include +#include +#include +#include +#include +#include +#define milisTimeOut 3000 + +class qtsslsocket : public QObject +{ + Q_OBJECT + +public: + qtsslsocket(std::string server,int port); + ~qtsslsocket() { + disconnect(this->socket,SIGNAL(encryptedBytesWritten(qint64)),this,SLOT(on_read())); + socket->close(); + socket = NULL; + pb = NULL; + + } + bool isCon(); + bool send(std::string str); + bool recieve(std::string &str); + void setProgressBar(QProgressBar *ptr); + +private slots: + void on_read(); + +private: + QSslSocket *socket; + QProgressBar *pb; + bool flag; +}; + +#endif // QTSSLSOCKET_H diff --git a/src/grades/Course.cpp b/src/grades/Course.cpp new file mode 100644 index 0000000..50464f6 --- /dev/null +++ b/src/grades/Course.cpp @@ -0,0 +1,75 @@ +#include "Course.h" + +Course::Course(int serial, std::string name, std::string type, double points, double hours, double grade, std::string additions) +{ + this->serialNum = serial; + this->name = name; + this->type = type; + this->points = points; + this->hours = hours; + this->grade = grade; + this->additions = additions; +} + +Course::~Course() +{ + +} + +void Course::printCourse() +{ + double noGrade = NO_GRADE_YET; + + std::cout << "===== Course =====" << std::endl; + std::cout << "serial: " << this->serialNum << std::endl; + std::cout << "name: " << this->name << std::endl; + std::cout << "type: " << this->type << std::endl; + std::cout << "points: " << this->points << std::endl; + std::cout << "hours: " << this->hours << std::endl; + + if (this->grade != noGrade) + std::cout << "grade: " << this->grade << std::endl; + else + std::cout << "grade: " << "No Grade" << std::endl; + + std::cout << "additions: " << this->additions << std::endl; +} + +double Course::getGrade() const +{ + double noGrade = NO_GRADE_YET; + if (grade == noGrade) + return 0; + else + return this->grade; +} + +void Course::setName(std::string name) +{ + this->name = name; +} + +void Course::setType(std::string type) +{ + this->type = type; +} + +void Course::setPoints(double points) +{ + this->points=points; +} + +void Course::setHours(double hours) +{ + this->hours = hours; +} + +void Course::setGrade(double grade) +{ + this->grade = grade; +} + +void Course::setAdditions(std::string additions) +{ + this->additions = additions; +} diff --git a/src/grades/Course.h b/src/grades/Course.h new file mode 100644 index 0000000..688320f --- /dev/null +++ b/src/grades/Course.h @@ -0,0 +1,60 @@ +#ifndef COURSE_H +#define COURSE_H + +#include +#include +#include + +#define COURSE_FIELDS 7 +#define NO_GRADE_YET 101; + + +class Course{ + +public: + enum CourseScheme + { + SERIAL, + NAME, + TYPE, + POINTS, + HOURS, + GRADE, + ADDITION + }; + + Course(int serial,std::string name, std::string type, double points, double hours, double grade, std::string additions); + ~Course(); + + + void printCourse(); + + int getSerialNum() const {return this->serialNum;} + std::string getName() const {return this->name;} + std::string getType() const {return this->type;} + double getPoints() const {return this->points;} + double getHours() const {return this->hours;} + double getGrade() const ; + std::string getAddidtions() const {return this->additions;} + + void setName(std::string name); + void setType(std::string type); + void setPoints(double points); + void setHours(double hours); + void setGrade(double grade); + void setAdditions(std::string additions); + +private: + + int serialNum; + std::string name; + std::string type; + double points; + double hours; + double grade; + std::string additions; +}; + + + +#endif diff --git a/src/grades/GradePage.cpp b/src/grades/GradePage.cpp new file mode 100644 index 0000000..5c73f3b --- /dev/null +++ b/src/grades/GradePage.cpp @@ -0,0 +1,184 @@ +#include "GradePage.h" + +GradePage::GradePage(std::string html) : Page(html) +{ + courses = new std::list(); + tempHtml = getString(); + genList(); + +} +GradePage::~GradePage() +{ + for(Course* c : *courses) + delete c; + delete courses; +} +void GradePage::genList() +{ + + this->tempHtml = tokenToLines( this->tempHtml , INFO_DATA_LINES_BEFORE_GRADES_DATA ); + + coursesListInit(this->tempHtml); + +} +void GradePage::addCourse(Course *a) +{ + GradePage::courses->push_back(a); + return; +} + +void GradePage::removeCourse(std::string courseSerialID) +{ + for(Course* c : *courses) + { + if (c->getSerialNum() == stoi(courseSerialID)) + { + courses->remove(c); + delete c; + return; + } + } + +} +void GradePage::coursesListInit(std::string& linesTokinzedString) +{ + std::list stringHolder; + std::string temp; + Course* cTemp = NULL; + char* tok; + char* textToTok = strdup(linesTokinzedString.c_str()); + tok = strtok(textToTok,"\n"); + while (tok != NULL) + { + temp = tok; + stringHolder.push_back(temp); + tok = strtok(NULL, "\n"); + } + for(std::string temp: stringHolder) + { + cTemp = lineToCourse(temp); + if (cTemp != NULL) + addCourse(cTemp); + } +} + +std::string GradePage::tokenToLines(std::string& textToPhrase,int fromLine) +{ + int ctr = 0; + std::string temp = ""; + char *tok; + char* textToTok = strdup(textToPhrase.c_str()); + tok = strtok(textToTok, "\n"); + while(tok != NULL) + { + //amount of data before the actual needed data and no empty lines + if ((ctr >= fromLine) && (strcmp(tok," \t ") != 0)) + { + temp += tok; + temp += "\n"; + } + ctr++; + tok = strtok(NULL, "\n"); + } + return temp; + +} +Course* GradePage::lineToCourse(std::string line) +{ + Course *tempC = NULL; + std::string templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions] + int serial; + double points,hours,grade; + std::string name,type, additions; + std::string tempS = ""; + int i = 0; + char* tok; + char* cLine = strdup(line.c_str()); + tok = strtok(cLine, "\t"); + while(tok != NULL) + { + + tempS = tok; + if (i == 1) //skip the tokenizing loop just once + { + tempS = ""; + char *tokTemp; + tokTemp = tok; + + while (!(isdigit((int)*tokTemp))) + tokTemp++; + + while (isdigit((int)*tokTemp)) + { + tempS += *tokTemp; + tokTemp++; + } + templinearray[i-1] = tempS; + templinearray[i] = tokTemp; + + } + else if (i > 1) + templinearray[i] = tempS; + i++; + tok=strtok(NULL, "\t"); + } + if (templinearray[0] == "") //empty phrasing + return NULL; + + serial = stoi(templinearray[Course::CourseScheme::SERIAL]); + + name = templinearray[Course::CourseScheme::NAME]; + type = templinearray[Course::CourseScheme::TYPE]; + + points = stod(templinearray[Course::CourseScheme::POINTS]); + hours = stod(templinearray[Course::CourseScheme::HOURS]); + + if (isGradedYet(templinearray[Course::CourseScheme::GRADE])) + grade = stod(templinearray[Course::CourseScheme::GRADE]); + else + grade = NO_GRADE_YET; + + additions = templinearray[Course::CourseScheme::ADDITION]; + + tempC = new Course(serial,name,type,points,hours,grade,additions); + return tempC; +} + +//checking if one of the chars inside grade is not a number +bool GradePage::isGradedYet(std::string grade) +{ + if (strlen(grade.c_str()) <= 1) + return false; + + for (char c: grade) + { + if (c == '\0') + break; + if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9 + return false; + + } + return true; +} +void GradePage::printCourses() +{ + for(Course* c : *courses) + c->printCourse(); +} + +double GradePage::getAvg() +{ + double avg = 0; + double points = 0; + for(Course* c : *courses) + { + if ((c->getGrade() != 0)) + { + avg += c->getGrade() * c->getPoints(); + points += c->getPoints(); + } + } + + avg /= points; + return avg; +} diff --git a/src/grades/GradePage.h b/src/grades/GradePage.h new file mode 100644 index 0000000..912dae5 --- /dev/null +++ b/src/grades/GradePage.h @@ -0,0 +1,42 @@ +#ifndef GRADE_PAGE_H +#define GRADE_PAGE_H + +#include "Page.h" +#include "Course.h" + +#include +#include //strlen and strtok to phrase the html file +#include //checks if character is numeric + +#define INFO_DATA_LINES_BEFORE_GRADES_DATA 5 + +class GradePage : public Page +{ + +public: + GradePage(std::string html); + void printCourses(); + ~GradePage(); + + void addCourse(Course *); + void removeCourse(std::string courseSerialID); + double getAvg(); + + std::list* getCourses() { return courses; } + +private: + + void genList(); + std::string tokenToLines(std::string& textToPhrase,int fromLine = 0); + void coursesListInit(std::string& linesTokinzedString); + Course* lineToCourse(std::string line); + + bool isGradedYet(std::string grade); + + std::list* courses; + std::string tempHtml; + +}; + + +#endif diff --git a/src/grades/Page.cpp b/src/grades/Page.cpp new file mode 100644 index 0000000..066cf7f --- /dev/null +++ b/src/grades/Page.cpp @@ -0,0 +1,164 @@ +#include "Page.h" + +Page::Page(std::string& html) +{ + makeText(html); +} +void Page::makeText(std::string& html) +{ + int index = 0; + index = findTitle(html, index); + index = runToActualText(html, index); //set index into the actual place where the data is + manageTableContent(html, index); +} + +int Page::findTitle(std::string& from, int index) +{ + std::string temp; + while(index < (int)from.length()) + { + if(from[index] == '<') + { + //title> + index++; + std::string titleTag = from.substr(index, 5); //legth of title + if(titleTag == "title") //check if the tag is title + { + while(from[index] != '>') + index++; + index++; + while(from[index] != '<') + { + temp += from[index]; + index++; + } + this->title = temp; //sets the title + return index; + } + } + + index++; + } + return -1; +} + +int Page::runToActualText(std::string& from, int index) +{ + while(index < (int)from.length()) + { + if(from[index] == '<') + { + index++; + if(from[index] == '!') + { + //!--FileName + std::string bodyTag = from.substr(index, 11); //!--FileName + + if(bodyTag == "!--FileName") //check if the tag is body tag + { + while(from[index] != '>') + index++; + return index; + } + } + } + index++; + } + return -1; +} + +void Page::manageTableContent(std::string& html, int index) +{ + std::string temp; + for (int i = index; i < (int)html.length(); i++) + { + if(html[i] == '<') + { + // / / + std::string endofTable = ""; + std::string tableTag = html.substr(i, 4); //legth of "tr/td" + if(tableTag == "") + { + temp += "\n"; //new row -> new line + i = stitchText(html, temp, i+4); + if(i == -1) //EOF + break; + } + else if(tableTag == "" || tableTag == "") + { + temp += "\t"; // new cell -> tab between data + i = stitchText(html, temp, i+4); + if (i == -1) //EOF + break; + } + else if(tableTag == "text = temp; +} + +int Page::stitchText(std::string& from, std::string& to, int index) +{ + if (from[index] == '<') + { + std::string bTag = from.substr(index, 3); + if (bTag != "") + return index-1; //go back one step - for the main function to inc i + index += 3; + } + + while (from[index] != '<' && index < (int)from.length()) + { + if (from[index] == '&') + { + //  + std::string nbspChr = from.substr(index, 6); + if (nbspChr == " ") + { + index += 5; + from.at(index) = ' '; + } + + } + + if (endOfString(index,(int) from.length())) + return -1; //EOF + + else if (from[index] == '<') + return index - 1; //go back one step - for the main function to inc i + + if (from[index] != '\n') //check the actuall data before continue + to += from[index]; + index++; + } + + return index-1; +} +bool Page::endOfString(int index, int length) +{ + if(index < length) + return false; + return true; +} + +std::string Page::getString() +{ + return this->text; +} + +std::string Page::getTitle() +{ + return this->title; +} diff --git a/src/grades/Page.h b/src/grades/Page.h new file mode 100644 index 0000000..c40f2e8 --- /dev/null +++ b/src/grades/Page.h @@ -0,0 +1,37 @@ +#ifndef PAGE_H +#define PAGE_H + +#include +#include + +class Page +{ + +public: + + ~Page() {} + + + +protected: + Page(std::string& html); + std::string getString(); + std::string getTitle(); + void makeText(std::string& html); + + +private: + + + int findTitle(std::string& from, int index); + int runToActualText(std::string& from, int index); + void manageTableContent(std::string& html, int index); + int stitchText(std::string& from, std::string& to, int index); + bool endOfString(int index, int length); + + std::string text; + std::string title; + +}; + +#endif \ No newline at end of file diff --git a/src/jce/jceLoginHtmlScripts.h b/src/jce/jceLoginHtmlScripts.h new file mode 100644 index 0000000..148a918 --- /dev/null +++ b/src/jce/jceLoginHtmlScripts.h @@ -0,0 +1,72 @@ +#ifndef JCELOGINHTMLSCRIPTS_H +#define JCELOGINHTMLSCRIPTS_H + +#include + +#define dst_host "yedion.jce.ac.il" +#define dst_port 443 + +#include "../user.h" + +class jceLoginHtmlScripts +{ + +private: + + jceLoginHtmlScripts(); + +public: + + static std::string makeRequest(std::string parameters) + { + std::string msg; + msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n"; + msg += "Host: " + std::string(dst_host) + "\r\n"; + msg += "Content-Type: application/x-www-form-urlencoded\r\n"; + msg += "Content-Length: " + to_string(parameters.length()) + "\r\n"; + msg += "Proxy-Connection: Keep-Alive\r\n"; + msg += "Accept-Charset: utf-8"; + msg += "Accept: text/plain\r\n"; + msg += "Connection: Keep-Alive\r\n"; + msg += "\r\n"; + msg += parameters; + return msg; + } + + const static std::string getFirstValidationStep(const user &usr) + { + std::string parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N"; + parameters += usr.getUsername(); + parameters += ",-N"; + parameters += usr.getPassword(); + return parameters; + } + + const static std::string getSecondValidationStep(const user &usr) + { + std::string parameters; + parameters = "prgname=LoginValidtion1&Arguments=-N"; + parameters += usr.getUserID(); + parameters += ",-A,-N"; + parameters += usr.getHashedPassword(); + parameters += ",-A,-A"; + return parameters; + } + const static std::string getGradesPath(const user &usr) + { + std::string parameters; + parameters = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&"; + parameters += "TZ=" + usr.getUserID() + "&"; + parameters += "UNIQ=" + usr.getHashedPassword() + "&"; + parameters += "R1C2=" + usr.date->getFYear() + "&"; + parameters += "R1C1=" + usr.date->getTYear() + "&"; + parameters += "R1C3=" + usr.date->getTSemester() + "&"; + parameters += "R1C4=" + usr.date->getFSemester() + "&"; + parameters += "R1C5=0"; + return parameters; + } + + +}; + +#endif // JCELOGINHTMLSCRIPTS_H diff --git a/src/jce/jcedate.cpp b/src/jce/jcedate.cpp new file mode 100644 index 0000000..1638890 --- /dev/null +++ b/src/jce/jcedate.cpp @@ -0,0 +1,34 @@ +#include "jcedate.h" + +jceDate::jceDate(std::string fromYear,std::string fromSemester,std::string toYear,std::string toSemester) +{ + this->fSemester = fromSemester; + this->fYear = fromYear; + this->tSemester = toSemester; + this->tYear = toYear; +} + +void jceDate::setFYear(std::string fromYear) +{ + this->fYear = fromYear; +} + +void jceDate::setTYear(std::string toYear) +{ + this->tYear = toYear; +} + +void jceDate::setFSemester(std::string fromSemester) +{ + this->fSemester = fromSemester; +} + +void jceDate::setTSemester(std::string toSemester) +{ + this->tSemester = toSemester; +} + +jceDate::~jceDate() +{ + +} diff --git a/src/jce/jcedate.h b/src/jce/jcedate.h new file mode 100644 index 0000000..46d965b --- /dev/null +++ b/src/jce/jcedate.h @@ -0,0 +1,33 @@ +#ifndef JCEDATE_H +#define JCEDATE_H + +#include + +class jceDate +{ + +public: + + jceDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester); + ~jceDate(); + + void setFYear(std::string fromYear); + void setTYear(std::string toYear); + void setFSemester(std::string fromSemester); + void setTSemester(std::string toSemester); + + std::string getFYear() { return this->fYear;} + std::string getTYear() { return this->tYear;} + std::string getFSemester() { return this->fSemester;} + std::string getTSemester() { return this->tSemester;} + +private: + std::string fYear; //from + std::string fSemester; + + std::string tYear; //to + std::string tSemester; + +}; + +#endif // JCEDATE_H diff --git a/src/jce/jcelogin.cpp b/src/jce/jcelogin.cpp new file mode 100644 index 0000000..cd8f003 --- /dev/null +++ b/src/jce/jcelogin.cpp @@ -0,0 +1,194 @@ +#include "jcelogin.h" + +jceLogin::jceLogin(user * username) +{ + this->recieverPage = new std::string(); + this->jceA = username; + this->JceConnector = new qtsslsocket(dst_host, dst_port); +} + +jceLogin::~jceLogin() +{ + this->jceA = NULL; + delete recieverPage; + delete JceConnector; + JceConnector = NULL; + recieverPage = NULL; +} + +void jceLogin::makeConnection() throw (jceStatus) +{ + jceStatus status; + cout << "Connecting with username: " << jceA->getUsername() << std::endl; + + if (checkConnection() == true) + { + cout << "first visiting..." << endl; + if (makeFirstVisit() == true) + { + status = jceStatus::JCE_FIRST_VALIDATION_PASSED; + cout << "validating..." << endl; + if (checkValidation() == true) + { + cout << "singing in" << endl; + status = jceStatus::JCE_SECOND_VALIDATION_PASSED; + if (makeSecondVisit() == true) + { + status = jceStatus::JCE_YOU_ARE_IN; + setLoginFlag(true); + } + else + { + status = jceStatus::ERROR_ON_VALIDATION; + cout << "not in evantually. error!" << std::endl; + } + + } + else + { + status = jceStatus::ERROR_ON_VALIDATION; + cout<< "error on validation" << std::endl; + } + + } + else + { + cout << "error on first visit" << std::endl; + status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED; + } + + } + else + { + cout << "error on creating socket" << std::endl; + status = jceStatus::ERROR_ON_OPEN_SOCKET; + } + throw status; + +} + +bool jceLogin::checkConnection() +{ + if (JceConnector->isCon()) + return true; + + return false; +} + +void jceLogin::reConnect() throw (jceStatus) +{ + closeAll(); + this->recieverPage = new std::string(); + this->JceConnector = new qtsslsocket(dst_host, dst_port); + try + { + makeConnection(); + } + catch (jceLogin::jceStatus &a) + { + throw a; + } +} + +void jceLogin::closeAll() +{ + delete recieverPage; + recieverPage = NULL; + JceConnector = NULL; + +} + +int jceLogin::makeFirstVisit() +{ + std::string usr = jceA->getUsername(); + std::string psw = jceA->getPassword(); + + if (JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA)))) + { + if (!JceConnector->recieve(*recieverPage)) + return jceLogin::ERROR_ON_GETTING_INFO; + } + else + return jceLogin::ERROR_ON_SEND_REQUEST; + + return true; +} + +int jceLogin::makeSecondVisit() +{ + std::string usrid=jceA->getUserID(); + std::string pswid=jceA->getHashedPassword(); + if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA))))) + { + if (!(JceConnector->recieve(*recieverPage))) + return jceLogin::ERROR_ON_GETTING_INFO; + + return true; + } + else + return jceLogin::ERROR_ON_SEND_REQUEST; + + return true; +} + +int jceLogin::getGrades() +{ + if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA))))) + { + if (!(JceConnector->recieve(*recieverPage))) + return jceLogin::ERROR_ON_GETTING_GRADES; + + return true; + } + else + return jceLogin::ERROR_ON_SEND_REQUEST; + + return true; + +} + +void jceLogin::setLoginFlag(bool x) +{ + this->loginFlag = x; +} + +void jceLogin::setProgressBar(QProgressBar *ptr) +{ + this->JceConnector->setProgressBar(ptr); +} +bool jceLogin::isLoginFlag() const +{ + return this->loginFlag; +} + +std::string jceLogin::getPage() +{ + return *recieverPage; +} + +bool jceLogin::checkValidation() +{ + //finds the hashed password + + std::size_t hasspass_position1 = recieverPage->find("-A,-N"); + hasspass_position1 += 5; + std::size_t hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1); + if ((hasspass_position2 != std::string::npos) && (hasspass_position1 != std::string::npos)) + { + std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1); + jceA->setHashedPassword(hasspass); + } + //finds the user id + std::size_t id_position1 = recieverPage->find("value=\"-N", 0); + id_position1 += 9; + std::size_t id_position2 = recieverPage->find(",-A", id_position1); + if ((id_position2 != std::string::npos) && (id_position1 != std::string::npos)) + { + std::string hassid = recieverPage->substr(id_position1,id_position2-id_position1); + jceA->setUserID(hassid); + } + if (((jceA->getUserID()).empty()) || ((jceA->getHashedPassword()).empty())) + return false; + + return true; +} diff --git a/src/jce/jcelogin.h b/src/jce/jcelogin.h new file mode 100644 index 0000000..e9448f1 --- /dev/null +++ b/src/jce/jcelogin.h @@ -0,0 +1,64 @@ +#ifndef JCELOGIN_H +#define JCELOGIN_H + +#include +#include + +#include "../connection/qtsslsocket.h" +#include "../user.h" +#include "jceLoginHtmlScripts.h" + + + + +class jceLogin +{ +public: + + enum jceStatus { + JCE_NOT_CONNECTED, + ERROR_ON_VALIDATION, + ERROR_ON_VALIDATION_USER_BLOCKED, + ERROR_ON_INPUT, + ERROR_ON_CONNECTING, + ERROR_ON_OPEN_SOCKET, + ERROR_ON_GETTING_INFO, + ERROR_ON_GETTING_GRADES, + ERROR_ON_SEND_REQUEST, + JCE_START_VALIDATING_PROGRESS, + JCE_FIRST_VALIDATION_PASSED, + JCE_SECOND_VALIDATION_PASSED, + JCE_YOU_ARE_IN, + JCE_GRADE_PAGE_PASSED + }; + + jceLogin(user* username); + ~jceLogin(); + void makeConnection() throw (jceStatus); + bool checkConnection(); + void reConnect() throw (jceStatus); + void closeAll(); + int getGrades(); + bool isLoginFlag() const; + + + void setProgressBar(QProgressBar *); + + std::string getPage(); + + + +private: + int makeFirstVisit(); + bool checkValidation(); + int makeSecondVisit(); + void setLoginFlag(bool x); + + bool loginFlag; + std::string * recieverPage; + user * jceA; + qtsslsocket * JceConnector; + +}; + +#endif // JCELOGIN_H diff --git a/src/user.cpp b/src/user.cpp new file mode 100644 index 0000000..5bb944a --- /dev/null +++ b/src/user.cpp @@ -0,0 +1,52 @@ +#include "user.h" + + +user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false) +{ + + this->username = username; + this->password = password; +} +user::~user() +{ + delete date; +} +void user::setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester) +{ + date->setFYear(fromYear); + date->setFSemester(fromSemester); + date->setTYear(toYear); + date->setTSemester(toSemester); +} + +void user::setInfluenceCourseOnly(bool status) +{ + this->influenceCourseOnly = status; +} + +bool user::getInfluenceCourseOnly() const +{ + return this->influenceCourseOnly; +} + +void user::setUsername(string& username) { + this->username=username; +} + +void user::setPassword(string& password) { + this->password=password; +} + +void user::setUserID(string& ID) +{ + this->userID = ID; +} +void user::setHashedPassword(string& hashpass) +{ + this->hashedPassword = hashpass; +} + +string user::getPassword() const { return password; } +string user::getUsername() const { return username; } +string user::getUserID() const { return userID; } +string user::getHashedPassword() const { return hashedPassword; } diff --git a/src/user.h b/src/user.h new file mode 100644 index 0000000..4eaeecd --- /dev/null +++ b/src/user.h @@ -0,0 +1,48 @@ +#ifndef user_H +#define user_H + +#include +#include +#include "jce/jcedate.h" + +using namespace std; +class user +{ +public: + user(string username,string password); + ~user(); + void setUsername(string& username); + void setPassword(string& password); + + string getPassword() const; + string getUsername() const; + + void setUserID(string& ID); + void setHashedPassword(string& hashpass); + + string getUserID() const; + string getHashedPassword() const; + + void setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester); + + void setInfluenceCourseOnly(bool status); + bool getInfluenceCourseOnly() const; + + jceDate * const date = new jceDate("","","",""); //we do not change the pointer + +private: + + string username; + string password; + + string hashedPassword; + string userID; + + bool influenceCourseOnly; + + + +}; +#endif + +