change_password.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. {% extends "layout.html" %}
  2. {% block head %}
  3. {{ super() }}
  4. <style type="text/css">
  5. label>span {
  6. color: deepskyblue;
  7. }
  8. .btn,
  9. .form-group>div>div,
  10. .form-control {
  11. border-radius: 0;
  12. }
  13. </style>
  14. {% endblock head %}
  15. {% block content %}
  16. <script>
  17. $(document).ready(function() {
  18. $("#change_password_form").delegate('#submit_button', 'click', function() {
  19. $.ajax({
  20. url : '/api/user/_change_password',
  21. type : 'POST',
  22. contentType: "application/json; charset=utf-8",
  23. dataType: "json",
  24. data : JSON.stringify({old_password: $('#old_password').val(), password: $('#password').val()}),
  25. error : function(data, textStatus, xhr) {
  26. if (data.status === 401) {
  27. alter_warning('当前密码有误!');
  28. } else {
  29. alter_danger(data.responseText);
  30. }
  31. },
  32. success : function(data, textStatus, xhr) {
  33. alter_success('密码修改成功!');
  34. setTimeout(function() {
  35. window.location.href="/";
  36. }, 1000);
  37. }
  38. });
  39. });
  40. $('#change_password_form').formValidation({
  41. framework: 'bootstrap4',
  42. icon: {
  43. valid: 'fa fa-check',
  44. invalid: 'fa fa-times',
  45. validating: 'fa fa-refresh'
  46. },
  47. // Since the Bootstrap Button hides the radio and checkbox
  48. // We exclude the disabled elements only
  49. excluded: ':disabled',
  50. locale: 'zh_CN',
  51. fields: {
  52. password: {
  53. validators: {
  54. notEmpty: {
  55. },
  56. stringLength: {
  57. min: 6,
  58. max: 128
  59. }
  60. }
  61. }
  62. }
  63. })
  64. .on('success.field.fv', function(e, data) {
  65. if (data.fv.getInvalidFields().length > 0) { // There is invalid field
  66. data.fv.disableSubmitButtons(true);
  67. }
  68. });
  69. });
  70. </script>
  71. <div class="panel">
  72. <div class="panel-body">
  73. <h3 class="title-hero" style="text-transform: unset;">
  74. 修改密码
  75. </h3>
  76. <div class="example-box-wrapper">
  77. <form id="change_password_form" class="form-horizontal bordered-row" action="javascript:;">
  78. <div class="form-group">
  79. <label class="col-sm-2 control-label">当前密码</label>
  80. <div class="col-sm-3">
  81. <input title="当前密码" class="form-control" id="old_password" name="old_password" type="password">
  82. </div>
  83. </div>
  84. <div class="form-group">
  85. <label class="col-sm-2 control-label">新密码</label>
  86. <div class="col-sm-3">
  87. <input title="新密码" class="form-control" id="password" name="password" type="password">
  88. </div>
  89. </div>
  90. <div class="form-group">
  91. <label class="col-sm-2 control-label"></label>
  92. <div class="col-sm-3 pull-right">
  93. <button id="submit_button" type="submit" class="btn btn-blue-alt" style="width: 180px; height: 40px; font-size: 16px;" disabled>确定</button>
  94. </div>
  95. </div>
  96. </form>
  97. </div>
  98. </div>
  99. </div>
  100. {% endblock content %}