hkuadmin continue

This commit is contained in:
fasiondog 2021-04-30 01:47:34 +08:00
parent ddc08c1220
commit 77a42f5551
11 changed files with 1893 additions and 1852 deletions

View File

@ -109,7 +109,7 @@ class MyMainWindow(QtWidgets.QMainWindow):
def initAction(self):
self.action_dict = dict(
action_file_session=QtWidgets.QAction(
QtGui.QIcon(":/icon/server.png"), _translate("MainWindow", "&Session"), self
QtGui.QIcon(":/icon/server_32.png"), _translate("MainWindow", "&Session"), self
),
action_file_quit=QtWidgets.QAction(QtGui.QIcon(":/icon/quit.png"), _translate('MainWindow', '&Quit'), self),
action_view_normal_style=QtWidgets.QAction(_translate('MainWindow', 'Normal style'), self),

View File

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from .assist import getServerStatus
from .user import login

View File

@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
import requests
from .config import getServerApiUrl, defaultRequestHeader
def getServerStatus(host, token):
url = getServerApiUrl(host, "assist", "status")
headers = defaultRequestHeader()
headers["hku_token"] = token
return requests.get(url, headers=headers)

View File

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
server_api_config = {"protocol": "http", "prefix": "hku", "version": "v1"}
def getServerApiUrl(host_url, service, api):
return "{}://{}/{}/{}/{}/{}".format(
server_api_config["protocol"], host_url, server_api_config["prefix"], service, server_api_config["version"], api
)
def defaultRequestHeader():
return {
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0",
"Accept-Encoding": "gzip, deflate, br"
}

View File

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
import requests
from .config import getServerApiUrl, defaultRequestHeader
def login(host: str, user: str, password: str):
url = getServerApiUrl(host, "user", "login")
headers = defaultRequestHeader()
return requests.post(url, headers=headers, json={"user": user, "password": password})
if __name__ == "__main__":
r = login("http://127.0.0.1:9001", "1", "1")
print(r.status_code)
print(r.json())

View File

@ -3,19 +3,46 @@
import sys
sys.path.append("..")
import resource
import ServerApi
import sqlalchemy
from PyQt5 import QtWidgets, QtCore, QtGui
from .Ui_HkuEditSessionDialog import Ui_HkuEditSessionDialog
_translate = QtCore.QCoreApplication.translate
class HkuEditSessionDialog(QtWidgets.QDialog, Ui_HkuEditSessionDialog):
def __init__(self, parent):
super(HkuEditSessionDialog, self).__init__(parent)
self.setWindowIcon(QtGui.QIcon(":/icon/server.png"))
self.setWindowIcon(QtGui.QIcon(":/icon/server_16.png"))
self.setupUi(self)
self.session_model = None
@property
def name(self):
return self.name_lineEdit.text().strip()
@property
def host(self):
return self.host_lineEdit.text().strip()
@property
def port(self):
return self.port_spinBox.value()
@property
def user(self):
return self.user_lineEdit.text().strip()
@property
def password(self):
return self.password_lineEdit.text().strip()
@property
def remark(self):
return self.remark_textEdit.toPlainText()
def setData(self, session_model):
self.session_model = session_model
self.name_lineEdit.setText(session_model.name)
@ -26,7 +53,6 @@ class HkuEditSessionDialog(QtWidgets.QDialog, Ui_HkuEditSessionDialog):
self.remark_textEdit.setText(session_model.remark)
def accept(self):
_translate = QtCore.QCoreApplication.translate
name = self.name_lineEdit.text().strip()
if len(name) == 0:
QtWidgets.QMessageBox.warning(
@ -42,7 +68,6 @@ class HkuEditSessionDialog(QtWidgets.QDialog, Ui_HkuEditSessionDialog):
self.session_model.remark = self.remark_textEdit.toPlainText()
session = self.parent().session
try:
print(self.parent())
session.add(self.session_model)
session.commit()
except sqlalchemy.exc.IntegrityError as e:
@ -63,7 +88,25 @@ class HkuEditSessionDialog(QtWidgets.QDialog, Ui_HkuEditSessionDialog):
@QtCore.pyqtSlot()
def on_test_pushButton_clicked(self):
print("jjjj")
try:
r = ServerApi.login(
"{}:{}".format(self.host_lineEdit.text().strip(), self.port_spinBox.value()), self.user_lineEdit.text(),
self.password_lineEdit.text()
)
if r.status_code == 200:
QtWidgets.QMessageBox.about(
self, _translate("HkuEditSessionDialog", "success"),
_translate("HkuEditSessionDialog", "Connect successfully!")
)
elif r.status_code == 400:
ret = r.json()
QtWidgets.QMessageBox.about(self, _translate("HkuEditSessionDialog", "Failed"), ret["errmsg"])
except Exception as e:
QtWidgets.QMessageBox.about(
self, _translate("HkuEditSessionDialog", "Failed"),
_translate("HkuEditSessionDialog", "Failed connect! Please check the host/ip and port\n%s") % e
)
@QtCore.pyqtSlot()
def on_remark_textEdit_textChanged(self):

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 B

View File

@ -7,6 +7,7 @@
<file>logo/logo_128.png</file>
<file>logo/logo_256.png</file>
<file>icon/quit.png</file>
<file>icon/server.png</file>
<file>icon/server_16.png</file>
<file>icon/server_32.png</file>
</qresource>
</RCC>

View File

@ -42,7 +42,7 @@ public:
: HttpException(NNG_HTTP_STATUS_BAD_REQUEST, msg), m_errcode(errcode) {}
virtual std::string msg() const noexcept override {
return fmt::format(R"({{"errcode": {}, "errmsg": "{}"}})", m_errcode, what());
return fmt::format(R"({{"result": false,"errcode":{}, "errmsg":"{}"}})", m_errcode, what());
}
int errcode() const noexcept {