update std funtions to qt's
This commit is contained in:
parent
d59da2ca0c
commit
1520f25b2a
|
@ -8,14 +8,14 @@ Page::Page() { dateHeader = "";}
|
||||||
*/
|
*/
|
||||||
QString Page::getString(QString &htmlToParse)
|
QString Page::getString(QString &htmlToParse)
|
||||||
{
|
{
|
||||||
makeText(htmlToParse);
|
makeText(htmlToParse);
|
||||||
return this->text;
|
return this->text;
|
||||||
}
|
}
|
||||||
void Page::makeText(QString &html)
|
void Page::makeText(QString &html)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
index = html.indexOf("<tbody>",0); //set index into the place where the data is
|
index = html.indexOf("<tbody>",0); //set index into the place where the data is
|
||||||
manageTableContent(html, index);
|
manageTableContent(html, index);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Page::manageTableContent strip html, make it string
|
* @brief Page::manageTableContent strip html, make it string
|
||||||
|
@ -24,153 +24,150 @@ void Page::makeText(QString &html)
|
||||||
*/
|
*/
|
||||||
void Page::manageTableContent(QString &html, int index)
|
void Page::manageTableContent(QString &html, int index)
|
||||||
{
|
{
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
return;
|
return;
|
||||||
QString temp;
|
QString temp;
|
||||||
for (int i = index; i < html.length(); i++)
|
for (int i = index; i < html.length(); i++)
|
||||||
{
|
{
|
||||||
if (html.at(i) == '<')
|
if (html.at(i) == '<')
|
||||||
{
|
{
|
||||||
//<tr> / <td> / <th>
|
//<tr> / <td> / <th>
|
||||||
QString endofTable = "</tbody>";
|
QString endofTable = "</tbody>";
|
||||||
QString tableTag = html.mid(i, 4); //legth of "tr/td"
|
QString tableTag = html.mid(i, 4); //legth of "tr/td"
|
||||||
if (tableTag == "<tr>")
|
if (tableTag == "<tr>")
|
||||||
{
|
{
|
||||||
if (!dateHeader.isEmpty())
|
if (!dateHeader.isEmpty())
|
||||||
temp += dateHeader;
|
temp += dateHeader;
|
||||||
i = stitchText(html, temp, i+4);
|
|
||||||
if (i == -1) //EOF
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (tableTag == "</tr")
|
|
||||||
{
|
|
||||||
temp += "\n"; //end row -> new line
|
|
||||||
i+=5;
|
|
||||||
}
|
|
||||||
else if (tableTag == "<td>" || tableTag == "<th>")
|
|
||||||
{
|
|
||||||
if (!dateHeader.isEmpty())
|
|
||||||
temp += "\t"; // new cell -> tab between data
|
|
||||||
if (html.mid(i, 6) == "<td><a") //link to lecturer portal, need to be deleted
|
|
||||||
{
|
|
||||||
i += 6;
|
|
||||||
while (html.at(++i) != '>');
|
|
||||||
i = stitchText(html, temp, i+1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
i = stitchText(html, temp, i+4);
|
i = stitchText(html, temp, i+4);
|
||||||
|
if (i == -1) //EOF
|
||||||
|
break;
|
||||||
|
|
||||||
if (dateHeader.isEmpty())
|
}
|
||||||
|
else if (tableTag == "</tr")
|
||||||
|
{
|
||||||
|
temp += "\n"; //end row -> new line
|
||||||
|
i+=5;
|
||||||
|
}
|
||||||
|
else if (tableTag == "<td>" || tableTag == "<th>")
|
||||||
|
{
|
||||||
|
if (!dateHeader.isEmpty())
|
||||||
|
temp += "\t"; // new cell -> tab between data
|
||||||
|
if (html.mid(i, 6) == "<td><a") //link to lecturer portal, need to be deleted
|
||||||
|
{
|
||||||
|
i += 6;
|
||||||
|
while (html.at(++i) != '>');
|
||||||
|
i = stitchText(html, temp, i+1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
i = stitchText(html, temp, i+4);
|
||||||
|
|
||||||
|
if (dateHeader.isEmpty())
|
||||||
|
temp += "\t";
|
||||||
|
|
||||||
|
if (i == -1) //EOF
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (tableTag == "<td ") // a Year title (in grades table) or Day and Hour (in calendar page)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!dateHeader.isEmpty())
|
||||||
|
{
|
||||||
|
//checking if theres a need to fill a timestamp of course
|
||||||
|
//if the string is not empty, then we will chop the last date stamp to avoid multiple date stamp in empty rows
|
||||||
|
if (!temp.isEmpty())
|
||||||
|
if (temp.lastIndexOf(dateHeader) == temp.length()-dateHeader.length())
|
||||||
|
{
|
||||||
|
temp.chop(dateHeader.length()+5);
|
||||||
|
temp += "\t";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while ((html.mid(i,5) != "</td>") && (i < (int)html.length()))
|
||||||
|
{
|
||||||
|
if (html.mid(i,3) == "<b>") //for gpa. year & semester title
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if ((html.at(i) == '>') && (html.mid(i+4,3) != "<b>")) //for calendar. day and hours
|
||||||
|
{
|
||||||
|
i += 1; //lenght of >
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
i = stitchText(html, temp, i);
|
||||||
temp += "\t";
|
temp += "\t";
|
||||||
|
}
|
||||||
if (i == -1) //EOF
|
if (html.mid(i,(endofTable).length()) == endofTable) //is end of table
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (tableTag == "<td ") // a Year title (in grades table) or Day and Hour (in calendar page)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!dateHeader.isEmpty())
|
|
||||||
{
|
|
||||||
//checking if theres a need to fill a timestamp of course
|
|
||||||
//if the string is not empty, then we will chop the last date stamp to avoid multiple date stamp in empty rows
|
|
||||||
if (!temp.isEmpty())
|
|
||||||
if (temp.lastIndexOf(dateHeader) == temp.length()-dateHeader.length())
|
|
||||||
{
|
|
||||||
temp.chop(dateHeader.length()+5);
|
|
||||||
temp += "\t";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while ((html.mid(i,5) != "</td>") && (i < (int)html.length()))
|
|
||||||
{
|
|
||||||
if (html.mid(i,3) == "<b>") //for gpa. year & semester title
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if ((html.at(i) == '>') && (html.mid(i+4,3) != "<b>")) //for calendar. day and hours
|
|
||||||
{
|
|
||||||
i += 1; //lenght of >
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
i = stitchText(html, temp, i);
|
|
||||||
temp += "\t";
|
|
||||||
}
|
|
||||||
if (html.mid(i,(endofTable).length()) == endofTable) //is end of table
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->text = temp;
|
this->text = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Page::stitchText(QString &from, QString &to, int index)
|
int Page::stitchText(QString &from, QString &to, int index)
|
||||||
{
|
{
|
||||||
if (from.mid(index,3) == "<b>")
|
if (from.mid(index,3) == "<b>")
|
||||||
{
|
{
|
||||||
QString bTag = from.mid(index, 3);
|
QString bTag = from.mid(index, 3);
|
||||||
QString dateline = from.mid(index,from.indexOf("</b>",index+4)-index);
|
QString dateline = from.mid(index,from.indexOf("</b>",index+4)-index);
|
||||||
QString temp;
|
QString temp;
|
||||||
QString date;
|
QString date;
|
||||||
char* tok;
|
QStringList holder = dateline.split("<> :");
|
||||||
int i = 0;
|
QStringList::iterator iterator;
|
||||||
char* textToTok = strdup(dateline.toStdString().c_str());
|
int i = 0;
|
||||||
tok = strtok(textToTok,"<> :");
|
for (iterator = holder.begin(); iterator != holder.end(); ++iterator)
|
||||||
while (tok != NULL)
|
|
||||||
{
|
{
|
||||||
if (i == 1)
|
temp = (*iterator);
|
||||||
|
if (i == 0)
|
||||||
{
|
{
|
||||||
temp = tok;
|
date += temp + "\t";
|
||||||
date += temp + "\t";
|
|
||||||
}
|
}
|
||||||
else if (i == 3)
|
else if (i == 3)
|
||||||
{
|
{
|
||||||
temp = tok;
|
date += temp;
|
||||||
date += temp;
|
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
tok = strtok(NULL, "<> :");
|
|
||||||
}
|
}
|
||||||
dateHeader = date;
|
dateHeader = date;
|
||||||
if (bTag != "<b>")
|
if (bTag != "<b>")
|
||||||
return index-1; //go back one step - for the main function to inc i
|
return index-1; //go back one step - for the main function to inc i
|
||||||
index += dateline.length();
|
index += dateline.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (from.at(index) != '<' && index < (int)from.length())
|
while (from.at(index) != '<' && index < (int)from.length())
|
||||||
{
|
{
|
||||||
if (from[index] == '&')
|
if (from[index] == '&')
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
QString nbspChr = from.mid(index, 6);
|
QString nbspChr = from.mid(index, 6);
|
||||||
if (nbspChr == " ")
|
if (nbspChr == " ")
|
||||||
{
|
{
|
||||||
index += 5;
|
index += 5;
|
||||||
from.replace(index,1,' ');
|
from.replace(index,1,' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endOfString(index,(int) from.length()))
|
if (endOfString(index,(int) from.length()))
|
||||||
return -1; //EOF
|
return -1; //EOF
|
||||||
|
|
||||||
else if (from.at(index) == '<')
|
else if (from.at(index) == '<')
|
||||||
return index - 1; //go back one step - for the main function to inc i
|
return index - 1; //go back one step - for the main function to inc i
|
||||||
|
|
||||||
if ((from.at(index) != '\n') && (from.at(index) != '\t')) //check the actuall data before continue
|
if ((from.at(index) != '\n') && (from.at(index) != '\t')) //check the actuall data before continue
|
||||||
to += from.at(index);
|
to += from.at(index);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return index-1;
|
return index-1;
|
||||||
}
|
}
|
||||||
bool Page::endOfString(int index, int length)
|
bool Page::endOfString(int index, int length)
|
||||||
{
|
{
|
||||||
if(index < length)
|
if(index < length)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,21 +6,21 @@
|
||||||
*/
|
*/
|
||||||
jceLogin::jceLogin(user* username, jceStatusBar *statusBar)
|
jceLogin::jceLogin(user* username, jceStatusBar *statusBar)
|
||||||
{
|
{
|
||||||
this->statusBar = statusBar;
|
this->statusBar = statusBar;
|
||||||
this->recieverPage = new QString();
|
this->recieverPage = new QString();
|
||||||
this->jceA = username;
|
this->jceA = username;
|
||||||
this->JceConnector = new jceSSLClient(statusBar);
|
this->JceConnector = new jceSSLClient(statusBar);
|
||||||
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
|
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
|
||||||
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
|
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
|
||||||
}
|
}
|
||||||
|
|
||||||
jceLogin::~jceLogin()
|
jceLogin::~jceLogin()
|
||||||
{
|
{
|
||||||
this->jceA = NULL;
|
this->jceA = NULL;
|
||||||
delete recieverPage;
|
delete recieverPage;
|
||||||
delete JceConnector;
|
delete JceConnector;
|
||||||
JceConnector = NULL;
|
JceConnector = NULL;
|
||||||
recieverPage = NULL;
|
recieverPage = NULL;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it.
|
* @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it.
|
||||||
|
@ -28,79 +28,79 @@ jceLogin::~jceLogin()
|
||||||
*/
|
*/
|
||||||
int jceLogin::makeConnection()
|
int jceLogin::makeConnection()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "connection to be make";
|
qDebug() << Q_FUNC_INFO << "connection to be make";
|
||||||
|
|
||||||
if (this->recieverPage == NULL)
|
if (this->recieverPage == NULL)
|
||||||
this->recieverPage = new QString();
|
this->recieverPage = new QString();
|
||||||
|
|
||||||
int returnMode; //gets status according to called function of validation step
|
int returnMode; //gets status according to called function of validation step
|
||||||
jceStatus status = jceStatus::JCE_NOT_CONNECTED;
|
jceStatus status = jceStatus::JCE_NOT_CONNECTED;
|
||||||
|
|
||||||
returnMode = checkConnection(); //checking socket status. is connected?
|
returnMode = checkConnection(); //checking socket status. is connected?
|
||||||
|
|
||||||
if (returnMode == (int)false)
|
if (returnMode == (int)false)
|
||||||
{
|
{
|
||||||
statusBar->setIconConnectionStatus(jceStatusBar::Connecting);
|
statusBar->setIconConnectionStatus(jceStatusBar::Connecting);
|
||||||
if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection
|
if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection
|
||||||
return jceStatus::ERROR_ON_OPEN_SOCKET;
|
return jceStatus::ERROR_ON_OPEN_SOCKET;
|
||||||
else
|
else
|
||||||
returnMode = true;
|
returnMode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (returnMode == (int)true) //connected to host
|
if (returnMode == (int)true) //connected to host
|
||||||
{
|
{
|
||||||
statusBar->setIconConnectionStatus(jceStatusBar::Connected);
|
statusBar->setIconConnectionStatus(jceStatusBar::Connected);
|
||||||
returnMode = makeFirstVisit();
|
returnMode = makeFirstVisit();
|
||||||
if (returnMode == (int)true) //requst and send first validation
|
if (returnMode == (int)true) //requst and send first validation
|
||||||
{
|
{
|
||||||
status = jceStatus::JCE_START_VALIDATING_PROGRESS;
|
// status = jceStatus::JCE_START_VALIDATING_PROGRESS;
|
||||||
returnMode = checkValidation();
|
returnMode = checkValidation();
|
||||||
if (returnMode == (int)true) //check if username and password are matching
|
if (returnMode == (int)true) //check if username and password are matching
|
||||||
{
|
{
|
||||||
status = jceStatus::JCE_VALIDATION_PASSED;
|
// status = jceStatus::JCE_VALIDATION_PASSED;
|
||||||
returnMode = makeSecondVisit();
|
returnMode = makeSecondVisit();
|
||||||
if (returnMode == (int)true) //siging in the website
|
if (returnMode == (int)true) //siging in the website
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Signed in succeesfully";
|
qDebug() << Q_FUNC_INFO << "Signed in succeesfully";
|
||||||
status = jceStatus::JCE_YOU_ARE_IN;
|
status = jceStatus::JCE_YOU_ARE_IN;
|
||||||
setLoginFlag(true);
|
setLoginFlag(true);
|
||||||
statusBar->setIconConnectionStatus(jceStatusBar::LoggedIn);
|
statusBar->setIconConnectionStatus(jceStatusBar::LoggedIn);
|
||||||
}
|
}
|
||||||
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
|
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
|
||||||
{
|
{
|
||||||
status = jceLogin::ERROR_ON_GETTING_INFO;
|
status = jceLogin::ERROR_ON_GETTING_INFO;
|
||||||
}
|
}
|
||||||
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
|
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
|
||||||
{
|
{
|
||||||
status = jceLogin::ERROR_ON_SEND_REQUEST;
|
status = jceLogin::ERROR_ON_SEND_REQUEST;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status = jceStatus::ERROR_ON_VALIDATION;
|
status = jceStatus::ERROR_ON_VALIDATION;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status = jceStatus::ERROR_ON_VALIDATION;
|
status = jceStatus::ERROR_ON_VALIDATION;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
|
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
|
||||||
{
|
{
|
||||||
status = jceLogin::ERROR_ON_GETTING_INFO;
|
status = jceLogin::ERROR_ON_GETTING_INFO;
|
||||||
}
|
}
|
||||||
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
|
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
|
||||||
{
|
{
|
||||||
status = jceLogin::ERROR_ON_SEND_REQUEST;
|
status = jceLogin::ERROR_ON_SEND_REQUEST;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
|
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status = jceStatus::JCE_NOT_CONNECTED;
|
status = jceStatus::JCE_NOT_CONNECTED;
|
||||||
|
|
||||||
if (status != jceStatus::JCE_YOU_ARE_IN)
|
if (status != jceStatus::JCE_YOU_ARE_IN)
|
||||||
statusBar->setIconConnectionStatus(jceStatusBar::Error);
|
statusBar->setIconConnectionStatus(jceStatusBar::Error);
|
||||||
//we throw status even if we are IN!
|
//we throw status even if we are IN!
|
||||||
qDebug() << Q_FUNC_INFO << "return status: " << status;
|
qDebug() << Q_FUNC_INFO << "return status: " << status;
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -109,10 +109,10 @@ int jceLogin::makeConnection()
|
||||||
*/
|
*/
|
||||||
bool jceLogin::checkConnection() const
|
bool jceLogin::checkConnection() const
|
||||||
{
|
{
|
||||||
if (JceConnector->isConnected())
|
if (JceConnector->isConnected())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief jceLogin::closeAll
|
* @brief jceLogin::closeAll
|
||||||
|
@ -120,11 +120,11 @@ bool jceLogin::checkConnection() const
|
||||||
void jceLogin::closeAll()
|
void jceLogin::closeAll()
|
||||||
{
|
{
|
||||||
statusBar->setIconConnectionStatus(jceStatusBar::Disconnected);
|
statusBar->setIconConnectionStatus(jceStatusBar::Disconnected);
|
||||||
this->JceConnector->makeDiconnect();
|
this->JceConnector->makeDiconnect();
|
||||||
if ((this->recieverPage != NULL) && (!this->recieverPage->isEmpty()))
|
if ((this->recieverPage != NULL) && (!this->recieverPage->isEmpty()))
|
||||||
{
|
{
|
||||||
delete recieverPage;
|
delete recieverPage;
|
||||||
recieverPage = NULL;
|
recieverPage = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -133,17 +133,17 @@ void jceLogin::closeAll()
|
||||||
*/
|
*/
|
||||||
void jceLogin::reMakeConnection()
|
void jceLogin::reMakeConnection()
|
||||||
{
|
{
|
||||||
if (this->JceConnector != NULL)
|
if (this->JceConnector != NULL)
|
||||||
delete JceConnector;
|
delete JceConnector;
|
||||||
if (this->recieverPage != NULL)
|
if (this->recieverPage != NULL)
|
||||||
delete recieverPage;
|
delete recieverPage;
|
||||||
recieverPage = NULL;
|
recieverPage = NULL;
|
||||||
JceConnector = NULL;
|
JceConnector = NULL;
|
||||||
this->recieverPage = new QString();
|
this->recieverPage = new QString();
|
||||||
this->JceConnector = new jceSSLClient(statusBar);
|
this->JceConnector = new jceSSLClient(statusBar);
|
||||||
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
|
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
|
||||||
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
|
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
|
||||||
emit connectionReadyAfterDisconnection();
|
emit connectionReadyAfterDisconnection();
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -152,15 +152,15 @@ void jceLogin::reMakeConnection()
|
||||||
*/
|
*/
|
||||||
int jceLogin::makeFirstVisit()
|
int jceLogin::makeFirstVisit()
|
||||||
{
|
{
|
||||||
if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
|
if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
|
||||||
{
|
{
|
||||||
if (!JceConnector->recieveData(recieverPage))
|
if (!JceConnector->recieveData(recieverPage))
|
||||||
return jceLogin::ERROR_ON_GETTING_INFO;
|
return jceLogin::ERROR_ON_GETTING_INFO;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief jceLogin::makeSecondVisit making the second validation step of jce student portal login
|
* @brief jceLogin::makeSecondVisit making the second validation step of jce student portal login
|
||||||
|
@ -168,19 +168,19 @@ int jceLogin::makeFirstVisit()
|
||||||
*/
|
*/
|
||||||
int jceLogin::makeSecondVisit()
|
int jceLogin::makeSecondVisit()
|
||||||
{
|
{
|
||||||
QString usrid=jceA->getUserID();
|
QString usrid=jceA->getUserID();
|
||||||
QString pswid=jceA->getHashedPassword();
|
QString pswid=jceA->getHashedPassword();
|
||||||
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
|
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
|
||||||
{
|
{
|
||||||
if (!(JceConnector->recieveData(recieverPage)))
|
if (!(JceConnector->recieveData(recieverPage)))
|
||||||
return jceLogin::ERROR_ON_GETTING_INFO;
|
return jceLogin::ERROR_ON_GETTING_INFO;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief jceLogin::getCalendar according to parameters, we make an HTML request and send it over socket to server
|
* @brief jceLogin::getCalendar according to parameters, we make an HTML request and send it over socket to server
|
||||||
|
@ -190,30 +190,30 @@ int jceLogin::makeSecondVisit()
|
||||||
*/
|
*/
|
||||||
int jceLogin::getCalendar(int year, int semester)
|
int jceLogin::getCalendar(int year, int semester)
|
||||||
{
|
{
|
||||||
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester)))))
|
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester)))))
|
||||||
{
|
{
|
||||||
if (!(JceConnector->recieveData(recieverPage)))
|
if (!(JceConnector->recieveData(recieverPage)))
|
||||||
return jceLogin::ERROR_ON_GETTING_PAGE;
|
return jceLogin::ERROR_ON_GETTING_PAGE;
|
||||||
else
|
else
|
||||||
return jceLogin::JCE_PAGE_PASSED;
|
return jceLogin::JCE_PAGE_PASSED;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
int jceLogin::getExams(int year, int semester)
|
int jceLogin::getExams(int year, int semester)
|
||||||
{
|
{
|
||||||
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getExamSchedule(*jceA,year,semester)))))
|
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getExamSchedule(*jceA,year,semester)))))
|
||||||
{
|
{
|
||||||
if (!(JceConnector->recieveData(recieverPage)))
|
if (!(JceConnector->recieveData(recieverPage)))
|
||||||
return jceLogin::ERROR_ON_GETTING_PAGE;
|
return jceLogin::ERROR_ON_GETTING_PAGE;
|
||||||
else
|
else
|
||||||
return jceLogin::JCE_PAGE_PASSED;
|
return jceLogin::JCE_PAGE_PASSED;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -227,17 +227,17 @@ int jceLogin::getExams(int year, int semester)
|
||||||
*/
|
*/
|
||||||
int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester)
|
int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester)
|
||||||
{
|
{
|
||||||
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
|
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
|
||||||
{
|
{
|
||||||
if (!(JceConnector->recieveData(recieverPage)))
|
if (!(JceConnector->recieveData(recieverPage)))
|
||||||
return jceLogin::ERROR_ON_GETTING_PAGE;
|
return jceLogin::ERROR_ON_GETTING_PAGE;
|
||||||
else
|
else
|
||||||
return jceLogin::JCE_PAGE_PASSED;
|
return jceLogin::JCE_PAGE_PASSED;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -247,43 +247,42 @@ int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemest
|
||||||
bool jceLogin::checkValidation()
|
bool jceLogin::checkValidation()
|
||||||
{
|
{
|
||||||
|
|
||||||
//finds the hashed password
|
//finds the hashed password
|
||||||
QString constUserID_TAG = "value=\"-N";
|
QString constUserID_TAG = "value=\"-N";
|
||||||
QString constHassID_TAG = "-A,-N";
|
QString constHassID_TAG = "-A,-N";
|
||||||
QString hasspass,hassid;
|
QString hasspass,hassid;
|
||||||
std::size_t hasspass_position1,hasspass_position2;
|
int hasspass_position1,hasspass_position2;
|
||||||
std::size_t id_position1,id_position2;
|
int id_position1,id_position2;
|
||||||
|
hasspass_position1 = this->recieverPage->indexOf(constHassID_TAG); //looking for hasspass index
|
||||||
|
if (hasspass_position1 == -1) //didnt find the tag
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
hasspass_position1 += constHassID_TAG.length(); //skip the index of tag
|
||||||
|
hasspass_position2 = this->recieverPage->indexOf(",-A,-A", hasspass_position1);
|
||||||
|
//finds the hass pass
|
||||||
|
if (hasspass_position2 != -1) //found the hasspass! storing it
|
||||||
|
hasspass = recieverPage->mid(hasspass_position1,hasspass_position2-hasspass_position1);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
//finds the user id
|
||||||
|
id_position1 = this->recieverPage->indexOf(constUserID_TAG, 0); //looking for hassid index
|
||||||
|
if (id_position1 == -1) //didnt find the tag
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
id_position1 += constUserID_TAG.length(); //skip the index of tag
|
||||||
|
id_position2 = this->recieverPage->indexOf(",-A", id_position1);
|
||||||
|
if (id_position2 != -1) //found the hassid! storing it
|
||||||
|
hassid = recieverPage->mid(id_position1,id_position2-id_position1);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
hasspass_position1 = this->recieverPage->toStdString().find(constHassID_TAG.toStdString()); //looking for hasspass index
|
//setting user information with given data hassid and hasspass
|
||||||
if (hasspass_position1 == std::string::npos) //didnt find the tag
|
jceA->setHashedPassword(hasspass);
|
||||||
return false;
|
jceA->setUserID(hassid);
|
||||||
else
|
|
||||||
hasspass_position1 += constHassID_TAG.length(); //skip the index of tag
|
|
||||||
hasspass_position2 = this->recieverPage->toStdString().find(",-A,-A", hasspass_position1);
|
|
||||||
//finds the hass pass
|
|
||||||
if (hasspass_position2 != std::string::npos) //found the hasspass! storing it
|
|
||||||
hasspass = recieverPage->mid(hasspass_position1,hasspass_position2-hasspass_position1);
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
//finds the user id
|
|
||||||
id_position1 = this->recieverPage->toStdString().find(constUserID_TAG.toStdString(), 0); //looking for hassid index
|
|
||||||
if (id_position1 == std::string::npos) //didnt find the tag
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
id_position1 += constUserID_TAG.length(); //skip the index of tag
|
|
||||||
id_position2 = this->recieverPage->toStdString().find(",-A", id_position1);
|
|
||||||
if (id_position2 != std::string::npos) //found the hassid! storing it
|
|
||||||
hassid = recieverPage->mid(id_position1,id_position2-id_position1);
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
//setting user information with given data hassid and hasspass
|
qDebug() << "jceLogin::checkValidation(); Found Hashed: " << hasspass << "And ID: " << hassid;
|
||||||
jceA->setHashedPassword(hasspass);
|
|
||||||
jceA->setUserID(hassid);
|
|
||||||
|
|
||||||
qDebug() << "jceLogin::checkValidation(); Found Hashed: " << hasspass << "And ID: " << hassid;
|
return true;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief jceLogin::setLoginFlag
|
* @brief jceLogin::setLoginFlag
|
||||||
|
@ -291,7 +290,7 @@ bool jceLogin::checkValidation()
|
||||||
*/
|
*/
|
||||||
void jceLogin::setLoginFlag(bool x)
|
void jceLogin::setLoginFlag(bool x)
|
||||||
{
|
{
|
||||||
this->loginFlag = x;
|
this->loginFlag = x;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief jceLogin::isLoginFlag checking if there is a connection, if true - > return if we signed in. otherwise, return not (not connected dough)
|
* @brief jceLogin::isLoginFlag checking if there is a connection, if true - > return if we signed in. otherwise, return not (not connected dough)
|
||||||
|
@ -299,9 +298,9 @@ void jceLogin::setLoginFlag(bool x)
|
||||||
*/
|
*/
|
||||||
bool jceLogin::isLoginFlag() const
|
bool jceLogin::isLoginFlag() const
|
||||||
{
|
{
|
||||||
if (checkConnection())
|
if (checkConnection())
|
||||||
return this->loginFlag;
|
return this->loginFlag;
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -310,30 +309,30 @@ bool jceLogin::isLoginFlag() const
|
||||||
*/
|
*/
|
||||||
QString jceLogin::getPage()
|
QString jceLogin::getPage()
|
||||||
{
|
{
|
||||||
return *recieverPage;
|
return *recieverPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void jceLogin::reValidation()
|
void jceLogin::reValidation()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Revalidating user";
|
qDebug() << Q_FUNC_INFO << "Revalidating user";
|
||||||
|
|
||||||
if (makeFirstVisit() == (int)true)
|
if (makeFirstVisit() == (int)true)
|
||||||
{
|
{
|
||||||
if (checkValidation())
|
if (checkValidation())
|
||||||
{
|
{
|
||||||
if (makeSecondVisit() == (int)true)
|
if (makeSecondVisit() == (int)true)
|
||||||
{
|
{
|
||||||
statusBar->setIconConnectionStatus(jceStatusBar::LoggedIn);
|
statusBar->setIconConnectionStatus(jceStatusBar::LoggedIn);
|
||||||
qDebug() << Q_FUNC_INFO << "Validated";
|
qDebug() << Q_FUNC_INFO << "Validated";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
qWarning() << Q_FUNC_INFO << "Second visit finished with an error";
|
qWarning() << Q_FUNC_INFO << "Second visit finished with an error";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
qDebug() << Q_FUNC_INFO << "checking validation ended with an error";
|
qDebug() << Q_FUNC_INFO << "checking validation ended with an error";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Couldnt Validate User";
|
qDebug() << Q_FUNC_INFO << "Couldnt Validate User";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue