")
- {
- 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
- if (html.substr(i, 6) == " | ');
- i = stitchText(html, temp, i+1);
- }
- else
- i = stitchText(html, temp, i+4);
- if (i == -1) //EOF
- break;
- }
- else if(tableTag == " | ')
- i++;
- i = stitchText(html, temp, i+1);
- }
- else if (html.substr(i,(endofTable).length()) == endofTable) //is end of table
- {
- break;
- }
- }
-
- }
-
- this->text = temp;
-}
-
-int Page::stitchText(std::string& from, std::string& to, int index)
-{
- if (from[index] == '<')
- {
- std::string bTag = from.substr(index, 3);
- if (bTag != "")
- 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;
-}
+#include "page.h"
+
+Page::Page()
+{
+
+}
+std::string Page::getString(std::string& htmlToPhrased)
+{
+ makeText(htmlToPhrased);
+ return this->text;
+}
+void Page::makeText(std::string& html)
+{
+ int index = 0;
+ index = runToActualText(html, index); //set index into the actual place where the data is
+ manageTableContent(html, index);
+}
+
+int Page::runToActualText(std::string& from, int index)
+{
+ while (index < (int)from.length())
+ {
+ if (from[index] == '<')
+ {
+ if (from.substr(index,7) == "")
+ return index+7;
+ }
+ 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
+ if (html.substr(i, 6) == " | ');
+ i = stitchText(html, temp, i+1);
+ }
+ else
+ i = stitchText(html, temp, i+4);
+ if (i == -1) //EOF
+ break;
+ }
+ else if(tableTag == " | ')
+ i++;
+ i = stitchText(html, temp, i+1);
+ }
+ else if (html.substr(i,(endofTable).length()) == endofTable) //is end of table
+ {
+ break;
+ }
+ }
+
+ }
+
+ this->text = temp;
+}
+
+int Page::stitchText(std::string& from, std::string& to, int index)
+{
+ if (from[index] == '<')
+ {
+ std::string bTag = from.substr(index, 3);
+ if (bTag != "")
+ 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;
+}
diff --git a/src/jceData/page.h b/src/jceData/page.h
index db584d0..d98b55a 100644
--- a/src/jceData/page.h
+++ b/src/jceData/page.h
@@ -1,39 +1,39 @@
-#ifndef PAGE_H
-#define PAGE_H
-
-/* This Code Made By Sagi Dayan
- * SagiDayan@gmail.com
- *
- * Minor changes has been made by Liran Ben Gida
- * LiranBG@gmail.com
-*/
-
-#include
-#include
-
-class Page
-{
-
-public:
-
- ~Page() {}
-
-protected:
- Page();
- std::string getString(std::string& htmlToPhrased);
- void makeText(std::string& html);
-
-
-private:
-
- int runToActualText(std::string& from, int index);
- void manageTableContent(std::string& html, int index);
- int stitchText(std::string& from, std::string& to, int index);
- bool endOfString(int index, int length);
-
- std::string text;
- std::string title;
-
-};
-
-#endif
+#ifndef PAGE_H
+#define PAGE_H
+
+/* This Code Made By Sagi Dayan
+ * SagiDayan@gmail.com
+ *
+ * Minor changes has been made by Liran Ben Gida
+ * LiranBG@gmail.com
+*/
+
+#include
+#include
+
+class Page
+{
+
+public:
+
+ ~Page() {}
+
+protected:
+ Page();
+ std::string getString(std::string& htmlToPhrased);
+ void makeText(std::string& html);
+
+
+private:
+
+ 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
diff --git a/src/jceSettings/jceLoginHtmlScripts.h b/src/jceSettings/jceLoginHtmlScripts.h
index 5b9f8a7..c2c7854 100644
--- a/src/jceSettings/jceLoginHtmlScripts.h
+++ b/src/jceSettings/jceLoginHtmlScripts.h
@@ -1,87 +1,87 @@
-#ifndef JCELOGINHTMLSCRIPTS_H
-#define JCELOGINHTMLSCRIPTS_H
-
-#include
-
-#define dst_host "yedion.jce.ac.il"
-#define dst_port 443
-
-#include "./src/jceSettings/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,
- int fromYear,
- int toYear,
- int fromSemester,
- int toSemester)
- {
- 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=" + std::to_string(fromYear) + "&";
- parameters += "R1C1=" + std::to_string(toYear) + "&";
- parameters += "R1C3=" + std::to_string(toSemester) + "&";
- parameters += "R1C4=" + std::to_string(fromSemester) + "&";
- parameters += "R1C5=0";
- return parameters;
- }
- const static std::string getCalendar(const user &usr,int year, int semester)
- {
- std::string parameters;
- parameters = "PRGNAME=Bitsua_maarechet_shaot&ARGUMENTS=TZ,UNIQ,MisparSheilta,R1C1,R1C2&";
- parameters += "TZ=" + usr.getUserID() + "&";
- parameters += "UNIQ=" + usr.getHashedPassword() + "&";
- parameters += "MisparSheilta=3&";
- parameters += "R1C1=" + std::to_string(year) + "&";
- parameters += "R1C2=" + std::to_string(semester) + "&";
- return parameters;
- }
-
-
-};
-
-#endif // JCELOGINHTMLSCRIPTS_H
+#ifndef JCELOGINHTMLSCRIPTS_H
+#define JCELOGINHTMLSCRIPTS_H
+
+#include
+
+#define dst_host "yedion.jce.ac.il"
+#define dst_port 443
+
+#include "./src/jceSettings/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,
+ int fromYear,
+ int toYear,
+ int fromSemester,
+ int toSemester)
+ {
+ 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=" + std::to_string(fromYear) + "&";
+ parameters += "R1C1=" + std::to_string(toYear) + "&";
+ parameters += "R1C3=" + std::to_string(toSemester) + "&";
+ parameters += "R1C4=" + std::to_string(fromSemester) + "&";
+ parameters += "R1C5=0";
+ return parameters;
+ }
+ const static std::string getCalendar(const user &usr,int year, int semester)
+ {
+ std::string parameters;
+ parameters = "PRGNAME=Bitsua_maarechet_shaot&ARGUMENTS=TZ,UNIQ,MisparSheilta,R1C1,R1C2&";
+ parameters += "TZ=" + usr.getUserID() + "&";
+ parameters += "UNIQ=" + usr.getHashedPassword() + "&";
+ parameters += "MisparSheilta=3&";
+ parameters += "R1C1=" + std::to_string(year) + "&";
+ parameters += "R1C2=" + std::to_string(semester) + "&";
+ return parameters;
+ }
+
+
+};
+
+#endif // JCELOGINHTMLSCRIPTS_H
diff --git a/src/jceSettings/jcelogin.cpp b/src/jceSettings/jcelogin.cpp
index 161cdea..2f2f2e0 100644
--- a/src/jceSettings/jcelogin.cpp
+++ b/src/jceSettings/jcelogin.cpp
@@ -1,229 +1,232 @@
-#include "jcelogin.h"
-
-jceLogin::jceLogin(user * username)
-{
- this->recieverPage = new std::string();
- this->jceA = username;
- this->JceConnector = new jceSSLClient();
-}
-
-jceLogin::~jceLogin()
-{
- this->jceA = NULL;
- delete recieverPage;
- delete JceConnector;
- JceConnector = NULL;
- recieverPage = NULL;
-}
-/**
- * @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it.
- * throws error upon the given error from JCE website or Socket error
- */
-void jceLogin::makeConnection() throw (jceStatus)
-{
- if (this->recieverPage == NULL)
- this->recieverPage = new std::string();
-
- if (JceConnector->makeConnect(dst_host,dst_port) == false)
- throw jceStatus::ERROR_ON_OPEN_SOCKET;
-
- int returnMode;
- jceStatus status = jceStatus::JCE_NOT_CONNECTED;
-
- returnMode = checkConnection();
- if (returnMode == true) //connected to host
- {
- returnMode = makeFirstVisit();
- if (returnMode == true) //requst and send first validation
- {
- status = jceStatus::JCE_START_VALIDATING_PROGRESS;
- returnMode = checkValidation();
- if (returnMode == true) //check if username and password are matching
- {
- status = jceStatus::JCE_VALIDATION_PASSED;
- returnMode = makeSecondVisit();
- if (returnMode == true) //siging in the website
- {
- status = jceStatus::JCE_YOU_ARE_IN;
- setLoginFlag(true);
- }
- else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
- {
- status = jceLogin::ERROR_ON_GETTING_INFO;
- }
- else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
- {
- status = jceLogin::ERROR_ON_SEND_REQUEST;
- }
- else
- status = jceStatus::ERROR_ON_VALIDATION;
- }
- else
- status = jceStatus::ERROR_ON_VALIDATION;
-
- }
- else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
- {
- status = jceLogin::ERROR_ON_GETTING_INFO;
- }
- else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
- {
- status = jceLogin::ERROR_ON_SEND_REQUEST;
- }
- else
- status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
-
- }
- else
- status = jceStatus::JCE_NOT_CONNECTED;
-
- //we throw status even if we are IN!
- throw status;
-
-}
-
-bool jceLogin::checkConnection()
-{
- if (JceConnector->isConnected())
- return true;
-
- return false;
-}
-
-void jceLogin::reConnect() throw (jceStatus)
-{
- closeAll();
- if (this->JceConnector != NULL)
- delete JceConnector;
- this->recieverPage = new std::string();
- this->JceConnector = new jceSSLClient();
- try
- {
-
- makeConnection();
- }
- catch (jceLogin::jceStatus &a)
- {
- throw a;
- }
-}
-
-void jceLogin::closeAll()
-{
- JceConnector->makeDiconnect();
- delete recieverPage;
- recieverPage = NULL;
- loginFlag = false;
-
-}
-
-int jceLogin::makeFirstVisit()
-{
- std::string usr = jceA->getUsername();
- std::string psw = jceA->getPassword();
- if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
- {
- if (!JceConnector->recieveData(*recieverPage,true))
- 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->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
- {
- if (!(JceConnector->recieveData(*recieverPage,true)))
- return jceLogin::ERROR_ON_GETTING_INFO;
-
- return true;
- }
- else
- return jceLogin::ERROR_ON_SEND_REQUEST;
-
- return true;
-}
-
-int jceLogin::getCalendar(int year, int semester)
-{
- if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester)))))
- {
- if (!(JceConnector->recieveData(*recieverPage,false)))
- return jceLogin::ERROR_ON_GETTING_GRADES;
- else
- return jceLogin::JCE_GRADE_PAGE_PASSED;
- }
- else
- return jceLogin::ERROR_ON_SEND_REQUEST;
-
- return true;
-
-}
-int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester)
-{
- std::cout << fromYear << " " << toYear << " " << fromSemester << " " << toSemester << std::endl;
- if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
- {
- if (!(JceConnector->recieveData(*recieverPage,false)))
- return jceLogin::ERROR_ON_GETTING_GRADES;
- else
- return jceLogin::JCE_GRADE_PAGE_PASSED;
- }
- else
- return jceLogin::ERROR_ON_SEND_REQUEST;
-
- return true;
-
-}
-
-void jceLogin::setLoginFlag(bool x)
-{
- this->loginFlag = x;
-}
-bool jceLogin::isLoginFlag() const
-{
- return this->loginFlag;
-}
-
-std::string jceLogin::getPage()
-{
- return *recieverPage;
-}
-
-/**
- * @brief jceLogin::checkValidation Made by Nadav Luzzato
- * @return true if second validation step is right
- */
-bool jceLogin::checkValidation()
-{
- //finds the hashed password
- std::size_t hasspass_position1,hasspass_position2;
-
- if ((hasspass_position1 = recieverPage->find("-A,-N")) == string::npos)
- return false;
- hasspass_position1 += 5;
- if ((hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1)) == string::npos)
- return false;
-
- std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1);
- jceA->setHashedPassword(hasspass);
-
- //finds the user id
- std::size_t id_position1 = recieverPage->find("value=\"-N", 0);
- id_position1 += 9;
- std::size_t id_position2 = recieverPage->find(",-A", id_position1);
- if ((id_position2 != std::string::npos) && (id_position1 != std::string::npos))
- {
- std::string hassid = recieverPage->substr(id_position1,id_position2-id_position1);
- jceA->setUserID(hassid);
- }
- if (((jceA->getUserID()).empty()) || ((jceA->getHashedPassword()).empty()))
- return false;
-
- return true;
-}
+#include "jcelogin.h"
+
+jceLogin::jceLogin(user * username)
+{
+ this->recieverPage = new std::string();
+ this->jceA = username;
+ this->JceConnector = new jceSSLClient();
+}
+
+jceLogin::~jceLogin()
+{
+ this->jceA = NULL;
+ delete recieverPage;
+ delete JceConnector;
+ JceConnector = NULL;
+ recieverPage = NULL;
+}
+/**
+ * @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it.
+ * throws error upon the given error from JCE website or Socket error
+ */
+void jceLogin::makeConnection() throw (jceStatus)
+{
+ if (this->recieverPage == NULL)
+ this->recieverPage = new std::string();
+
+ if (JceConnector->makeConnect(dst_host,dst_port) == false)
+ throw jceStatus::ERROR_ON_OPEN_SOCKET;
+
+ int returnMode;
+ jceStatus status = jceStatus::JCE_NOT_CONNECTED;
+
+ returnMode = checkConnection();
+ if (returnMode == true) //connected to host
+ {
+ returnMode = makeFirstVisit();
+ if (returnMode == true) //requst and send first validation
+ {
+ status = jceStatus::JCE_START_VALIDATING_PROGRESS;
+ returnMode = checkValidation();
+ if (returnMode == true) //check if username and password are matching
+ {
+ status = jceStatus::JCE_VALIDATION_PASSED;
+ returnMode = makeSecondVisit();
+ if (returnMode == true) //siging in the website
+ {
+ status = jceStatus::JCE_YOU_ARE_IN;
+ setLoginFlag(true);
+ }
+ else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
+ {
+ status = jceLogin::ERROR_ON_GETTING_INFO;
+ }
+ else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
+ {
+ status = jceLogin::ERROR_ON_SEND_REQUEST;
+ }
+ else
+ status = jceStatus::ERROR_ON_VALIDATION;
+ }
+ else
+ status = jceStatus::ERROR_ON_VALIDATION;
+
+ }
+ else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
+ {
+ status = jceLogin::ERROR_ON_GETTING_INFO;
+ }
+ else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
+ {
+ status = jceLogin::ERROR_ON_SEND_REQUEST;
+ }
+ else
+ status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
+
+ }
+ else
+ status = jceStatus::JCE_NOT_CONNECTED;
+
+ //we throw status even if we are IN!
+ throw status;
+
+}
+
+bool jceLogin::checkConnection() const
+{
+ if (JceConnector->isConnected())
+ return true;
+
+ return false;
+}
+
+void jceLogin::reConnect() throw (jceStatus)
+{
+ closeAll();
+ if (this->JceConnector != NULL)
+ delete JceConnector;
+ this->recieverPage = new std::string();
+ this->JceConnector = new jceSSLClient();
+ try
+ {
+
+ makeConnection();
+ }
+ catch (jceLogin::jceStatus &a)
+ {
+ throw a;
+ }
+}
+
+void jceLogin::closeAll()
+{
+ JceConnector->makeDiconnect();
+ delete recieverPage;
+ recieverPage = NULL;
+ loginFlag = false;
+
+}
+
+int jceLogin::makeFirstVisit()
+{
+ std::string usr = jceA->getUsername();
+ std::string psw = jceA->getPassword();
+ if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
+ {
+ if (!JceConnector->recieveData(*recieverPage,true))
+ 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->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
+ {
+ if (!(JceConnector->recieveData(*recieverPage,true)))
+ return jceLogin::ERROR_ON_GETTING_INFO;
+
+ return true;
+ }
+ else
+ return jceLogin::ERROR_ON_SEND_REQUEST;
+
+ return true;
+}
+
+int jceLogin::getCalendar(int year, int semester)
+{
+ if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester)))))
+ {
+ if (!(JceConnector->recieveData(*recieverPage,false)))
+ return jceLogin::ERROR_ON_GETTING_GRADES;
+ else
+ return jceLogin::JCE_GRADE_PAGE_PASSED;
+ }
+ else
+ return jceLogin::ERROR_ON_SEND_REQUEST;
+
+ return true;
+
+}
+int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester)
+{
+ std::cout << fromYear << " " << toYear << " " << fromSemester << " " << toSemester << std::endl;
+ if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
+ {
+ if (!(JceConnector->recieveData(*recieverPage,false)))
+ return jceLogin::ERROR_ON_GETTING_GRADES;
+ else
+ return jceLogin::JCE_GRADE_PAGE_PASSED;
+ }
+ else
+ return jceLogin::ERROR_ON_SEND_REQUEST;
+
+ return true;
+
+}
+
+void jceLogin::setLoginFlag(bool x)
+{
+ this->loginFlag = x;
+}
+bool jceLogin::isLoginFlag() const
+{
+ if (checkConnection())
+ return this->loginFlag;
+ return false;
+
+}
+
+std::string jceLogin::getPage()
+{
+ return *recieverPage;
+}
+
+/**
+ * @brief jceLogin::checkValidation Made by Nadav Luzzato
+ * @return true if second validation step is right
+ */
+bool jceLogin::checkValidation()
+{
+ //finds the hashed password
+ std::size_t hasspass_position1,hasspass_position2;
+
+ if ((hasspass_position1 = recieverPage->find("-A,-N")) == string::npos)
+ return false;
+ hasspass_position1 += 5;
+ if ((hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1)) == string::npos)
+ return false;
+
+ 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/jceSettings/jcelogin.h b/src/jceSettings/jcelogin.h
index dfcb593..ae02673 100644
--- a/src/jceSettings/jcelogin.h
+++ b/src/jceSettings/jcelogin.h
@@ -1,60 +1,60 @@
-#ifndef JCELOGIN_H
-#define JCELOGIN_H
-
-#include
-#include
-
-#include "./src/jceConnection/jcesslclient.h"
-#include "./src/jceSettings/user.h"
-#include "jceLoginHtmlScripts.h"
-
-class jceLogin
-{
-public:
-
- enum jceStatus {
- JCE_NOT_CONNECTED,
- ERROR_ON_VALIDATION,
- ERROR_ON_VALIDATION_USER_BLOCKED,
- ERROR_ON_OPEN_SOCKET,
- ERROR_ON_SEND_REQUEST,
- ERROR_ON_GETTING_INFO,
- ERROR_ON_GETTING_GRADES,
-
- JCE_START_VALIDATING_PROGRESS,
- JCE_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 getCalendar(int year, int semester);
- int getGrades(int fromYear, int toYear, int fromSemester, int toSemester);
- bool isLoginFlag() const;
-
- std::string getPage();
-
-
-
-
-
-private:
- int makeFirstVisit();
- bool checkValidation();
- int makeSecondVisit();
- void setLoginFlag(bool x);
-
- bool loginFlag;
- std::string * recieverPage;
- user * jceA;
- jceSSLClient * JceConnector;
-
-
-};
-
-#endif // JCELOGIN_H
+#ifndef JCELOGIN_H
+#define JCELOGIN_H
+
+#include
+#include
+
+#include "./src/jceConnection/jcesslclient.h"
+#include "./src/jceSettings/user.h"
+#include "jceLoginHtmlScripts.h"
+
+class jceLogin
+{
+public:
+
+ enum jceStatus {
+ JCE_NOT_CONNECTED,
+ ERROR_ON_VALIDATION,
+ ERROR_ON_VALIDATION_USER_BLOCKED,
+ ERROR_ON_OPEN_SOCKET,
+ ERROR_ON_SEND_REQUEST,
+ ERROR_ON_GETTING_INFO,
+ ERROR_ON_GETTING_GRADES,
+
+ JCE_START_VALIDATING_PROGRESS,
+ JCE_VALIDATION_PASSED,
+ JCE_YOU_ARE_IN,
+ JCE_GRADE_PAGE_PASSED
+ };
+
+ jceLogin(user* username);
+ ~jceLogin();
+ void makeConnection() throw (jceStatus);
+ bool checkConnection() const;
+ void reConnect() throw (jceStatus);
+ void closeAll();
+ int getCalendar(int year, int semester);
+ int getGrades(int fromYear, int toYear, int fromSemester, int toSemester);
+ bool isLoginFlag() const;
+
+ std::string getPage();
+
+
+
+
+
+private:
+ int makeFirstVisit();
+ bool checkValidation();
+ int makeSecondVisit();
+ void setLoginFlag(bool x);
+
+ bool loginFlag;
+ std::string * recieverPage;
+ user * jceA;
+ jceSSLClient * JceConnector;
+
+
+};
+
+#endif // JCELOGIN_H
diff --git a/src/jceSettings/user.cpp b/src/jceSettings/user.cpp
index 2a046ac..5e1d6a7 100644
--- a/src/jceSettings/user.cpp
+++ b/src/jceSettings/user.cpp
@@ -1,45 +1,45 @@
-#include "user.h"
-
-
-user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false)
-{
-
- this->username = username;
- this->password = password;
-}
-user::~user()
-{
-}
-
-
-void user::setInfluenceCourseOnly(bool status)
-{
- this->influenceCourseOnly = status;
-}
-
-bool user::getInfluenceCourseOnly() const
-{
- return this->influenceCourseOnly;
-}
-
-void user::setUsername(string& username) {
- this->username=username;
-}
-
-void user::setPassword(string& password) {
- this->password=password;
-}
-
-void user::setUserID(string& ID)
-{
- this->userID = ID;
-}
-void user::setHashedPassword(string& hashpass)
-{
- this->hashedPassword = hashpass;
-}
-
-string user::getPassword() const { return password; }
-string user::getUsername() const { return username; }
-string user::getUserID() const { return userID; }
-string user::getHashedPassword() const { return hashedPassword; }
+#include "user.h"
+
+
+user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false)
+{
+
+ this->username = username;
+ this->password = password;
+}
+user::~user()
+{
+}
+
+
+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/jceSettings/user.h b/src/jceSettings/user.h
index dd638fd..1e74391 100644
--- a/src/jceSettings/user.h
+++ b/src/jceSettings/user.h
@@ -1,43 +1,43 @@
-#ifndef user_H
-#define user_H
-
-#include
-#include
-
-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 setInfluenceCourseOnly(bool status);
- bool getInfluenceCourseOnly() const;
-
-private:
-
- string username;
- string password;
-
- string hashedPassword;
- string userID;
-
- bool influenceCourseOnly;
-
-
-
-};
-#endif
-
-
+#ifndef user_H
+#define user_H
+
+#include
+#include
+
+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 setInfluenceCourseOnly(bool status);
+ bool getInfluenceCourseOnly() const;
+
+private:
+
+ string username;
+ string password;
+
+ string hashedPassword;
+ string userID;
+
+ bool influenceCourseOnly;
+
+
+
+};
+#endif
+
+
| |