fixed bugs, added option to keep login

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

View file

@ -10,7 +10,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = jceGrade
TEMPLATE = app
RC_FILE = appConfigure.rc
CONFIG += c++11 static console
CONFIG += c++11 static
SOURCES += main/coursestablemanager.cpp \
main/loginhandler.cpp \

View file

@ -1,6 +1,10 @@
#include "loginhandler.h"
loginHandler::loginHandler(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr)
loginHandler::loginHandler()
{
}
void loginHandler::setPointers(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr)
{
this->jceLog = ptr;
this->statusLabelPtr = statusLabelPtr;
@ -11,9 +15,8 @@ loginHandler::loginHandler(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdE
bool loginHandler::makeConnection()
{
if (this->jceLog == NULL)
{
return false;
}
try
{
jceLog->makeConnection();
@ -38,15 +41,12 @@ bool loginHandler::makeConnection()
}
else if (a == jceLogin::ERROR_ON_OPEN_SOCKET)
{
popMessage("Please check your internet status");
popMessage("Please check your Internet status");
jceLog->closeAll();
return false;
}
else if (a == jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED)
{
std::cout << "error!!!!!!" << (jceLog->getPage()) << std::endl;
popMessage("You were blocked, please wait couple of minutes or contact JCE");
jceLog->closeAll();

View file

@ -7,11 +7,13 @@
#include <QPixmap>
#include "src/jce/jcelogin.h"
#include "./src/data/savedata.h"
class loginHandler
{
public:
loginHandler(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr);
loginHandler();
void setPointers(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr);
bool makeConnection();
private:

View file

@ -31,16 +31,25 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
this->jceLog = NULL;
this->userLoginSetting = new user("","");
this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting);
this->loginHandel = new loginHandler();
updateDates();
//check login File
SaveData::init();
if (SaveData::isSaved())
{
ui->usrnmLineEdit->setText(SaveData::getUsername());
ui->pswdLineEdit->setText(SaveData::getPassword());
ui->keepLogin->setChecked(true);
}
}
MainScreen::~MainScreen()
{
delete userLoginSetting;
delete jceLog;
delete loginHandel;
delete ui;
}
void MainScreen::on_ratesButton_clicked()
@ -163,7 +172,7 @@ void MainScreen::uiSetDisconnectMode()
return;
}
void MainScreen::uiSetConnectMode()
void MainScreen::uiSetConnectMode() //fix before distrbute
{
std::string page;
@ -196,7 +205,7 @@ void MainScreen::uiSetConnectMode()
ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page));
jceLog = new jceLogin(userLoginSetting);
this->loginHandel = new loginHandler(jceLog,statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit);
this->loginHandel->setPointers(jceLog,statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit);
if (loginHandel->makeConnection() == true)
{
@ -266,3 +275,12 @@ void MainScreen::on_actionExit_triggered()
exit(0);
}
void MainScreen::on_keepLogin_clicked()
{
if (ui->keepLogin->isChecked())
SaveData::save(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text());
else
SaveData::deleteData();
}

View file

@ -55,6 +55,8 @@ private slots:
void on_coursesTable_itemChanged(QTableWidgetItem *item);
void on_keepLogin_clicked();
private:
void updateDates();

View file

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>855</width>
<height>636</height>
<height>649</height>
</rect>
</property>
<property name="sizePolicy">
@ -169,20 +169,14 @@ font-size: 15px;
<property name="bottomMargin">
<number>15</number>
</property>
<item row="1" column="0">
<item row="2" column="0">
<layout class="QHBoxLayout" name="loginButtonHorizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QCheckBox" name="keepLogin">
<property name="text">
<string>Keep login</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</widget>
</item>
<item>
<widget class="QPushButton" name="loginButton">
@ -442,7 +436,7 @@ font-size: 15px;
<x>20</x>
<y>20</y>
<width>251</width>
<height>141</height>
<height>159</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_7">
@ -593,6 +587,9 @@ font-size: 15px;
<property name="readOnly">
<bool>false</bool>
</property>
<property name="showGroupSeparator" stdset="0">
<bool>false</bool>
</property>
<property name="minimum">
<number>2009</number>
</property>
@ -602,9 +599,6 @@ font-size: 15px;
<property name="value">
<number>2009</number>
</property>
<property name="showGroupSeparator" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
@ -684,7 +678,7 @@ font-size: 15px;
<x>0</x>
<y>0</y>
<width>855</width>
<height>21</height>
<height>29</height>
</rect>
</property>
<widget class="QMenu" name="menuA_about">

View file

@ -1,37 +1,66 @@
#include "qtsslsocket.h"
qtsslsocket::qtsslsocket(std::string server,int port) : flag(false)
bool qtsslsocket::makeConnect(std::string server,int port)
{
if (this->socket != NULL) //already connected?
{
socket->close();
socket = NULL;
}
if (this->socket == NULL) //if was connected, we deleted it and remake it
socket = new QSslSocket();
if (this->socket != NULL) //now we will connect it to host
{
socket->connectToHostEncrypted(server.c_str(), port);
if (socket->waitForEncrypted()) //waiting for encryption
flag = true;
}
return isCon(); //return true/false upon isCon function
}
qtsslsocket::qtsslsocket() : flag(false)
{
socket = new QSslSocket();
socket->connectToHostEncrypted(server.c_str(), port);
if (socket->waitForEncrypted())
flag = true;
}
qtsslsocket::~qtsslsocket() {
socket->close();
socket = NULL;
}
bool qtsslsocket::isCon()
{
return flag;
return ((flag) && (this->socket != NULL));
}
//need to fix the method
bool qtsslsocket::send(std::string str)
{
int status;
bool flag = isCon();
if (flag)
this->socket->write(str.c_str());
if (flag) //if connected
{
status = socket->write(str.c_str(),str.length());
while (socket->waitForBytesWritten());
}
return flag;
}
bool qtsslsocket::recieve(std::string &str)
{
bool flag = false;
QString s = "";
while (socket->waitForReadyRead(milisTimeOut))
s.append((socket->readAll().data()));
s.append(socket->readAll());
str = s.toStdString();
if (s.size() > 0)
flag = true;
return flag;
}

View file

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

View file

@ -4,7 +4,7 @@ jceLogin::jceLogin(user * username)
{
this->recieverPage = new std::string();
this->jceA = username;
this->JceConnector = new qtsslsocket(dst_host, dst_port);
this->JceConnector = new qtsslsocket();
}
jceLogin::~jceLogin()
@ -21,24 +21,21 @@ jceLogin::~jceLogin()
*/
void jceLogin::makeConnection() throw (jceStatus)
{
if (JceConnector->makeConnect(dst_host,dst_port) == false)
throw jceStatus::ERROR_ON_OPEN_SOCKET;
jceStatus status = jceStatus::JCE_NOT_CONNECTED;
if (checkConnection() == true) //connected to host
{
if (makeFirstVisit() == true) //requst and send first validation
{
std::cout << "visit 1\n";
std::cout << *(this->recieverPage);
status = jceStatus::JCE_FIRST_VALIDATION_PASSED;
if (checkValidation() == true) //check if username and password are matching
{
std::cout << "visit 2\n";
std::cout << *(this->recieverPage);
status = jceStatus::JCE_SECOND_VALIDATION_PASSED;
if (makeSecondVisit() == true) //siging in the website
{
std::cout << "visit 3\n";
std::cout << *(this->recieverPage);
status = jceStatus::JCE_YOU_ARE_IN;
setLoginFlag(true);
}
@ -72,8 +69,10 @@ bool jceLogin::checkConnection()
void jceLogin::reConnect() throw (jceStatus)
{
closeAll();
if (this->JceConnector != NULL)
delete JceConnector;
this->recieverPage = new std::string();
this->JceConnector = new qtsslsocket(dst_host, dst_port);
this->JceConnector = new qtsslsocket();
try
{
makeConnection();
@ -161,8 +160,6 @@ std::string jceLogin::getPage()
bool jceLogin::checkValidation()
{
//finds the hashed password
std::cout << *recieverPage << std::endl;
std::size_t hasspass_position1 = recieverPage->find("-A,-N");
hasspass_position1 += 5;
std::size_t hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1);