加入普通登录接口
This commit is contained in:
@@ -1,26 +1,16 @@
|
||||
package com.buy507.mall.portal.controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.buy507.mall.common.api.CommonResult;
|
||||
import com.buy507.mall.portal.domain.*;
|
||||
import com.buy507.mall.portal.service.UmsMemberService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.buy507.mall.common.api.CommonResult;
|
||||
import com.buy507.mall.portal.domain.FirstMemberInfoParam;
|
||||
import com.buy507.mall.portal.domain.MemberInfoResult;
|
||||
import com.buy507.mall.portal.domain.MemberTransferParam;
|
||||
import com.buy507.mall.portal.domain.WeChatLogin;
|
||||
import com.buy507.mall.portal.domain.WithdrawApplyParam;
|
||||
import com.buy507.mall.portal.service.UmsMemberService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 会员管理Controller
|
||||
@@ -34,7 +24,6 @@ public class UmsMemberController {
|
||||
private UmsMemberService memberService;
|
||||
|
||||
|
||||
/*
|
||||
@ApiOperation("注册")
|
||||
@RequestMapping(value = "/register", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@@ -43,36 +32,33 @@ public class UmsMemberController {
|
||||
@RequestParam String authCode) {
|
||||
return memberService.register(telephone, password, authCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ApiOperation(value = "登录以后返回token")
|
||||
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult login(@RequestParam String telephone, @RequestParam String password) {
|
||||
String token = memberService.login(telephone, password);
|
||||
if (token == null) {
|
||||
Map<String, String> tokenMap = memberService.login(telephone, password);
|
||||
if (tokenMap == null) {
|
||||
return CommonResult.validateFailed("用户名或密码错误");
|
||||
}
|
||||
Map<String, String> tokenMap = new HashMap<>();
|
||||
tokenMap.put("token", token);
|
||||
tokenMap.put("tokenHead", tokenHead);
|
||||
return CommonResult.success(tokenMap);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@ApiOperation(value = "微信登录接口,登录成功以后返回token")
|
||||
@RequestMapping(value = "/wechatLogin", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult<Map<String, String>> wechatLogin(@RequestBody WeChatLogin weChatLogin) {
|
||||
|
||||
|
||||
if(StringUtils.isEmpty(weChatLogin.getCode())) {
|
||||
return CommonResult.failed("授权码code不能为空");
|
||||
}
|
||||
|
||||
|
||||
Map<String, String> tokenMap = memberService.wechatLogin(weChatLogin);
|
||||
if (tokenMap == null) {
|
||||
return CommonResult.unauthorized(null);
|
||||
}
|
||||
|
||||
|
||||
return CommonResult.success(tokenMap);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public interface UmsMemberService {
|
||||
* @param password 密码
|
||||
* @return 生成的JWT的token
|
||||
*/
|
||||
String login(String telephone,String password);
|
||||
Map<String, String> login(String telephone,String password);
|
||||
|
||||
/**
|
||||
* 微信登录
|
||||
|
||||
@@ -245,8 +245,8 @@ public class UmsMemberServiceImpl implements UmsMemberService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String login(String telephone, String password) {
|
||||
String token = null;
|
||||
public Map<String, String> login(String telephone, String password) {
|
||||
Map<String, String> tokenMap = null;
|
||||
//密码需要客户端加密后传递
|
||||
try {
|
||||
UserDetails userDetails = userDetailsService.loadUserByUsername(telephone);
|
||||
@@ -255,12 +255,26 @@ public class UmsMemberServiceImpl implements UmsMemberService {
|
||||
}
|
||||
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
token = jwtTokenUtil.generateToken(userDetails);
|
||||
UmsMember member = ((MemberDetails) userDetails).getUmsMember();
|
||||
String token = jwtTokenUtil.generateToken(userDetails);
|
||||
tokenMap = new HashMap<>();
|
||||
tokenMap.put("token", token);
|
||||
tokenMap.put("tokenHead", tokenHead);
|
||||
tokenMap.put("phone", member.getPhone() == null ? "" : member.getPhone());
|
||||
if(StringUtils.isEmpty(member.getPhone()) || StringUtils.isEmpty(member.getRealName())) {
|
||||
tokenMap.put("flag", "0");
|
||||
} else {
|
||||
tokenMap.put("flag", "1");
|
||||
}
|
||||
|
||||
//insertLoginLog(username);
|
||||
} catch (AuthenticationException e) {
|
||||
LOGGER.warn("登录异常:{}", e.getMessage());
|
||||
}
|
||||
return token;
|
||||
|
||||
|
||||
|
||||
return tokenMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user