From e8e8bc4b06b6fa4fdd61bd816e19679c83902362 Mon Sep 17 00:00:00 2001 From: liranbg Date: Sat, 14 Jun 2014 20:02:50 +0300 Subject: [PATCH] Initial commit --- jceGrade.pro | 49 +++ main/coursestablemanager.cpp | 215 ++++++++++ main/coursestablemanager.h | 43 ++ main/loginhandler.cpp | 66 ++++ main/loginhandler.h | 29 ++ main/main.cpp | 13 + main/mainscreen.cpp | 237 +++++++++++ main/mainscreen.h | 78 ++++ main/mainscreen.ui | 691 +++++++++++++++++++++++++++++++++ resources/blueStatusIcon.png | Bin 0 -> 1990 bytes resources/connectionstatus.qrc | 8 + resources/greenStatusIcon.png | Bin 0 -> 1879 bytes resources/icon.png | Bin 0 -> 3175 bytes resources/redStatusIcon.png | Bin 0 -> 1699 bytes src/connection/qtsslsocket.cpp | 56 +++ src/connection/qtsslsocket.h | 40 ++ src/grades/Course.cpp | 75 ++++ src/grades/Course.h | 60 +++ src/grades/GradePage.cpp | 184 +++++++++ src/grades/GradePage.h | 42 ++ src/grades/Page.cpp | 164 ++++++++ src/grades/Page.h | 37 ++ src/jce/jceLoginHtmlScripts.h | 72 ++++ src/jce/jcedate.cpp | 34 ++ src/jce/jcedate.h | 33 ++ src/jce/jcelogin.cpp | 194 +++++++++ src/jce/jcelogin.h | 64 +++ src/user.cpp | 52 +++ src/user.h | 48 +++ 29 files changed, 2584 insertions(+) create mode 100644 jceGrade.pro create mode 100644 main/coursestablemanager.cpp create mode 100644 main/coursestablemanager.h create mode 100644 main/loginhandler.cpp create mode 100644 main/loginhandler.h create mode 100644 main/main.cpp create mode 100644 main/mainscreen.cpp create mode 100644 main/mainscreen.h create mode 100644 main/mainscreen.ui create mode 100644 resources/blueStatusIcon.png create mode 100644 resources/connectionstatus.qrc create mode 100644 resources/greenStatusIcon.png create mode 100644 resources/icon.png create mode 100644 resources/redStatusIcon.png create mode 100644 src/connection/qtsslsocket.cpp create mode 100644 src/connection/qtsslsocket.h create mode 100644 src/grades/Course.cpp create mode 100644 src/grades/Course.h create mode 100644 src/grades/GradePage.cpp create mode 100644 src/grades/GradePage.h create mode 100644 src/grades/Page.cpp create mode 100644 src/grades/Page.h create mode 100644 src/jce/jceLoginHtmlScripts.h create mode 100644 src/jce/jcedate.cpp create mode 100644 src/jce/jcedate.h create mode 100644 src/jce/jcelogin.cpp create mode 100644 src/jce/jcelogin.h create mode 100644 src/user.cpp create mode 100644 src/user.h 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 0000000000000000000000000000000000000000..1f70d90fe2b98a7d65649e9abb6188d9d4c33e8a GIT binary patch literal 1990 zcmV;%2RZnOP) zh#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%*0R{?=YQa(~IBMQf z&9|5{1~EdKn=FoF?%%n?%;{5{|K-n`OEVYW%AvDcLEFJS_3oEVwdHT|W1)9%nyhj{$aNp{q00DQXCsPNN3-|6_U2Zf^ zhNRoO!gL-s`R9RqzxOU}M+$|~@ls#;8SmVbwb`XDO+zzIliQv3^)ua0=N;e!zQCpJ YzxA!b_1%Arx&QzG07*qoM6N<$f?Sce{Qv*} literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..fcb16a420b7a34bd7c487f94b855a5737849e1b1 GIT binary patch literal 1879 zcmV-d2dMaoP)strj9X`D1a9mk&W%$s>X?!7E##&#?xZJ%^>@0RceJPT=@6@IH`#7VsEwn8X}OrYHCA{>onU)fe{h z+^(nDy>$o8O_L-h0w62<+-fiI!SzeL`{7ys`Hxea`_~!Uox6L6ZuvXl_rT((0dE6- zB&L$1+rIIovG0ECI~@4(H`&$PPHdtFM(TlHk#p|WW&Zl^-}vL}f8yHTKWOT_) zaBc1LY6Iv`X(q4C9Qs=QhlgJk2cG#lkJcZdaF(p>(|v$tWuL-UG~yaN9-C(Cj%hy9 zOVPr$TTjs`CxNp-Ya{R&@DrNJD-+*-I{oqYUKKl=kK=H3ii}Rt8;%*BGFzP&8J&FX zeUH+WjMp~t#N*pJUCf#6#^MZ}(g5!OeE>a#hQMJq$4AoxJJatUd`To>#C&&g<6^A; zZKK}x5Qh2jRgwM;ax}&d!RHHy0cJ3Kkxz^KMTs(;5oCc;y^~*f5NsTur@e-Eu4#**F zt>X3S*QeUApZmcmVZ1p>dq+cYy?cn|;4mRD>eX^ z&Ju(HOxNLz*~xP8tVW6bOvak=5Gx!V+e3Oe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3e%Q-i7r#q32- z(*DZ#$5!D9Fau~6=lSJ+IQugpdM76*v0ayNbrm7y`XWeYc5{|D*NjO-YwSXSBa@Tj z=a(<{{Lz@R6}SRiQ$Sw9n@8aAPh1ywU;sQ1(`rQvDYclMS9@s#3}B4G7z4)O4h(SI zb-7ln{pb>$3SdqF{eAG(F_1&$GSV1WTic*;C*V#^0z>68$7(fs3(hRVpA;~;8%AFR z>`VsHZiChvpowf}gowRN`n2}|!uPQ=8D0f0!ss%*qB3ye0H{GgYK>?#5SE1itXP?~ z3A$B|)9^5!6DIS+5UDjozPV6YA`Ojc zVN^YYFWAb##g|3$~3gD~46u_&X3JU=7?^GPt)j6GwZn z`-@swSLh1Wn}^4KBpcZ_}X7-~|5pQkN$;*4RB?4|g{@b<1_uaPxIUrjE!o zz;1%5f&U#e7xC8?xcBWt{&wprf0zyRNB5YS_c$Mi_wi=Pj#rqB#i>07&J6W1dT1}| z$Uzt!l(^rEY_31iJba|Nc^7Uk58002ovPDHLkV1neY31R>M literal 0 HcmV?d00001 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 + +