mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-03 17:42:20 +08:00
refactor:项目调整
This commit is contained in:
parent
8fc8468219
commit
74722c6e68
@ -102,7 +102,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.youlai</groupId>
|
<groupId>com.youlai</groupId>
|
||||||
<artifactId>common-elasticsearch</artifactId>
|
<artifactId>common-es</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -47,7 +47,7 @@ public class BrandController {
|
|||||||
Page<PmsBrand> result = iPmsBrandService.page(new Page<>(page, limit), queryWrapper);
|
Page<PmsBrand> result = iPmsBrandService.page(new Page<>(page, limit), queryWrapper);
|
||||||
return Result.success(result.getRecords(), result.getTotal());
|
return Result.success(result.getRecords(), result.getTotal());
|
||||||
case LIST:
|
case LIST:
|
||||||
queryWrapper.eq(PmsBrand::getStatus, GlobalConstants.STATUS_NORMAL_VALUE)
|
queryWrapper.eq(PmsBrand::getStatus, GlobalConstants.STATUS_YES)
|
||||||
.select(PmsBrand::getId, PmsBrand::getName);
|
.select(PmsBrand::getId, PmsBrand::getName);
|
||||||
List<PmsBrand> list = iPmsBrandService.list(queryWrapper);
|
List<PmsBrand> list = iPmsBrandService.list(queryWrapper);
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
|
@ -34,7 +34,7 @@ public class CategoryController {
|
|||||||
public Result list(Long parentId) {
|
public Result list(Long parentId) {
|
||||||
PmsCategory category = new PmsCategory();
|
PmsCategory category = new PmsCategory();
|
||||||
category.setParentId(parentId);
|
category.setParentId(parentId);
|
||||||
category.setStatus(GlobalConstants.STATUS_NORMAL_VALUE);
|
category.setStatus(GlobalConstants.STATUS_YES);
|
||||||
List<CategoryVO> list = iPmsCategoryService.listForTree(category);
|
List<CategoryVO> list = iPmsCategoryService.listForTree(category);
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
2
pom.xml
2
pom.xml
@ -217,7 +217,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.youlai</groupId>
|
<groupId>com.youlai</groupId>
|
||||||
<artifactId>common-elasticsearch</artifactId>
|
<artifactId>common-es</artifactId>
|
||||||
<version>${youlai.version}</version>
|
<version>${youlai.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -13,11 +13,14 @@ import java.util.List;
|
|||||||
@Data
|
@Data
|
||||||
public class SysRole extends BaseEntity {
|
public class SysRole extends BaseEntity {
|
||||||
|
|
||||||
@TableId(type= IdType.AUTO)
|
@TableId(type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty("角色编码")
|
||||||
|
private String code;
|
||||||
|
|
||||||
private Integer sort;
|
private Integer sort;
|
||||||
|
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
@ -94,7 +94,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.youlai</groupId>
|
<groupId>com.youlai</groupId>
|
||||||
<artifactId>common-elasticsearch</artifactId>
|
<artifactId>common-es</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -13,7 +13,7 @@ import lombok.Setter;
|
|||||||
|
|
||||||
public enum PermTypeEnum {
|
public enum PermTypeEnum {
|
||||||
|
|
||||||
ROUTE(1, "路由权限"),
|
ROUTE(1, "接口权限"),
|
||||||
BUTTON(2, "按钮权限");
|
BUTTON(2, "按钮权限");
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ -23,4 +23,4 @@ public enum PermTypeEnum {
|
|||||||
PermTypeEnum(Integer value, String desc) {
|
PermTypeEnum(Integer value, String desc) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public class RoleController {
|
|||||||
return Result.success(result.getRecords(), result.getTotal());
|
return Result.success(result.getRecords(), result.getTotal());
|
||||||
case LIST:
|
case LIST:
|
||||||
List list = iSysRoleService.list(new LambdaQueryWrapper<SysRole>()
|
List list = iSysRoleService.list(new LambdaQueryWrapper<SysRole>()
|
||||||
.eq(SysRole::getStatus, GlobalConstants.STATUS_NORMAL_VALUE));
|
.eq(SysRole::getStatus, GlobalConstants.STATUS_YES));
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
default:
|
default:
|
||||||
return Result.failed(ResultCode.QUERY_MODE_IS_NULL);
|
return Result.failed(ResultCode.QUERY_MODE_IS_NULL);
|
||||||
|
@ -13,7 +13,6 @@ import com.youlai.admin.pojo.entity.SysUserRole;
|
|||||||
import com.youlai.admin.pojo.dto.UserDTO;
|
import com.youlai.admin.pojo.dto.UserDTO;
|
||||||
import com.youlai.admin.pojo.vo.UserVO;
|
import com.youlai.admin.pojo.vo.UserVO;
|
||||||
import com.youlai.admin.service.*;
|
import com.youlai.admin.service.*;
|
||||||
import com.youlai.common.base.BaseController;
|
|
||||||
import com.youlai.common.result.Result;
|
import com.youlai.common.result.Result;
|
||||||
import com.youlai.common.result.ResultCode;
|
import com.youlai.common.result.ResultCode;
|
||||||
import com.youlai.common.web.util.RequestUtils;
|
import com.youlai.common.web.util.RequestUtils;
|
||||||
@ -35,7 +34,7 @@ import java.util.stream.Collectors;
|
|||||||
@RequestMapping("/api.admin/v1/users")
|
@RequestMapping("/api.admin/v1/users")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class UserController extends BaseController {
|
public class UserController {
|
||||||
|
|
||||||
private final ISysUserService iSysUserService;
|
private final ISysUserService iSysUserService;
|
||||||
private final ISysUserRoleService iSysUserRoleService;
|
private final ISysUserRoleService iSysUserRoleService;
|
||||||
|
@ -68,7 +68,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||||||
menu.getRoles()
|
menu.getRoles()
|
||||||
));
|
));
|
||||||
// 菜单显示隐藏
|
// 菜单显示隐藏
|
||||||
routerVO.setHidden(!GlobalConstants.VISIBLE_SHOW_VALUE.equals(menu.getVisible()) ? true : false);
|
routerVO.setHidden(!GlobalConstants.STATUS_YES.equals(menu.getVisible()) );
|
||||||
List<RouterVO> children = recursionForRoutes(menu.getId(), menuList);
|
List<RouterVO> children = recursionForRoutes(menu.getId(), menuList);
|
||||||
routerVO.setChildren(children);
|
routerVO.setChildren(children);
|
||||||
if(CollectionUtil.isNotEmpty(children)){
|
if(CollectionUtil.isNotEmpty(children)){
|
||||||
|
@ -3,8 +3,8 @@ package com.youlai.auth.config;
|
|||||||
import cn.hutool.http.HttpStatus;
|
import cn.hutool.http.HttpStatus;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.youlai.auth.domain.User;
|
import com.youlai.auth.domain.User;
|
||||||
import com.youlai.auth.service.JdbcClientDetailsServiceImpl;
|
import com.youlai.auth.service.impl.JdbcClientDetailsServiceImpl;
|
||||||
import com.youlai.auth.service.UserDetailsServiceImpl;
|
import com.youlai.auth.service.impl.UserDetailsServiceImpl;
|
||||||
import com.youlai.common.constant.AuthConstants;
|
import com.youlai.common.constant.AuthConstants;
|
||||||
import com.youlai.common.result.Result;
|
import com.youlai.common.result.Result;
|
||||||
import com.youlai.common.result.ResultCode;
|
import com.youlai.common.result.ResultCode;
|
||||||
@ -135,9 +135,8 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
|
|||||||
return (accessToken, authentication) -> {
|
return (accessToken, authentication) -> {
|
||||||
Map<String, Object> map = new HashMap<>(8);
|
Map<String, Object> map = new HashMap<>(8);
|
||||||
User user = (User) authentication.getUserAuthentication().getPrincipal();
|
User user = (User) authentication.getUserAuthentication().getPrincipal();
|
||||||
map.put(AuthConstants.USER_ID_KEY, user.getId());
|
map.put("userId", user.getId());
|
||||||
map.put(AuthConstants.CLIENT_ID_KEY, user.getClientId());
|
map.put("username", user.getUsername());
|
||||||
map.put(AuthConstants.USER_NAME_KEY, user.getUsername());
|
|
||||||
((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(map);
|
((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(map);
|
||||||
return accessToken;
|
return accessToken;
|
||||||
};
|
};
|
||||||
|
@ -1,27 +1,14 @@
|
|||||||
package com.youlai.auth.controller;
|
package com.youlai.auth.controller;
|
||||||
|
|
||||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
import com.youlai.auth.service.IAuthService;
|
||||||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
||||||
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import com.youlai.common.constant.AuthConstants;
|
import com.youlai.common.constant.AuthConstants;
|
||||||
import com.youlai.common.constant.GlobalConstants;
|
|
||||||
import com.youlai.common.result.Result;
|
|
||||||
import com.youlai.common.result.ResultCode;
|
|
||||||
import com.youlai.common.web.exception.BizException;
|
|
||||||
import com.youlai.common.web.util.RequestUtils;
|
import com.youlai.common.web.util.RequestUtils;
|
||||||
import com.youlai.mall.ums.api.MemberFeignClient;
|
|
||||||
import com.youlai.mall.ums.pojo.domain.UmsMember;
|
|
||||||
import com.youlai.mall.ums.pojo.dto.AuthMemberDTO;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
||||||
import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
|
import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
|
||||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
@ -42,6 +29,8 @@ import java.util.Map;
|
|||||||
public class AuthController {
|
public class AuthController {
|
||||||
|
|
||||||
private TokenEndpoint tokenEndpoint;
|
private TokenEndpoint tokenEndpoint;
|
||||||
|
private IAuthService weAppAuthServiceImpl;
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "OAuth2认证", notes = "login")
|
@ApiOperation(value = "OAuth2认证", notes = "login")
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@ -51,11 +40,6 @@ public class AuthController {
|
|||||||
@ApiImplicitParam(name = "refresh_token", value = "刷新token"),
|
@ApiImplicitParam(name = "refresh_token", value = "刷新token"),
|
||||||
@ApiImplicitParam(name = "username", defaultValue = "admin", value = "登录用户名"),
|
@ApiImplicitParam(name = "username", defaultValue = "admin", value = "登录用户名"),
|
||||||
@ApiImplicitParam(name = "password", defaultValue = "123456", value = "登录密码"),
|
@ApiImplicitParam(name = "password", defaultValue = "123456", value = "登录密码"),
|
||||||
|
|
||||||
// 微信小程序认证参数(无小程序可忽略)
|
|
||||||
@ApiImplicitParam(name = "code", value = "小程序授权code"),
|
|
||||||
@ApiImplicitParam(name = "encryptedData", value = "包括敏感数据在内的完整用户信息的加密数据"),
|
|
||||||
@ApiImplicitParam(name = "iv", value = "加密算法的初始向量"),
|
|
||||||
})
|
})
|
||||||
@PostMapping("/token")
|
@PostMapping("/token")
|
||||||
public OAuth2AccessToken postAccessToken(
|
public OAuth2AccessToken postAccessToken(
|
||||||
@ -74,7 +58,7 @@ public class AuthController {
|
|||||||
String clientId = RequestUtils.getAuthClientId();
|
String clientId = RequestUtils.getAuthClientId();
|
||||||
switch (clientId) {
|
switch (clientId) {
|
||||||
case AuthConstants.WEAPP_CLIENT_ID: // 微信认证
|
case AuthConstants.WEAPP_CLIENT_ID: // 微信认证
|
||||||
oAuth2AccessToken = this.handleForWxAuth(principal, parameters);
|
oAuth2AccessToken = weAppAuthServiceImpl.login(principal, parameters);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody();
|
oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody();
|
||||||
@ -84,57 +68,4 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private WxMaService wxService;
|
|
||||||
private MemberFeignClient memberFeignClient;
|
|
||||||
private PasswordEncoder passwordEncoder;
|
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
public OAuth2AccessToken handleForWxAuth(Principal principal, Map<String, String> parameters) throws HttpRequestMethodNotSupportedException {
|
|
||||||
|
|
||||||
String code = parameters.get("code");
|
|
||||||
|
|
||||||
if (StrUtil.isBlank(code)) {
|
|
||||||
throw new BizException("code不能为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
WxMaJscode2SessionResult session = null;
|
|
||||||
// 根据授权code获取微信用户信息
|
|
||||||
session = wxService.getUserService().getSessionInfo(code);
|
|
||||||
String openid = session.getOpenid();
|
|
||||||
String sessionKey = session.getSessionKey();
|
|
||||||
|
|
||||||
Result<AuthMemberDTO> result = memberFeignClient.getUserByOpenid(openid);
|
|
||||||
|
|
||||||
if (ResultCode.USER_NOT_EXIST.getCode().equals(result.getCode())) { // 微信授权登录 会员信息不存在时 注册会员
|
|
||||||
String encryptedData = parameters.get("encryptedData");
|
|
||||||
String iv = parameters.get("iv");
|
|
||||||
|
|
||||||
WxMaUserInfo userInfo = wxService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
|
|
||||||
if (userInfo == null) {
|
|
||||||
throw new BizException("获取用户信息失败");
|
|
||||||
}
|
|
||||||
UmsMember user = new UmsMember()
|
|
||||||
.setNickname(userInfo.getNickName())
|
|
||||||
.setAvatar(userInfo.getAvatarUrl())
|
|
||||||
.setGender(Integer.valueOf(userInfo.getGender()))
|
|
||||||
.setOpenid(openid)
|
|
||||||
.setUsername(openid)
|
|
||||||
.setPassword(passwordEncoder.encode(openid).replace(AuthConstants.BCRYPT, Strings.EMPTY)) // 加密密码移除前缀加密方式 {bcrypt}
|
|
||||||
.setStatus(GlobalConstants.STATUS_NORMAL_VALUE);
|
|
||||||
|
|
||||||
Result res = memberFeignClient.add(user);
|
|
||||||
if (!ResultCode.SUCCESS.getCode().equals(res.getCode())) {
|
|
||||||
throw new BizException("注册会员失败");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// oauth2认证参数对应授权登录时注册会员的username、password信息,模拟通过oauth2的密码模式认证生成JWT
|
|
||||||
parameters.put("username", openid);
|
|
||||||
parameters.put("password", openid);
|
|
||||||
|
|
||||||
OAuth2AccessToken oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody();
|
|
||||||
return oAuth2AccessToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.youlai.auth.service;
|
||||||
|
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
||||||
|
|
||||||
|
import java.security.Principal;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author haoxr
|
||||||
|
* @description TODO
|
||||||
|
* @createTime 2021/5/20 23:35
|
||||||
|
*/
|
||||||
|
public interface IAuthService {
|
||||||
|
|
||||||
|
OAuth2AccessToken login(Principal principal, Map<String, String> parameters) ;
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.youlai.auth.service;
|
package com.youlai.auth.service.impl;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.springframework.security.oauth2.provider.ClientDetails;
|
import org.springframework.security.oauth2.provider.ClientDetails;
|
@ -1,4 +1,4 @@
|
|||||||
package com.youlai.auth.service;
|
package com.youlai.auth.service.impl;
|
||||||
|
|
||||||
import com.youlai.admin.api.UserFeignClient;
|
import com.youlai.admin.api.UserFeignClient;
|
||||||
import com.youlai.admin.pojo.dto.UserDTO;
|
import com.youlai.admin.pojo.dto.UserDTO;
|
@ -0,0 +1,97 @@
|
|||||||
|
package com.youlai.auth.service.impl;
|
||||||
|
|
||||||
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||||
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||||
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.youlai.auth.service.IAuthService;
|
||||||
|
import com.youlai.common.constant.AuthConstants;
|
||||||
|
import com.youlai.common.constant.GlobalConstants;
|
||||||
|
import com.youlai.common.result.Result;
|
||||||
|
import com.youlai.common.result.ResultCode;
|
||||||
|
import com.youlai.common.web.exception.BizException;
|
||||||
|
import com.youlai.mall.ums.api.MemberFeignClient;
|
||||||
|
import com.youlai.mall.ums.pojo.domain.UmsMember;
|
||||||
|
import com.youlai.mall.ums.pojo.dto.AuthMemberDTO;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
import org.apache.logging.log4j.util.Strings;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
||||||
|
import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.security.Principal;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author haoxr
|
||||||
|
* @description 微信小程序认证接口
|
||||||
|
* @createTime 2021/5/20 23:37
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class WeAppAuthServiceImpl implements IAuthService {
|
||||||
|
private WxMaService wxService;
|
||||||
|
private MemberFeignClient memberFeignClient;
|
||||||
|
private PasswordEncoder passwordEncoder;
|
||||||
|
private TokenEndpoint tokenEndpoint;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param principal
|
||||||
|
* @param parameters code=小程序授权code
|
||||||
|
* encryptedData=包括敏感数据在内的完整用户信息的加密数据
|
||||||
|
* iv=加密算法的初始向量
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
|
public OAuth2AccessToken login(Principal principal, Map<String, String> parameters) {
|
||||||
|
|
||||||
|
String code = parameters.get("code");
|
||||||
|
|
||||||
|
if (StrUtil.isBlank(code)) {
|
||||||
|
throw new BizException("code不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
WxMaJscode2SessionResult session = null;
|
||||||
|
// 根据授权code获取微信用户信息
|
||||||
|
session = wxService.getUserService().getSessionInfo(code);
|
||||||
|
String openid = session.getOpenid();
|
||||||
|
String sessionKey = session.getSessionKey();
|
||||||
|
|
||||||
|
Result<AuthMemberDTO> result = memberFeignClient.getUserByOpenid(openid);
|
||||||
|
|
||||||
|
if (ResultCode.USER_NOT_EXIST.getCode().equals(result.getCode())) { // 微信授权登录 会员信息不存在时 注册会员
|
||||||
|
String encryptedData = parameters.get("encryptedData");
|
||||||
|
String iv = parameters.get("iv");
|
||||||
|
|
||||||
|
WxMaUserInfo userInfo = wxService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
|
||||||
|
if (userInfo == null) {
|
||||||
|
throw new BizException("获取用户信息失败");
|
||||||
|
}
|
||||||
|
UmsMember user = new UmsMember()
|
||||||
|
.setNickname(userInfo.getNickName())
|
||||||
|
.setAvatar(userInfo.getAvatarUrl())
|
||||||
|
.setGender(Integer.valueOf(userInfo.getGender()))
|
||||||
|
.setOpenid(openid)
|
||||||
|
.setUsername(openid)
|
||||||
|
.setPassword(passwordEncoder.encode(openid).replace(AuthConstants.BCRYPT, Strings.EMPTY)) // 加密密码移除前缀加密方式 {bcrypt}
|
||||||
|
.setStatus(GlobalConstants.STATUS_YES);
|
||||||
|
|
||||||
|
Result res = memberFeignClient.add(user);
|
||||||
|
if (!ResultCode.SUCCESS.getCode().equals(res.getCode())) {
|
||||||
|
throw new BizException("注册会员失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// oauth2认证参数对应授权登录时注册会员的username、password信息,模拟通过oauth2的密码模式认证生成JWT
|
||||||
|
parameters.put("username", openid);
|
||||||
|
parameters.put("password", openid);
|
||||||
|
|
||||||
|
OAuth2AccessToken oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody();
|
||||||
|
return oAuth2AccessToken;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
package com.youlai.common.base;
|
|
||||||
|
|
||||||
public class BaseController<T> {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -2,9 +2,8 @@ package com.youlai.common.constant;
|
|||||||
|
|
||||||
public interface GlobalConstants {
|
public interface GlobalConstants {
|
||||||
|
|
||||||
Integer STATUS_NORMAL_VALUE = 1;
|
Integer STATUS_YES = 1;
|
||||||
|
Integer STATUS_NO= 0;
|
||||||
Integer VISIBLE_SHOW_VALUE = 1;
|
|
||||||
|
|
||||||
String DEFAULT_USER_PASSWORD = "123456";
|
String DEFAULT_USER_PASSWORD = "123456";
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>common-elasticsearch</artifactId>
|
<artifactId>common-es</artifactId>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
@ -20,45 +20,6 @@
|
|||||||
</pattern>
|
</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- Logstash收集登录日志输出到ElasticSearch -->
|
|
||||||
<appender name="LOGIN_LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
|
|
||||||
<destination>g.youlai.tech:5044</destination>
|
|
||||||
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
|
|
||||||
<providers>
|
|
||||||
<timestamp>
|
|
||||||
<timeZone>Asia/Shanghai</timeZone>
|
|
||||||
</timestamp>
|
|
||||||
<!--自定义日志输出格式-->
|
|
||||||
<pattern>
|
|
||||||
<pattern>
|
|
||||||
{
|
|
||||||
"project": "${APP_NAME}",
|
|
||||||
"date": "%X{date}", <!-- 索引名时区同步 -->
|
|
||||||
"action":"login",
|
|
||||||
"pid": "${PID:-}",
|
|
||||||
"thread": "%thread",
|
|
||||||
"message": "%message",
|
|
||||||
"elapsedTime": "%X{elapsedTime}",
|
|
||||||
"username":"%X{username}",
|
|
||||||
"clientIP": "%X{clientIP}",
|
|
||||||
"region":"%X{region}",
|
|
||||||
"token":"%X{token}",
|
|
||||||
"loginTime": "%date{\"yyyy-MM-dd HH:mm:ss\"}",
|
|
||||||
"description":"%X{description}"
|
|
||||||
}
|
|
||||||
</pattern>
|
|
||||||
</pattern>
|
|
||||||
</providers>
|
|
||||||
</encoder>
|
|
||||||
<keepAliveDuration>5 minutes</keepAliveDuration>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- additivity 默认是true,标识该logger的日志会在root的appender再打印一次 -->
|
|
||||||
<logger name="com.youlai.common.web.aspect.LoginLogAspect" level="INFO" additivity="false">
|
|
||||||
<appender-ref ref="LOGIN_LOGSTASH"/>
|
|
||||||
</logger>
|
|
||||||
|
|
||||||
<logger name="com.alibaba.nacos.client.naming" level="ERROR" additivity="false">
|
<logger name="com.alibaba.nacos.client.naming" level="ERROR" additivity="false">
|
||||||
<appender-ref ref="CONSOLE"/>
|
<appender-ref ref="CONSOLE"/>
|
||||||
</logger>
|
</logger>
|
||||||
|
@ -19,6 +19,6 @@
|
|||||||
<module>common-web</module>
|
<module>common-web</module>
|
||||||
<module>common-mybatis</module>
|
<module>common-mybatis</module>
|
||||||
<module>common-rabbitmq</module>
|
<module>common-rabbitmq</module>
|
||||||
<module>common-elasticsearch</module>
|
<module>common-es</module>
|
||||||
</modules>
|
</modules>
|
||||||
</project>
|
</project>
|
||||||
|
Loading…
Reference in New Issue
Block a user