diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java index a0eb5151..522749cd 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java @@ -173,6 +173,7 @@ public class WxAuthController { user = new LitemallUser(); user.setUsername(username); user.setPassword(password); + user.setMobile(mobile); user.setWeixinOpenid(""); user.setAvatar("https://yanxuan.nosdn.127.net/80841d741d7fa3073e0ae27bf487339f.jpg?imageView&quality=90&thumbnail=64x64"); user.setNickname(username); @@ -198,4 +199,35 @@ public class WxAuthController { result.put("userInfo", userInfo); return ResponseUtil.ok(result); } + + /** + * 账号密码重置 + */ + @PostMapping("reset") + public Object reset(@RequestBody String body, HttpServletRequest request) { + String password = JacksonUtil.parseString(body, "password"); + String mobile = JacksonUtil.parseString(body, "mobile"); + String code = JacksonUtil.parseString(body, "code"); + + if(mobile == null || code == null || password == null){ + return ResponseUtil.badArgument(); + } + + List userList = userService.queryByMobile(mobile); + LitemallUser user = null; + if(userList.size() > 1){ + return ResponseUtil.serious(); + } + else if(userList.size() == 0){ + return ResponseUtil.fail(403, "手机号未注册"); + } + else{ + user = userList.get(0); + } + + user.setPassword(password); + userService.update(user); + + return ResponseUtil.ok(); + } } diff --git a/litemall-wx/config/api.js b/litemall-wx/config/api.js index e3573f71..996ab4ee 100644 --- a/litemall-wx/config/api.js +++ b/litemall-wx/config/api.js @@ -23,6 +23,7 @@ module.exports = { AuthLoginByWeixin: WxApiRoot + 'auth/login_by_weixin', //微信登录 AuthLoginByAccount: WxApiRoot + 'auth/login', //账号登录 AuthRegister: WxApiRoot + 'auth/register', //账号注册 + AuthReset: WxApiRoot + 'auth/reset', //账号密码重置 GoodsCount: WxApiRoot + 'goods/count', //统计商品总数 GoodsList: WxApiRoot + 'goods/list', //获得商品列表 diff --git a/litemall-wx/pages/auth/reset/reset.js b/litemall-wx/pages/auth/reset/reset.js index f5bbc78c..57401bcf 100644 --- a/litemall-wx/pages/auth/reset/reset.js +++ b/litemall-wx/pages/auth/reset/reset.js @@ -1,8 +1,11 @@ +var api = require('../../../config/api.js'); var app = getApp(); Page({ data: { - username: '', - code: '' + mobile: '', + code: '', + password: '', + confirmPassword: '' }, onLoad: function (options) { // 页面初始化 options为页面跳转所带来的参数 @@ -24,13 +27,84 @@ Page({ // 页面关闭 }, - startLogin: function(){ - var that = this; + sendCode: function () { + wx.showModal({ + title: '注意', + content: '由于目前不支持手机短信发送,因此验证码任意值都可以', + showCancel: false + }); }, - bindUsernameInput: function(e){ - + startReset: function(){ + var that = this; + + if (this.data.mobile.length == 0 || this.data.code.length == 0) { + wx.showModal({ + title: '错误信息', + content: '手机号和验证码不能为空', + showCancel: false + }); + return false; + } + + if (this.data.password.length < 3) { + wx.showModal({ + title: '错误信息', + content: '用户名和密码不得少于3位', + showCancel: false + }); + return false; + } + + if (this.data.password != this.data.confirmPassword) { + wx.showModal({ + title: '错误信息', + content: '确认密码不一致', + showCancel: false + }); + return false; + } + + wx.request({ + url: api.AuthReset, + data: { + mobile: that.data.mobile, + code: that.data.code, + password: that.data.password + }, + method: 'POST', + header: { + 'content-type': 'application/json' + }, + success: function (res) { + if (res.data.errno == 0) { + wx.navigateBack(); + } + else{ + wx.showModal({ + title: '密码重置失败', + content: res.data.errmsg, + showCancel: false + }); + } + } + }); + }, + bindPasswordInput: function (e) { + this.setData({ - username: e.detail.value + password: e.detail.value + }); + }, + bindConfirmPasswordInput: function (e) { + + this.setData({ + confirmPassword: e.detail.value + }); + }, + bindMobileInput: function (e) { + + this.setData({ + mobile: e.detail.value }); }, bindCodeInput: function(e){ @@ -41,12 +115,22 @@ Page({ }, clearInput: function(e){ switch (e.currentTarget.id){ - case 'clear-username': + case 'clear-password': this.setData({ - username: '' + password: '' }); break; - case 'clear-code': + case 'clear-confirm-password': + this.setData({ + confirmPassword: '' + }); + break; + case 'clear-mobile': + this.setData({ + mobile: '' + }); + break; + case 'clear-code': this.setData({ code: '' }); diff --git a/litemall-wx/pages/auth/reset/reset.wxml b/litemall-wx/pages/auth/reset/reset.wxml index 54e9a7c1..35f29cf3 100644 --- a/litemall-wx/pages/auth/reset/reset.wxml +++ b/litemall-wx/pages/auth/reset/reset.wxml @@ -1,20 +1,30 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + 获取验证码 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/litemall-wx/pages/auth/reset/reset.wxss b/litemall-wx/pages/auth/reset/reset.wxss index bd888202..94fca0b8 100644 --- a/litemall-wx/pages/auth/reset/reset.wxss +++ b/litemall-wx/pages/auth/reset/reset.wxss @@ -14,7 +14,7 @@ border-bottom: 1px solid #d9d9d9; } -.form-item .username, .form-item .code{ +.form-item .mobile, .form-item .password, .form-item .code{ position: absolute; top: 26rpx; left: 0; @@ -38,11 +38,11 @@ width: 350rpx; } -.form-item-code .code-img{ +.form-item-code .code-btn{ float: right; - margin-top: 4rpx; - height: 88rpx; - width: 236rpx; + padding: 20rpx 40rpx; + border: 1px solid #d9d9d9; + border-radius: 10rpx; } .form-item .clear{ @@ -56,7 +56,7 @@ width: 44rpx; } -.login-btn{ +.reset-btn{ margin: 60rpx 0 40rpx 0; height: 96rpx; line-height: 96rpx; @@ -65,4 +65,4 @@ width: 100%; background: #b4282d; border-radius: 6rpx; -} +} \ No newline at end of file