changePassword.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from PyQt6.QtWidgets import QWidget , QMessageBox
  2. from UI.changePassword import Ui_FormChangePssword
  3. from .LogerinTxt import app_logger
  4. from Functions.apiFunction import api_fc
  5. class changePassword(Ui_FormChangePssword, QWidget):
  6. def __init__(self, parent=None):
  7. super().__init__(parent)
  8. try:
  9. self.setupUi(self)
  10. self.ipinfo = None
  11. self.pushButton.clicked.connect(self.btn)
  12. self.user = None
  13. except Exception as e:
  14. app_logger.log_error(e)
  15. def severpost_meassge(self, postname, **kwargs):
  16. try:
  17. # ip = "http://" + str(self.ipinfo) + "/static/" + str(postname) + str(postdata) + str(postdata2)
  18. # res = requests.get(url=ip, timeout=30).json()
  19. res = api_fc.request_post('/static/{}'.format(postname), **kwargs)
  20. return res
  21. except Exception as e:
  22. # print('登录服务器失败')
  23. QMessageBox.warning(self, "提示", "服务器连接超时,请联系管理员检查服务器!")
  24. app_logger.log_error(e)
  25. return ''
  26. def severpost_data(self, postname, data: dict):
  27. try:
  28. # ip = "http://" + str(self.ipinfo) + "/static/" + str(postname)
  29. # data = json.dumps(data)
  30. # res = requests.post(url=ip, data=data, timeout=30).json()
  31. res = api_fc.request_post('/static/{}'.format(postname), data=data)
  32. return res
  33. except Exception as e:
  34. QMessageBox.warning(self, "提示", "服务器连接超时,请联系管理员检查服务器!")
  35. app_logger.log_error(e)
  36. return 'fail'
  37. def btn(self):
  38. try:
  39. oldpassword = self.lineEditold.text()
  40. newpassword = self.lineEditnew.text()
  41. newpassword2 = self.lineEditnew2.text()
  42. #res = self.severpost_meassge("loginTable",username="/%s" % self.user,password="/%s" % oldpassword)["data"]["返回值"]
  43. res =api_fc.request_post_without_token("/loginTable",username=self.user,password=oldpassword)["data"]["返回值"]
  44. # print(res)
  45. if res != "":
  46. if newpassword == newpassword2:
  47. dataDic = {'登录名': self.user, '新密码': newpassword, "旧密码": oldpassword}
  48. res = self.severpost_data("changePassword", dataDic)
  49. if res["返回值"] == "ok":
  50. self.close()
  51. QMessageBox.warning(self, "提示", "密码修改成功!!!")
  52. else:
  53. QMessageBox.warning(self, "提示", "密码修改失败,请检查服务器连接状态或联系管理员!!!")
  54. else:
  55. QMessageBox.warning(self, "警告", "两次密码输入不同!!!")
  56. else:
  57. QMessageBox.warning(self, "警告", "原密码错误!!!")
  58. except Exception as e:
  59. app_logger.log_error(e)