password.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const util = require('../../../utils/util.js');
  2. const md5 = require('../../../utils/md5.js');
  3. const app = getApp();
  4. const crypto=require("../../../utils/crypto")
  5. Page({
  6. data: {
  7. userInfo: app.globalData.userInfo,
  8. code: '',
  9. password: '',
  10. rPassword: '',
  11. time: 0
  12. },
  13. sendCode() {
  14. let that = this;
  15. if (that.data.time > 0) return false;
  16. console.log(this.data.userInfo);
  17. let key=crypto.encrypted(this.data.userInfo.loginName)
  18. console.log(key);
  19. util.sendMessage({ phone: this.data.userInfo.loginName, type: "rcode", time: 120,key:key }, (res) => {
  20. that.setData({ time: res.text })
  21. })
  22. },
  23. submit() {
  24. let that = this;
  25. if (util.isEmpty(this.data.code)) {
  26. util.showTips("请输入验证码");
  27. return false;
  28. }
  29. if (this.data.code.length != 6) {
  30. util.showTips("请输入6位验证码");
  31. return false;
  32. }
  33. console.log(this.data.password, this.data.rPassword)
  34. if (util.isEmpty(this.data.password) || util.isEmpty(this.data.rPassword)){
  35. util.showTips("密码不能为空");
  36. return false;
  37. }
  38. if (this.data.password.length < 4) {
  39. util.showTips("请输入至少4位密码");
  40. return false;
  41. }
  42. if (this.data.password!=this.data.rPassword) {
  43. util.showTips("两次密码不一致");
  44. return false;
  45. }
  46. util.ajax({
  47. func: '/v2/login/forget',
  48. data: { 'phone': that.data.userInfo.loginName, 'rcode': that.data.code, 'password': md5.hexMD5(that.data.password)}
  49. }, function (res) {
  50. if (res.code == 0) {
  51. wx.showModal({
  52. content: '密码修改成功。',
  53. showCancel:false,
  54. success(res) {
  55. if (res.confirm) {
  56. wx.navigateBack()
  57. }
  58. }
  59. })
  60. } else {
  61. util.showTips(res.reason)
  62. }
  63. })
  64. },
  65. codeInput(e) {
  66. this.setData({ code: e.detail.value })
  67. },
  68. passwordInput(e) {
  69. this.setData({ password: e.detail.value })
  70. },
  71. rPasswordInput(e) {
  72. this.setData({ rPassword: e.detail.value })
  73. }
  74. })