From 38f8d93e5219477a90ba835cfda761507fc97eab Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Mon, 2 Apr 2018 00:25:27 +0800 Subject: [PATCH] =?UTF-8?q?update[litemall-wx,litemall-wx-api,litemall-db]?= =?UTF-8?q?:=E5=AE=9E=E7=8E=B0=E7=94=A8=E6=88=B7=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E6=98=AF=E5=9B=A0=E4=B8=BA=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E5=8F=91=E9=80=81=E4=B8=8D=E6=94=AF=E6=8C=81?= =?UTF-8?q?=EF=BC=8C=E5=9B=A0=E6=AD=A4=E6=89=8B=E6=9C=BA=E5=8F=B7=E7=A0=81?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E6=98=AF=E6=97=A0=E6=84=8F=E4=B9=89?= =?UTF-8?q?=E7=9A=84=E3=80=82=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/service/LitemallUserService.java | 6 ++ .../litemall/wx/web/WxAuthController.java | 57 ++++++++++++++++++- litemall-wx/config/api.js | 9 +-- litemall-wx/pages/auth/register/register.js | 49 ++++++++++++---- litemall-wx/pages/auth/register/register.wxml | 11 +++- litemall-wx/pages/auth/register/register.wxss | 10 ++-- 6 files changed, 118 insertions(+), 24 deletions(-) diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java index 63f7f6a8..bc239fda 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java @@ -69,4 +69,10 @@ public class LitemallUserService { example.or().andUsernameEqualTo(username); return userMapper.selectByExample(example); } + + public List queryByMobile(String mobile) { + LitemallUserExample example = new LitemallUserExample(); + example.or().andMobileEqualTo(mobile); + return userMapper.selectByExample(example); + } } 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 7fbe1b97..a0eb5151 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 @@ -15,6 +15,7 @@ import org.linlinjava.litemall.wx.dao.UserToken; import org.linlinjava.litemall.wx.service.UserTokenManager; import org.linlinjava.litemall.wx.util.IpUtil; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -37,7 +38,7 @@ public class WxAuthController { private WxMaService wxService; /** - * 微信登录 + * 账号登录 */ @RequestMapping("login") public Object login(@RequestBody String body, HttpServletRequest request) { @@ -143,4 +144,58 @@ public class WxAuthController { result.put("userInfo", userInfo); return ResponseUtil.ok(result); } + + /** + * 账号注册 + */ + @PostMapping("register") + public Object register(@RequestBody String body, HttpServletRequest request) { + String username = JacksonUtil.parseString(body, "username"); + String password = JacksonUtil.parseString(body, "password"); + String mobile = JacksonUtil.parseString(body, "mobile"); + String code = JacksonUtil.parseString(body, "code"); + + if(username == null || password == null || mobile == null || code == null){ + return ResponseUtil.badArgument(); + } + + List userList = userService.queryByUsername(username); + if(userList.size() > 0){ + return ResponseUtil.fail(403, "用户名已注册"); + } + + userList = userService.queryByMobile(mobile); + if(userList.size() > 0){ + return ResponseUtil.fail(403, "手机号已注册"); + } + + LitemallUser user = new LitemallUser(); + user = new LitemallUser(); + user.setUsername(username); + user.setPassword(password); + user.setWeixinOpenid(""); + user.setAvatar("https://yanxuan.nosdn.127.net/80841d741d7fa3073e0ae27bf487339f.jpg?imageView&quality=90&thumbnail=64x64"); + user.setNickname(username); + user.setGender("未知"); + user.setUserLevel("普通用户"); + user.setStatus("可用"); + user.setLastLoginTime(LocalDate.now()); + user.setLastLoginIp(IpUtil.client(request)); + userService.add(user); + + + // userInfo + UserInfo userInfo = new UserInfo(); + userInfo.setNickName(username); + userInfo.setAvatarUrl(user.getAvatar()); + + // token + UserToken userToken = UserTokenManager.generateToken(user.getId()); + + Map result = new HashMap(); + result.put("token", userToken.getToken()); + result.put("tokenExpire", userToken.getExpireTime().toString()); + result.put("userInfo", userInfo); + return ResponseUtil.ok(result); + } } diff --git a/litemall-wx/config/api.js b/litemall-wx/config/api.js index 4a114832..e3573f71 100644 --- a/litemall-wx/config/api.js +++ b/litemall-wx/config/api.js @@ -22,6 +22,7 @@ module.exports = { AuthLoginByWeixin: WxApiRoot + 'auth/login_by_weixin', //微信登录 AuthLoginByAccount: WxApiRoot + 'auth/login', //账号登录 + AuthRegister: WxApiRoot + 'auth/register', //账号注册 GoodsCount: WxApiRoot + 'goods/count', //统计商品总数 GoodsList: WxApiRoot + 'goods/list', //获得商品列表 @@ -43,7 +44,6 @@ module.exports = { CartGoodsCount: WxApiRoot + 'cart/goodscount', // 获取购物车商品件数 CartCheckout: WxApiRoot + 'cart/checkout', // 下单前信息确认 - OrderSubmit: WxApiRoot + 'order/submit', // 提交订单 PayPrepayId: WxApiRoot + 'pay/prepay', //获取微信统一下单prepay_id CollectList: WxApiRoot + 'collect/list', //收藏列表 @@ -57,10 +57,10 @@ module.exports = { TopicDetail: WxApiRoot + 'topic/detail', //专题详情 TopicRelated: WxApiRoot + 'topic/related', //相关专题 - SearchIndex: WxApiRoot + 'search/index', //搜索页面数据 - SearchResult: WxApiRoot + 'search/result', //搜索数据 + SearchIndex: WxApiRoot + 'search/index', //搜索关键字 + SearchResult: WxApiRoot + 'search/result', //搜索结果 SearchHelper: WxApiRoot + 'search/helper', //搜索帮助 - SearchClearHistory: WxApiRoot + 'search/clearhistory', //搜索帮助 + SearchClearHistory: WxApiRoot + 'search/clearhistory', //搜索历史清楚 AddressList: WxApiRoot + 'address/list', //收货地址列表 AddressDetail: WxApiRoot + 'address/detail', //收货地址详情 @@ -69,6 +69,7 @@ module.exports = { RegionList: WxApiRoot + 'region/list', //获取区域列表 + OrderSubmit: WxApiRoot + 'order/submit', // 提交订单 OrderList: WxApiRoot + 'order/list', //订单列表 OrderDetail: WxApiRoot + 'order/detail', //订单详情 OrderCancel: WxApiRoot + 'order/cancel', //取消订单 diff --git a/litemall-wx/pages/auth/register/register.js b/litemall-wx/pages/auth/register/register.js index 6c1faa85..3c5c810a 100644 --- a/litemall-wx/pages/auth/register/register.js +++ b/litemall-wx/pages/auth/register/register.js @@ -5,8 +5,8 @@ Page({ username: '', password: '', confirmPassword: '', - code: '', - loginErrorCount: 0 + mobile: '', + code: '' }, onLoad: function (options) { // 页面初始化 options为页面跳转所带来的参数 @@ -28,10 +28,17 @@ Page({ // 页面关闭 }, + sendCode: function () { + wx.showModal({ + title: '注意', + content: '由于目前不支持手机短信发送,因此验证码任意值都可以', + showCancel: false + }); + }, startRegister: function () { var that = this; - if (that.data.password.length < 3 || that.data.username.length < 3) { + if (this.data.password.length < 3 || this.data.username.length < 3) { wx.showModal({ title: '错误信息', content: '用户名和密码不得少于3位', @@ -40,7 +47,7 @@ Page({ return false; } - if (that.data.password != that.data.confirmPassword) { + if (this.data.password != this.data.confirmPassword) { wx.showModal({ title: '错误信息', content: '确认密码不一致', @@ -49,21 +56,31 @@ Page({ return false; } + if (this.data.mobile.length == 0 || this.data.code.length == 0) { + wx.showModal({ + title: '错误信息', + content: '手机号和验证码不能为空', + showCancel: false + }); + return false; + } + wx.request({ - url: api.ApiRootUrl + 'auth/register', + url: api.AuthRegister, data: { username: that.data.username, - password: that.data.password + password: that.data.password, + mobile: that.data.mobile, + code: that.data.code }, method: 'POST', header: { 'content-type': 'application/json' }, success: function (res) { - if (res.data.code == 200) { - that.setData({ - 'loginErrorCount': 0 - }); + if (res.data.errno == 0) { + app.globalData.hasLogin = true; + wx.setStorageSync('userInfo', res.data.data.userInfo); wx.setStorage({ key: "token", data: res.data.data.token, @@ -75,7 +92,6 @@ Page({ }); } - console.log(res.data.data.token) } }); }, @@ -97,6 +113,12 @@ Page({ confirmPassword: e.detail.value }); }, + bindMobileInput: function (e) { + + this.setData({ + mobile: e.detail.value + }); + }, bindCodeInput: function (e) { this.setData({ @@ -120,6 +142,11 @@ Page({ confirmPassword: '' }); break; + case 'clear-mobile': + this.setData({ + mobile: '' + }); + break; case 'clear-code': this.setData({ code: '' diff --git a/litemall-wx/pages/auth/register/register.wxml b/litemall-wx/pages/auth/register/register.wxml index 16f8576d..96a7fb89 100644 --- a/litemall-wx/pages/auth/register/register.wxml +++ b/litemall-wx/pages/auth/register/register.wxml @@ -11,17 +11,22 @@ - + - + + + + + + - + 获取验证码 diff --git a/litemall-wx/pages/auth/register/register.wxss b/litemall-wx/pages/auth/register/register.wxss index 57875f91..f9023c1a 100644 --- a/litemall-wx/pages/auth/register/register.wxss +++ b/litemall-wx/pages/auth/register/register.wxss @@ -14,7 +14,7 @@ border-bottom: 1px solid #d9d9d9; } -.form-item .username, .form-item .password, .form-item .code{ +.form-item .username, .form-item .password, .form-item .mobile, .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{