|
@@ -3,11 +3,15 @@
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
+#include "grpcfwclient.h"
|
|
|
#include "mainwindow.h"
|
|
|
#include "mainwindowlogin.h"
|
|
|
|
|
|
+#include "fwlogin.pb.h"
|
|
|
+
|
|
|
extern MainWindow * gwmain;
|
|
|
extern MainWindowLogin * gwlogin;
|
|
|
+extern grpcfwclient * gpgrpcfwclient;
|
|
|
|
|
|
MainWindowLogin::MainWindowLogin(QWidget *parent) :
|
|
|
QMainWindow(parent),
|
|
@@ -27,11 +31,9 @@ MainWindowLogin::MainWindowLogin(QWidget *parent) :
|
|
|
"QCheckBox::indicator {width: 20px;height: 20px;border: none;image: url(:/no_display.png);}"
|
|
|
"QCheckBox::indicator:checked {image: url(:/display.png);}");
|
|
|
|
|
|
-// mpcheckdisplay->setGeometry(ui->lineEdit_password->pos().x() + 100,ui->lineEdit_password->pos().y() + 4,20,20);
|
|
|
-
|
|
|
mpcheckdisplay->setGeometry(ui->lineEdit_password->size().width() - 30, (ui->lineEdit_password->size().height() -20)/2,20,20);
|
|
|
|
|
|
- connect(this,SIGNAL(loginstate(int,char *)),this,SLOT(onloginstate(int,char *)));
|
|
|
+ connect(this,SIGNAL(loginstate(int,const char *)),this,SLOT(onloginstate(int,const char *)));
|
|
|
|
|
|
setWindowTitle("Login");
|
|
|
}
|
|
@@ -43,10 +45,44 @@ MainWindowLogin::~MainWindowLogin()
|
|
|
|
|
|
void MainWindowLogin::on_pushButton_Login_clicked()
|
|
|
{
|
|
|
- ui->pushButton_Login->setText("Loging....");
|
|
|
- ui->pushButton_Login->setEnabled(false);
|
|
|
|
|
|
- mpthread = new std::thread(&MainWindowLogin::threadlogin,this);
|
|
|
+ if(ui->lineEdit_username->text().length()<1)
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,tr("Warning"),tr("username empty."),QMessageBox::YesAll);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ui->lineEdit_password->text().length()<1)
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,tr("Waring"),tr("password empty."),QMessageBox::YesAll);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ iv::fw::loginreq xlogin;
|
|
|
+ xlogin.set_username(ui->lineEdit_username->text().toStdString());
|
|
|
+ xlogin.set_password(ui->lineEdit_password->text().toStdString());
|
|
|
+
|
|
|
+ iv::queryrpcReq xreq;
|
|
|
+ xreq.set_ntype(iv::CommonRPCType::LOGIN);
|
|
|
+ int ndatasize = xlogin.ByteSize();
|
|
|
+ xreq.set_ndatasize(ndatasize);
|
|
|
+ std::shared_ptr<char> pstr_ptr = std::shared_ptr<char>(new char[ndatasize]);
|
|
|
+ if(xlogin.SerializeToArray(pstr_ptr.get(),ndatasize))
|
|
|
+ {
|
|
|
+ xreq.set_data(pstr_ptr.get(),ndatasize);
|
|
|
+ ui->pushButton_Login->setText("Loging....");
|
|
|
+ ui->pushButton_Login->setEnabled(false);
|
|
|
+
|
|
|
+ mpthread = new std::thread(&MainWindowLogin::threadlogin,this,xreq);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,tr("Warning"),tr("logingreq serialize fail."),QMessageBox::YesAll);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
// this->hide();
|
|
|
// gwmain->show();
|
|
@@ -62,7 +98,7 @@ void MainWindowLogin::slot_checkbox_state_changed(int state)
|
|
|
|
|
|
}
|
|
|
|
|
|
-void MainWindowLogin::onloginstate(int nstate, char * strerr)
|
|
|
+void MainWindowLogin::onloginstate(int nstate, const char * strerr)
|
|
|
{
|
|
|
if(nstate == 1)
|
|
|
{
|
|
@@ -80,8 +116,55 @@ void MainWindowLogin::onloginstate(int nstate, char * strerr)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void MainWindowLogin::threadlogin()
|
|
|
+void MainWindowLogin::threadlogin(iv::queryrpcReq xreq)
|
|
|
{
|
|
|
- std::this_thread::sleep_for(std::chrono::milliseconds(3000));
|
|
|
- emit loginstate(0,"password error");
|
|
|
+ int i;
|
|
|
+ for(i=0;i<3;i++)
|
|
|
+ {
|
|
|
+ int nreq = gpgrpcfwclient->SetReq(xreq);
|
|
|
+ if(nreq == 0)
|
|
|
+ {
|
|
|
+ std::cout<<"MainWindowLogin::threadlogin setreq fail."<<std::endl;
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ iv::queryrpcReply xReply;
|
|
|
+ int nreply = gpgrpcfwclient->GetReply(xReply);
|
|
|
+ while(nreply == 0)
|
|
|
+ {
|
|
|
+ nreply = gpgrpcfwclient->GetReply(xReply);
|
|
|
+ }
|
|
|
+ if(nreply<0)
|
|
|
+ {
|
|
|
+ emit loginstate(0,"can't connect to server");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(xReply.ntype() == iv::CommonRPCType::LOGIN)
|
|
|
+ {
|
|
|
+ iv::fw::loginreply xLoginReply;
|
|
|
+ if(xLoginReply.ParseFromArray(xReply.data().data(),xReply.ndatasize()))
|
|
|
+ {
|
|
|
+ if(xLoginReply.nauth() == 0)
|
|
|
+ {
|
|
|
+ emit loginstate(0,xLoginReply.errstr().data());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ emit loginstate(1,"Login Success.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ emit loginstate(0,"Parse Reply Fail.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ emit loginstate(0,"login fail.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
}
|