password.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. onLoad(options) {
  14. if (options.noLogin) {
  15. this.setData({
  16. noLogin: options.noLogin
  17. })
  18. }
  19. },
  20. onShow() {
  21. // 更新用户信息
  22. this.setData({
  23. userInfo: app.globalData.userInfo,
  24. })
  25. },
  26. sendCode() {
  27. let that = this;
  28. if (that.data.time > 0) return false;
  29. console.log(this.data.userInfo);
  30. let key=crypto.encrypted(this.data.userInfo.loginName)
  31. console.log(key);
  32. util.sendMessage({ phone: this.data.userInfo.loginName, type: "rcode", time: 120,key:key }, (res) => {
  33. that.setData({ time: res.text })
  34. })
  35. },
  36. submit() {
  37. let that = this;
  38. if (util.isEmpty(this.data.code)) {
  39. util.showTips("请输入验证码");
  40. return false;
  41. }
  42. if (this.data.code.length != 6) {
  43. util.showTips("请输入6位验证码");
  44. return false;
  45. }
  46. console.log(this.data.password, this.data.rPassword)
  47. if (util.isEmpty(this.data.password) || util.isEmpty(this.data.rPassword)){
  48. util.showTips("密码不能为空");
  49. return false;
  50. }
  51. if (this.data.password.length < 4) {
  52. util.showTips("请输入至少4位密码");
  53. return false;
  54. }
  55. if (this.data.password!=this.data.rPassword) {
  56. util.showTips("两次密码不一致");
  57. return false;
  58. }
  59. util.ajax({
  60. func: '/v2/login/forget',
  61. data: { 'phone': that.data.userInfo.loginName, 'rcode': that.data.code, 'password': md5.hexMD5(that.data.password)}
  62. }, function (res) {
  63. if (res.code == 0) {
  64. wx.showModal({
  65. content: '密码修改成功。',
  66. showCancel:false,
  67. success(res) {
  68. if (res.confirm) {
  69. wx.navigateBack()
  70. }
  71. }
  72. })
  73. } else {
  74. util.showTips(res.reason)
  75. }
  76. })
  77. },
  78. codeInput(e) {
  79. this.setData({ code: e.detail.value })
  80. },
  81. passwordInput(e) {
  82. this.setData({ password: e.detail.value })
  83. },
  84. rPasswordInput(e) {
  85. this.setData({ rPassword: e.detail.value })
  86. }
  87. })