rePassword.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. $(function () {
  2. $("#changePwd").on("click", function (e) {
  3. e.preventDefault();
  4. var password = $("#password");
  5. var password1 = $("#password1");
  6. if (password.val().trim() === "") {
  7. showMsg("请输入密码", 2, 1000);
  8. password.focus();
  9. return;
  10. }
  11. if (password1.val().trim() === "") {
  12. showMsg("请再次输入密码", 2, 1000);
  13. password1.focus();
  14. return;
  15. }
  16. if (password.val().trim() === password1.val().trim()) {
  17. fetchJSON(
  18. "api/user/update",
  19. {
  20. userId:sessionStorage.getItem("userId"),
  21. userAccount: sessionStorage.getItem("userAccount"),
  22. userPassword: password.val().trim(),
  23. },
  24. "post",
  25. function (ret) {
  26. if (ret.code === 0) {
  27. fetchJSON("api/user/logout", {}, "post", function (data) {
  28. showMsg("修改成功,请重新登陆",2,1000);
  29. sessionStorage.setItem("userId", -1);
  30. sessionStorage.setItem("userAccount", "");
  31. window.login = "login";
  32. window.location.href = "../../index.html";
  33. });
  34. } else {
  35. showMsg(ret.msg, 2, 1000);
  36. if (data.code === 6) {
  37. showMsg("修改失败", 2);
  38. $("#username").focus();
  39. } else {
  40. showMsg(data.data, 2);
  41. }
  42. }
  43. }
  44. );
  45. } else {
  46. showMsg("两次密码不匹配", 2, 1000);
  47. return;
  48. }
  49. });
  50. });
  51. //身份证验证
  52. function is_idcard(id) {
  53. var idcardReg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
  54. if(idcardReg.test(id))
  55. return true;
  56. else
  57. return false;
  58. }