Commit 8bd3e8d0 authored by Junling Bu's avatar Junling Bu
Browse files

update[litemall-wx,litemall-wx-api,litemall-db]:实现账户登录,但多次失败验证码还不支持。"

parent eb499e85
...@@ -63,4 +63,10 @@ public class LitemallUserService { ...@@ -63,4 +63,10 @@ public class LitemallUserService {
LitemallUserExample example = new LitemallUserExample(); LitemallUserExample example = new LitemallUserExample();
return (int)userMapper.countByExample(example); return (int)userMapper.countByExample(example);
} }
public List<LitemallUser> queryByUsername(String username) {
LitemallUserExample example = new LitemallUserExample();
example.or().andUsernameEqualTo(username);
return userMapper.selectByExample(example);
}
} }
...@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
...@@ -35,14 +36,59 @@ public class WxAuthController { ...@@ -35,14 +36,59 @@ public class WxAuthController {
@Autowired @Autowired
private WxMaService wxService; private WxMaService wxService;
/**
* 微信登录
*/
@RequestMapping("login")
public Object login(@RequestBody String body, HttpServletRequest request) {
String username = JacksonUtil.parseString(body, "username");
String password = JacksonUtil.parseString(body, "password");
if(username == null || password == null){
return ResponseUtil.badArgument();
}
List<LitemallUser> userList =userService.queryByUsername(username);
LitemallUser user = null;
if(userList.size() > 1){
return ResponseUtil.fail502();
}
else if(userList.size() == 0){
return ResponseUtil.badArgumentValue();
}
else {
user = userList.get(0);
}
if(!user.getPassword().equals(password)){
return ResponseUtil.badArgumentValue();
}
// userInfo
UserInfo userInfo = new UserInfo();
userInfo.setNickName(username);
userInfo.setAvatarUrl(user.getAvatar());
// token
UserToken userToken = UserTokenManager.generateToken(user.getId());
Map<Object, Object> result = new HashMap<Object, Object>();
result.put("token", userToken.getToken());
result.put("tokenExpire", userToken.getExpireTime().toString());
result.put("userInfo", userInfo);
return ResponseUtil.ok(result);
}
/** /**
* 微信登录 * 微信登录
*/ */
@RequestMapping("login_by_weixin") @RequestMapping("login_by_weixin")
public Object loginByWeixin(@RequestBody String body, HttpServletRequest request) { public Object loginByWeixin(@RequestBody String body, HttpServletRequest request) {
String code = JacksonUtil.parseString(body, "code"); String code = JacksonUtil.parseString(body, "code");
FullUserInfo fullUserInfo = JacksonUtil.parseObject(body, "userInfo", FullUserInfo.class); FullUserInfo fullUserInfo = JacksonUtil.parseObject(body, "userInfo", FullUserInfo.class);
if(code == null || fullUserInfo == null){
return ResponseUtil.badArgument();
}
UserInfo userInfo = fullUserInfo.getUserInfo(); UserInfo userInfo = fullUserInfo.getUserInfo();
String sessionKey = null; String sessionKey = null;
......
...@@ -21,6 +21,7 @@ module.exports = { ...@@ -21,6 +21,7 @@ module.exports = {
CatalogCurrent: WxApiRoot + 'catalog/current', //分类目录当前分类数据接口 CatalogCurrent: WxApiRoot + 'catalog/current', //分类目录当前分类数据接口
AuthLoginByWeixin: WxApiRoot + 'auth/login_by_weixin', //微信登录 AuthLoginByWeixin: WxApiRoot + 'auth/login_by_weixin', //微信登录
AuthLoginByAccount: WxApiRoot + 'auth/login', //账号登录
GoodsCount: WxApiRoot + 'goods/count', //统计商品总数 GoodsCount: WxApiRoot + 'goods/count', //统计商品总数
GoodsList: WxApiRoot + 'goods/list', //获得商品列表 GoodsList: WxApiRoot + 'goods/list', //获得商品列表
......
...@@ -48,7 +48,7 @@ Page({ ...@@ -48,7 +48,7 @@ Page({
accountLogin: function () { accountLogin: function () {
var that = this; var that = this;
if (that.data.password.length < 1 || that.data.username.length < 1) { if (this.data.password.length < 1 || this.data.username.length < 1) {
wx.showModal({ wx.showModal({
title: '错误信息', title: '错误信息',
content: '请输入用户名和密码', content: '请输入用户名和密码',
...@@ -58,7 +58,7 @@ Page({ ...@@ -58,7 +58,7 @@ Page({
} }
wx.request({ wx.request({
url: api.ApiRootUrl + 'auth/login', url: api.AuthLoginByAccount,
data: { data: {
username: that.data.username, username: that.data.username,
password: that.data.password password: that.data.password
...@@ -68,11 +68,12 @@ Page({ ...@@ -68,11 +68,12 @@ Page({
'content-type': 'application/json' 'content-type': 'application/json'
}, },
success: function (res) { success: function (res) {
if(res.data.code == 200){ if (res.data.errno == 0){
that.setData({ that.setData({
'loginErrorCount': 0 loginErrorCount: 0
}); });
app.globalData.hasLogin = true; app.globalData.hasLogin = true;
wx.setStorageSync('userInfo', res.data.data.userInfo);
wx.setStorage({ wx.setStorage({
key:"token", key:"token",
data: res.data.data.token, data: res.data.data.token,
...@@ -84,6 +85,9 @@ Page({ ...@@ -84,6 +85,9 @@ Page({
}); });
} }
else{ else{
that.setData({
loginErrorCount: that.data.loginErrorCount + 1
});
app.globalData.hasLogin = false; app.globalData.hasLogin = false;
util.showErrorToast('账户登录失败'); util.showErrorToast('账户登录失败');
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<view class="form-box"> <view class="form-box">
<view class="form-item"> <view class="form-item">
<input class="username" value="{{username}}" bindinput="bindUsernameInput" placeholder="账号" auto-focus/> <input class="username" value="{{username}}" bindinput="bindUsernameInput" placeholder="账号"/>
<image wx:if="{{ username.length > 0 }}" id="clear-username" class="clear" src="/static/images/clear_input.png" catchtap="clearInput"></image> <image wx:if="{{ username.length > 0 }}" id="clear-username" class="clear" src="/static/images/clear_input.png" catchtap="clearInput"></image>
</view> </view>
...@@ -11,22 +11,22 @@ ...@@ -11,22 +11,22 @@
<image class="clear" id="clear-password" wx:if="{{ password.length > 0 }}" src="/static/images/clear_input.png" catchtap="clearInput"></image> <image class="clear" id="clear-password" wx:if="{{ password.length > 0 }}" src="/static/images/clear_input.png" catchtap="clearInput"></image>
</view> </view>
<view class="form-item-code" wx-if="{{loginErrorCount >= 3}}"> <!-- <view class="form-item-code" wx-if="{{loginErrorCount >= 3}}">
<view class="form-item code-item"> <view class="form-item code-item">
<input class="code" value="{{code}}" bindinput="bindCodeInput" placeholder="验证码"/> <input class="code" value="{{code}}" bindinput="bindCodeInput" placeholder="验证码"/>
<image class="clear" id="clear-code" wx:if="{{ code.length > 0 }}" src="/static/images/clear_input.png" catchtap="clearInput"></image> <image class="clear" id="clear-code" wx:if="{{ code.length > 0 }}" src="/static/images/clear_input.png" catchtap="clearInput"></image>
</view> </view>
<image class="code-img" src="https://dl.reg.163.com/cp?pd=yanxuan_web&pkid=SkeBZeG&random=1489903563234"></image> <image class="code-img" src="https://dl.reg.163.com/cp?pd=yanxuan_web&pkid=SkeBZeG&random=1489903563234"></image>
</view> </view> -->
<button type="default" class="login-btn" bindtap="accountLogin">账号登录</button> <button type="default" class="login-btn" bindtap="accountLogin">账号登录</button>
<view class="form-item-text"> <view class="form-item-text">
<navigator url="/pages/auth/register/register" class="register">注册账号</navigator> <navigator url="/pages/auth/register/register" class="register">注册账号</navigator>
<navigator url="/pages/auth/reset/reset" class="reset">忘记密码</navigator> <navigator url="/pages/auth/reset/reset" class="reset">忘记密码</navigator>
</view> </view>
<button type="primary" class="login-btn" bindtap="wxLogin">微信直接登录</button> <button type="primary" class="login-btn" bindtap="wxLogin">微信直接登录</button>
</view> </view>
</view> </view>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment