dialogchangepass.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "dialogchangepass.h"
  2. #include "ui_dialogchangepass.h"
  3. #include "WSSSO.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. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  18. <<"SNCUser.DialogChangePass Destroyed.";
  19. }
  20. void DialogChangePass::setUserHash(QString userHash)
  21. {
  22. this->userHash = userHash;
  23. }
  24. void DialogChangePass::setHost(QString host)
  25. {
  26. this->host = host;
  27. }
  28. void DialogChangePass::on_buttonBox_accepted()
  29. {
  30. QString oldPass = this->ui->oldPassEdit->text();
  31. QString newPass2 = this->ui->newPass2Edit->text();
  32. QString newPass = this->ui->newPassEdit->text();
  33. if(newPass2!=newPass)
  34. {
  35. QMessageBox::critical(this,"结果","两次输入的密码不一致!",QMessageBox::Ok);
  36. return ;
  37. }
  38. if(oldPass.isEmpty() ||newPass.isEmpty())
  39. {
  40. QMessageBox::critical(this,"结果","密码不能为空!",QMessageBox::Ok);
  41. return ;
  42. }
  43. this->ui->buttonBox->setEnabled(false);
  44. WSSSO *client = new WSSSO();
  45. QString json = client->changePass(oldPass,newPass,this->userHash);
  46. this->ui->buttonBox->setEnabled(true);
  47. bool ok = false;
  48. if(json.isEmpty())
  49. {
  50. QMessageBox::warning(this,"结果","网络连接失败!",QMessageBox::Ok);
  51. }
  52. else
  53. {
  54. RespChangePass *response = new RespChangePass(json);
  55. if(response->getRtnCode()==1)
  56. {
  57. this->ui->oldPassEdit->setText("");
  58. this->ui->newPassEdit->setText("");
  59. this->ui->newPass2Edit->setText("");
  60. ok = true;
  61. QMessageBox::information(this,"结果","密码修改成功!",QMessageBox::Ok);
  62. }
  63. else if(response->getRtnCode()==-1)
  64. {
  65. QMessageBox::critical(this,"结果","登录超时,请重新登录!",QMessageBox::Ok);
  66. }
  67. else
  68. {
  69. QMessageBox::critical(this,"结果",response->getRtnMemo(),QMessageBox::Ok);
  70. }
  71. delete response;
  72. }
  73. if(ok)
  74. this->close();
  75. delete client;
  76. }