|
@@ -1,6 +1,20 @@
|
|
#include "mainwindowadminuser.h"
|
|
#include "mainwindowadminuser.h"
|
|
#include "ui_mainwindowadminuser.h"
|
|
#include "ui_mainwindowadminuser.h"
|
|
|
|
|
|
|
|
+#include <QMessageBox>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#include "grpcfwclient.h"
|
|
|
|
+
|
|
|
|
+#include "mainwindow.h"
|
|
|
|
+#include "mainwindowlogin.h"
|
|
|
|
+#include "mainwindowadminuser.h"
|
|
|
|
+
|
|
|
|
+extern MainWindow * gwmain;
|
|
|
|
+extern MainWindowLogin * gwlogin;
|
|
|
|
+extern MainWindowAdminUser * gwadminuser;
|
|
|
|
+extern grpcfwclient * gpgrpcfwclient;
|
|
|
|
+
|
|
MainWindowAdminUser::MainWindowAdminUser(QWidget *parent) :
|
|
MainWindowAdminUser::MainWindowAdminUser(QWidget *parent) :
|
|
QMainWindow(parent),
|
|
QMainWindow(parent),
|
|
ui(new Ui::MainWindowAdminUser)
|
|
ui(new Ui::MainWindowAdminUser)
|
|
@@ -14,3 +28,112 @@ MainWindowAdminUser::~MainWindowAdminUser()
|
|
{
|
|
{
|
|
delete ui;
|
|
delete ui;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+void MainWindowAdminUser::on_pushButton_clicked()
|
|
|
|
+{
|
|
|
|
+ std::string struser = ui->lineEdit_UserName->text().toStdString();
|
|
|
|
+ if(struser.length()<1)
|
|
|
|
+ {
|
|
|
|
+ QMessageBox::warning(this,tr("Warning"),tr("User Name is Empty."),QMessageBox::YesAll);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ iv::fw::adminreq xadminreq;
|
|
|
|
+ xadminreq.set_admintype(iv::fw::ADMINREQ_TYPE::QUERYUSER);
|
|
|
|
+ xadminreq.set_username(struser);
|
|
|
|
+ xadminreq.set_password(struser);
|
|
|
|
+
|
|
|
|
+ iv::queryrpcReq xreq;
|
|
|
|
+ xreq.set_ntype(iv::CommonRPCType::USERADMIN);
|
|
|
|
+ int ndatasize = xadminreq.ByteSize();
|
|
|
|
+ xreq.set_ndatasize(ndatasize);
|
|
|
|
+ std::shared_ptr<char> pstr_ptr = std::shared_ptr<char>(new char[ndatasize]);
|
|
|
|
+ if(xadminreq.SerializeToArray(pstr_ptr.get(),ndatasize))
|
|
|
|
+ {
|
|
|
|
+ xreq.set_data(pstr_ptr.get(),ndatasize);
|
|
|
|
+
|
|
|
|
+ mpthread = new std::thread(&MainWindowAdminUser::threadadmin,this,xreq);
|
|
|
|
+ DisableAllButton();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ QMessageBox::warning(this,tr("Warning"),tr("admin serialize fail."),QMessageBox::YesAll);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindowAdminUser::threadadmin(iv::queryrpcReq xreq)
|
|
|
|
+{
|
|
|
|
+ int i;
|
|
|
|
+ for(i=0;i<3;i++)
|
|
|
|
+ {
|
|
|
|
+ int nreq = gpgrpcfwclient->SetReq(xreq);
|
|
|
|
+ if(nreq == 0)
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"MainWindowAdminUser::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 adminstate(0,"can't connect to server");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if(xReply.ntype() == iv::CommonRPCType::USERADMIN)
|
|
|
|
+ {
|
|
|
|
+ iv::fw::adminreply xAdminReply;
|
|
|
|
+ if(xAdminReply.ParseFromArray(xReply.data().data(),xReply.ndatasize()))
|
|
|
|
+ {
|
|
|
|
+ if(xAdminReply.nresult() == 0)
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"error code: "<<xAdminReply.errstr()<<std::endl;
|
|
|
|
+ strncpy(mstrlasterr,xAdminReply.errstr().data(),256);
|
|
|
|
+ emit adminstate(0,mstrlasterr);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ emit adminstate(1,"Success.");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ emit adminstate(0,"Parse Reply Fail.");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ emit adminstate(0,"admin fail.");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindowAdminUser::DisableAllButton()
|
|
|
|
+{
|
|
|
|
+ ui->pushButton->setEnabled(false);
|
|
|
|
+ ui->pushButton_Disable->setEnabled(false);
|
|
|
|
+ ui->pushButton_Enable->setEnabled(false);
|
|
|
|
+ ui->pushButton_Query->setEnabled(false);
|
|
|
|
+ ui->pushButton_ResetPass->setEnabled(false);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindowAdminUser::EnableAllButton()
|
|
|
|
+{
|
|
|
|
+ ui->pushButton->setEnabled(true);
|
|
|
|
+ ui->pushButton_Disable->setEnabled(true);
|
|
|
|
+ ui->pushButton_Enable->setEnabled(true);
|
|
|
|
+ ui->pushButton_Query->setEnabled(true);
|
|
|
|
+ ui->pushButton_ResetPass->setEnabled(true);
|
|
|
|
+}
|
|
|
|
+
|