dialogchangepass.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "dialogchangepass.h"
  2. #include "ui_dialogchangepass.h"
  3. #include "wsnumchk.h"
  4. #include "respchangepass.h"
  5. #include <QtGui>
  6. DialogChangePass::DialogChangePass(QWidget *parent) :
  7. QDialog(parent),
  8. ui(new Ui::DialogChangePass)
  9. {
  10. ui->setupUi(this);
  11. ui->buttonBox->button(QDialogButtonBox::Ok)->setText("更改");
  12. ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("关闭");
  13. }
  14. DialogChangePass::~DialogChangePass()
  15. {
  16. delete ui;
  17. }
  18. void DialogChangePass::setUserHash(QString userHash)
  19. {
  20. this->userHash = userHash;
  21. }
  22. void DialogChangePass::setHost(QString host)
  23. {
  24. this->host = host;
  25. }
  26. void DialogChangePass::on_buttonBox_accepted()
  27. {
  28. this->ui->buttonBox->setEnabled(false);
  29. WSNumChk *client = new WSNumChk(this->host);
  30. QString oldPass = this->ui->oldPassEdit->text();
  31. QString newPass = this->ui->newPassEdit->text();
  32. QString json = client->changePass(oldPass,newPass,this->userHash);
  33. bool ok = false;
  34. if(json.isEmpty())
  35. {
  36. QMessageBox::information(this,"结果","网络连接失败!",QMessageBox::Ok);
  37. }
  38. else
  39. {
  40. RespChangePass *response = new RespChangePass(json);
  41. if(response->getRtnCode()==1)
  42. {
  43. this->ui->oldPassEdit->setText("");
  44. this->ui->newPassEdit->setText("");
  45. this->ui->newPass2Edit->setText("");
  46. ok = true;
  47. QMessageBox::information(this,"结果","密码修改成功!",QMessageBox::Ok);
  48. }
  49. else if(response->getRtnCode()==-1)
  50. {
  51. QMessageBox::information(this,"结果","登录超时,请重新登录!",QMessageBox::Ok);
  52. }
  53. else
  54. {
  55. QMessageBox::information(this,"结果","发生错误,密码修改不成功!",QMessageBox::Ok);
  56. }
  57. delete response;
  58. }
  59. this->ui->buttonBox->setEnabled(true);
  60. if(ok)
  61. this->close();
  62. delete client;
  63. }