clEditPassword.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "clEditPassword.h"
  2. #include "ui_clEditPassword.h"
  3. #include <QValidator>
  4. #include "CAppInfo.h"
  5. #include "logproc.h"
  6. #include "awMsgBox.h"
  7. #include <QRegExpValidator>
  8. #include <QRegExp>
  9. clEditPassword::clEditPassword(QWidget *parent) :
  10. QWidget(parent),
  11. ui(new Ui::clEditPassword)
  12. {
  13. ui->setupUi(this);
  14. setStyleSheet(g_appInfoPtr->m_sQssStr);
  15. qRegisterMetaType<CEditPassword>("CEditPassword");
  16. connect(g_httpBllPtr.get(), &CHttpBll::sgnEditPassword, this, &clEditPassword::onEditPassword);
  17. }
  18. clEditPassword::~clEditPassword()
  19. {
  20. awMsgBox::clear(this);
  21. delete ui;
  22. }
  23. void clEditPassword::setUI(const int nWidth, const int nHeight)
  24. {
  25. setGeometry(0, 0, nWidth, nHeight);
  26. QRegExp regx("[a-zA-Z0-9]{6,18}");
  27. ui->edt_oldPassword->setGeometry(g_appInfoPtr->m_fRate*30, g_appInfoPtr->m_fRate*30,
  28. g_appInfoPtr->m_fRate*360, g_appInfoPtr->m_fRate*40);
  29. QValidator *validator = new QRegExpValidator(regx, ui->edt_newPassword);
  30. ui->edt_newPassword->setValidator(validator);
  31. ui->edt_newPassword->setGeometry(ui->edt_oldPassword->x(), ui->edt_oldPassword->y() + ui->edt_oldPassword->height() + g_appInfoPtr->m_fRate*20,
  32. ui->edt_oldPassword->width(), ui->edt_oldPassword->height());
  33. QValidator *validator1 = new QRegExpValidator(regx, ui->edt_newPassword1);
  34. ui->edt_newPassword1->setValidator(validator1);
  35. ui->edt_newPassword1->setGeometry(ui->edt_oldPassword->x(), ui->edt_newPassword->y() + ui->edt_newPassword->height() + g_appInfoPtr->m_fRate*20,
  36. ui->edt_oldPassword->width(), ui->edt_oldPassword->height());
  37. ui->btn_savePassword->setGeometry(ui->edt_oldPassword->x(), ui->edt_newPassword1->y() + ui->edt_newPassword1->height() + g_appInfoPtr->m_fRate*20,
  38. g_appInfoPtr->m_fRate*80, g_appInfoPtr->m_fRate*36);
  39. }
  40. void clEditPassword::on_btn_savePassword_clicked()
  41. {
  42. if (ui->edt_oldPassword->text().isEmpty())
  43. {
  44. ShowMsg(QString::fromLocal8Bit("请先输入原始密码"), this, MSG_ICON_TYPE::mit_error);
  45. return;
  46. }
  47. if (ui->edt_newPassword->text() != ui->edt_newPassword1->text())
  48. {
  49. ShowMsg(QString::fromLocal8Bit("两次输入密码不一致"), this, MSG_ICON_TYPE::mit_error);
  50. return;
  51. }
  52. if(ui->edt_newPassword->text().length() < 6 ||
  53. ui->edt_newPassword->text().length() > 18)
  54. {
  55. ShowMsg(QString::fromLocal8Bit("请输入6到18位数字或字母"), this, MSG_ICON_TYPE::mit_error);
  56. return;
  57. }
  58. CHttpRequestPackage hrp;
  59. hrp.sUri = "/api/ecs_core/student/password";
  60. hrp.nRequestType = RequestType::rtEditPassword;
  61. hrp.eParamType = HttpParamType::hptUrl;
  62. hrp.sParamList.push_back(QString("newPassword,%1").arg(ui->edt_newPassword->text()));
  63. hrp.sParamList.push_back(QString("password,%1").arg(ui->edt_oldPassword->text()));
  64. g_httpBllPtr->put(hrp);
  65. }
  66. void clEditPassword::onEditPassword(CEditPassword editPassword)
  67. {
  68. if (editPassword.nCode == 200)
  69. {
  70. ShowMsg(QString::fromLocal8Bit("保存密码成功"), this, MSG_ICON_TYPE::mit_succeed);
  71. }
  72. else
  73. {
  74. if (editPassword.sMessage != "")
  75. {
  76. ShowMsg(editPassword.sMessage, this, MSG_ICON_TYPE::mit_error);
  77. }
  78. else
  79. {
  80. ShowMsg(QString::fromLocal8Bit("保存密码失败"), this, MSG_ICON_TYPE::mit_error);
  81. }
  82. }
  83. }