
from PyQt6.QtWidgets import QWidget , QMessageBox

from UI.amroLogin import Ui_amroLogin
from .LogerinTxt import app_logger
from Functions.apiFunction import api_fc


class amroLoginWidget(Ui_amroLogin, QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        try:
            self.setupUi(self)
            self.pushButton.clicked.connect(self.btn)
            self.ipinfo = None
        except Exception as e:
            app_logger.log_error(e)

    def btn(self):
        try:
            username = self.lineEditUsername.text()
            password = self.lineEditPassword.text()
            # ip = "http://" + str(self.ipinfo) + "/static/remotelogin/%s/%s" % (username, password)
            try:
                # res = requests.get(url=ip, timeout=60)
                res = api_fc.request_post('/static/remotelogin', username=username, password=password)
                #print('amro login res:{}'.format(res))
                if res['status'] == "ok":
                    QMessageBox.warning(self, "提示", "服务器AMRO登录成功！")
                    self.close()
                else:
                    QMessageBox.warning(self, "提示", "服务器AMRO登录失败，请检查账号密码或服务器端登录或联系管理员检查服务器！")
            except:
                QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                self.close()
        except Exception as e:
            app_logger.log_error(e)