Commit 330c5613 authored by gaoguangjing's avatar gaoguangjing

小程序登录修改

parent 80a545ab
...@@ -531,7 +531,7 @@ public class UserController implements IBaseController { ...@@ -531,7 +531,7 @@ public class UserController implements IBaseController {
} else if (!wechatRelateUserIfNecessary(user, request)) { } else if (!wechatRelateUserIfNecessary(user, request)) {
return JsonResult.buildErrorStateResult("登录时微信关联失败", null); return JsonResult.buildErrorStateResult("登录时微信关联失败", null);
} }
LoginProperties loginProperties = new LoginProperties("", 1, channelId, createdFrom, appChannel, merchant.getId(), merchant.getName()); LoginProperties loginProperties = new LoginProperties("", 1, channelId, createdFrom, appChannel, merchant.getId(), merchant.getName(), null);
AuthBean authBean=sessionService.createSession(user, loginProperties); AuthBean authBean=sessionService.createSession(user, loginProperties);
if(authBean!=null){ if(authBean!=null){
authBean.setRegister(false); authBean.setRegister(false);
...@@ -596,7 +596,7 @@ public class UserController implements IBaseController { ...@@ -596,7 +596,7 @@ public class UserController implements IBaseController {
} else if (!wechatRelateUserIfNecessary(user, request)) { } else if (!wechatRelateUserIfNecessary(user, request)) {
return JsonResult.buildErrorStateResult("登录时微信关联失败", null); return JsonResult.buildErrorStateResult("登录时微信关联失败", null);
} }
LoginProperties loginProperties = new LoginProperties("", 4, channelId, createdFrom, appChannel, merchant.getId(), merchant.getName()); LoginProperties loginProperties = new LoginProperties("", 4, channelId, createdFrom, appChannel, merchant.getId(), merchant.getName(), null);
//尝试解锁 //尝试解锁
lockIpv4Service.unLockPhone(user.getPhoneNo()); lockIpv4Service.unLockPhone(user.getPhoneNo());
//更新session //更新session
......
...@@ -334,7 +334,7 @@ public class WeChatController implements IBaseController { ...@@ -334,7 +334,7 @@ public class WeChatController implements IBaseController {
private String createUserSession(User user, Merchant merchant, String redirect, String domain, Long registerFrom) { private String createUserSession(User user, Merchant merchant, String redirect, String domain, Long registerFrom) {
log.info("[WeChatController][createUserSession]微信授权及跳转:user:{},merchant:{},redirect:{},domain:{},registerFrom:{}", user, merchant, redirect, domain, registerFrom); log.info("[WeChatController][createUserSession]微信授权及跳转:user:{},merchant:{},redirect:{},domain:{},registerFrom:{}", user, merchant, redirect, domain, registerFrom);
LoginProperties loginProperties = new LoginProperties("", 4, Constants.Channel.WECHAT, registerFrom, String.valueOf(Constants.Channel.WECHAT), merchant.getId(), merchant.getName()); LoginProperties loginProperties = new LoginProperties("", 4, Constants.Channel.WECHAT, registerFrom, String.valueOf(Constants.Channel.WECHAT), merchant.getId(), merchant.getName(), null);
if (StringUtils.isEmpty(redirect) || Constants.REDIRECT.equals(redirect)) { if (StringUtils.isEmpty(redirect) || Constants.REDIRECT.equals(redirect)) {
log.info("微信登录:redirect为null,走正常流程."); log.info("微信登录:redirect为null,走正常流程.");
if (Constants.MERCHANT_BAITIAO.equals(merchant.getName())) { if (Constants.MERCHANT_BAITIAO.equals(merchant.getName())) {
...@@ -362,7 +362,7 @@ public class WeChatController implements IBaseController { ...@@ -362,7 +362,7 @@ public class WeChatController implements IBaseController {
} }
private String loginInWechatWithSessionCreated(User user, Merchant merchant, String target, Long channelId, String domain, Long registerFrom) { private String loginInWechatWithSessionCreated(User user, Merchant merchant, String target, Long channelId, String domain, Long registerFrom) {
LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, String.valueOf(Constants.Channel.WECHAT), merchant.getId(), merchant.getName()); LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, String.valueOf(Constants.Channel.WECHAT), merchant.getId(), merchant.getName(), null);
AuthBean authBean = sessionService.createSession(user, loginProperties); AuthBean authBean = sessionService.createSession(user, loginProperties);
log.info("[WeChatController][loginInWechatWithSessionCreated]微信授权及跳转:user:{},merchant:{},target:{},channelId:{},domain:{},registerFrom:{}", user, merchant, target, channelId, domain, registerFrom); log.info("[WeChatController][loginInWechatWithSessionCreated]微信授权及跳转:user:{},merchant:{},target:{},channelId:{},domain:{},registerFrom:{}", user, merchant, target, channelId, domain, registerFrom);
return domain + "/landing?token=" + authBean.getToken() + "&registerFrom=" + registerFrom + "&channelId=" + channelId + "&key=" + merchant.getName() + "&target=" + target; return domain + "/landing?token=" + authBean.getToken() + "&registerFrom=" + registerFrom + "&channelId=" + channelId + "&key=" + merchant.getName() + "&target=" + target;
......
...@@ -15,6 +15,8 @@ import cn.quantgroup.xyqb.security.AuthorizationPoint; ...@@ -15,6 +15,8 @@ import cn.quantgroup.xyqb.security.AuthorizationPoint;
import cn.quantgroup.xyqb.service.merchant.IMerchantService; import cn.quantgroup.xyqb.service.merchant.IMerchantService;
import cn.quantgroup.xyqb.service.register.IUserRegisterService; import cn.quantgroup.xyqb.service.register.IUserRegisterService;
import cn.quantgroup.xyqb.service.session.ISessionService; import cn.quantgroup.xyqb.service.session.ISessionService;
import cn.quantgroup.xyqb.service.user.IOauthClientDetailsService;
import cn.quantgroup.xyqb.service.user.IOauthLoginInfoService;
import cn.quantgroup.xyqb.service.user.IUserService; import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.util.IpUtil; import cn.quantgroup.xyqb.util.IpUtil;
import cn.quantgroup.xyqb.util.ValidationUtil; import cn.quantgroup.xyqb.util.ValidationUtil;
...@@ -51,6 +53,8 @@ public class AppController implements IBaseController { ...@@ -51,6 +53,8 @@ public class AppController implements IBaseController {
@Autowired @Autowired
private IUserService userService; private IUserService userService;
@Autowired @Autowired
private IOauthLoginInfoService oauthLoginInfoService;
@Autowired
private IMerchantService merchantService; private IMerchantService merchantService;
@Autowired @Autowired
private IUserRegisterService userRegisterService; private IUserRegisterService userRegisterService;
...@@ -92,7 +96,7 @@ public class AppController implements IBaseController { ...@@ -92,7 +96,7 @@ public class AppController implements IBaseController {
if (merchant == null) { if (merchant == null) {
result = JsonResult.buildErrorStateResult("无效的商户", null); result = JsonResult.buildErrorStateResult("无效的商户", null);
}else{ }else{
LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, appChannel, merchant.getId(), merchant.getName()); LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, appChannel, merchant.getId(), merchant.getName(), null);
AuthBean bean = sessionService.createSession(user, loginProperties); AuthBean bean = sessionService.createSession(user, loginProperties);
LoginInfo.LoginContext context = new LoginInfo.LoginContext(); LoginInfo.LoginContext context = new LoginInfo.LoginContext();
context.setChannelId(channelId); context.setChannelId(channelId);
...@@ -161,7 +165,7 @@ public class AppController implements IBaseController { ...@@ -161,7 +165,7 @@ public class AppController implements IBaseController {
if (merchant == null) { if (merchant == null) {
return JsonResult.buildErrorStateResult("无效的商户", null); return JsonResult.buildErrorStateResult("无效的商户", null);
} }
LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, appChannel, merchant.getId(), merchant.getName()); LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, appChannel, merchant.getId(), merchant.getName(), null);
AuthBean bean = sessionService.createSession(user, loginProperties); AuthBean bean = sessionService.createSession(user, loginProperties);
log.info("第三方用户登录成功 [AppController] login --> loginFrom:{}, phoneNo:{},appChannel:{}", registerFrom, phoneNo, appChannel); log.info("第三方用户登录成功 [AppController] login --> loginFrom:{}, phoneNo:{},appChannel:{}", registerFrom, phoneNo, appChannel);
return JsonResult.buildSuccessResult("登录成功", bean); return JsonResult.buildSuccessResult("登录成功", bean);
...@@ -221,7 +225,7 @@ public class AppController implements IBaseController { ...@@ -221,7 +225,7 @@ public class AppController implements IBaseController {
if (merchant == null) { if (merchant == null) {
return JsonResult.buildErrorStateResult("无效的商户", null); return JsonResult.buildErrorStateResult("无效的商户", null);
} }
LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, appChannel, merchant.getId(), merchant.getName()); LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, appChannel, merchant.getId(), merchant.getName(), null);
AuthBean bean = sessionService.createSession(user, loginProperties); AuthBean bean = sessionService.createSession(user, loginProperties);
LoginInfo loginInfo = new LoginInfo(); LoginInfo loginInfo = new LoginInfo();
loginInfo.setUser(new UserRet(user)); loginInfo.setUser(new UserRet(user));
...@@ -297,6 +301,7 @@ public class AppController implements IBaseController { ...@@ -297,6 +301,7 @@ public class AppController implements IBaseController {
@RequestParam(required = false, defaultValue = "1") Long registerFrom, @RequestParam(required = false, defaultValue = "1") Long registerFrom,
@RequestParam(required = false, defaultValue = "1") Long channelId, @RequestParam(required = false, defaultValue = "1") Long channelId,
@RequestParam(required = false, defaultValue = "") String appChannel, @RequestParam(required = false, defaultValue = "") String appChannel,
@RequestParam(required = false, defaultValue = "defualt") String tenantId,
HttpServletRequest request) { HttpServletRequest request) {
if (!ValidationUtil.validatePhoneNo(phoneNo)) { if (!ValidationUtil.validatePhoneNo(phoneNo)) {
return JsonResult.buildErrorStateResult(USER_ERROR_OR_PASSWORD_ERROR, null); return JsonResult.buildErrorStateResult(USER_ERROR_OR_PASSWORD_ERROR, null);
...@@ -309,7 +314,11 @@ public class AppController implements IBaseController { ...@@ -309,7 +314,11 @@ public class AppController implements IBaseController {
if (!user.getEnable()) { if (!user.getEnable()) {
return JsonResult.buildErrorStateResult("登录失败", null); return JsonResult.buildErrorStateResult("登录失败", null);
} }
LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, appChannel, null, ""); //校验租户ID tenantId
if (!tenantId.equals("1")) {
oauthLoginInfoService.addLoginInfo(user, tenantId);
}
LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, appChannel, null, "", tenantId);
AuthBean bean = sessionService.createSession(user, loginProperties); AuthBean bean = sessionService.createSession(user, loginProperties);
log.info("第三方用户登录成功 [AppController] login2 --> loginFrom:{}, phoneNo:{},appChannel:{}", registerFrom, phoneNo, appChannel); log.info("第三方用户登录成功 [AppController] login2 --> loginFrom:{}, phoneNo:{},appChannel:{}", registerFrom, phoneNo, appChannel);
return JsonResult.buildSuccessResult("登录成功", bean); return JsonResult.buildSuccessResult("登录成功", bean);
......
...@@ -57,7 +57,7 @@ public class AppletController { ...@@ -57,7 +57,7 @@ public class AppletController {
Long userId = iAppletService.relevance(appletParamEntry); Long userId = iAppletService.relevance(appletParamEntry);
LoginVo loginVo = loginModule.loginByUserId(appletParamEntry.getChannelId(), LoginVo loginVo = loginModule.loginByUserId(appletParamEntry.getChannelId(),
appletParamEntry.getUtmSource(), userId); appletParamEntry.getUtmSource(), userId, null);
return JsonResult return JsonResult
.buildSuccessResultGeneric(loginVo); .buildSuccessResultGeneric(loginVo);
...@@ -68,12 +68,12 @@ public class AppletController { ...@@ -68,12 +68,12 @@ public class AppletController {
*/ */
@Validated @Validated
@PostMapping("/login") @PostMapping("/login")
public JsonResult login(@RequestParam String appName, @RequestParam String openId, String utmSource) { public JsonResult login(@RequestParam String appName, @RequestParam String openId, @RequestParam(required = false, defaultValue = "defualt") String tenantId, String utmSource) {
if (!containsAppName(appName)) { if (!containsAppName(appName)) {
throw new DataException("appName不合法"); throw new DataException("appName不合法");
} }
LoginVo login = iAppletService.login(appName, openId, utmSource); LoginVo login = iAppletService.login(appName, openId, tenantId, utmSource);
return JsonResult.buildSuccessResultGeneric(login); return JsonResult.buildSuccessResultGeneric(login);
} }
......
...@@ -11,5 +11,5 @@ public interface ILoginModule { ...@@ -11,5 +11,5 @@ public interface ILoginModule {
Boolean modifyPwd(VerifyTypeEnum type, String phoneNo, String password, String verify); Boolean modifyPwd(VerifyTypeEnum type, String phoneNo, String password, String verify);
LoginVo loginByUserId(Long channelId, String appChannel, Long userId); LoginVo loginByUserId(Long channelId, String appChannel, Long userId, String tenantId);
} }
...@@ -83,7 +83,7 @@ public class LoginModule implements ILoginModule { ...@@ -83,7 +83,7 @@ public class LoginModule implements ILoginModule {
} }
@Override @Override
public LoginVo loginByUserId(Long channelId, String appChannel, Long userId) { public LoginVo loginByUserId(Long channelId, String appChannel, Long userId, String tenantId) {
User user = userService.findById(userId); User user = userService.findById(userId);
if(null == user){ if(null == user){
throw new DataException("未找到此用户"); throw new DataException("未找到此用户");
...@@ -92,6 +92,7 @@ public class LoginModule implements ILoginModule { ...@@ -92,6 +92,7 @@ public class LoginModule implements ILoginModule {
.createdFrom(user.getRegisteredFrom()) .createdFrom(user.getRegisteredFrom())
.appChannel(appChannel == null ? "" : appChannel) .appChannel(appChannel == null ? "" : appChannel)
.channelId(channelId) .channelId(channelId)
.tenantId(tenantId)
.build(); .build();
AuthBean session = sessionService.createSession(user, loginProperties); AuthBean session = sessionService.createSession(user, loginProperties);
return LoginVo.builder() return LoginVo.builder()
......
...@@ -35,4 +35,6 @@ public class LoginProperties { ...@@ -35,4 +35,6 @@ public class LoginProperties {
private String appChannel = ""; private String appChannel = "";
private Long merchantId = 1L; private Long merchantId = 1L;
private String merchantName = ""; private String merchantName = "";
//租户ID
private String tenantId = "defualt";
} }
...@@ -12,5 +12,5 @@ import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry; ...@@ -12,5 +12,5 @@ import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry;
*/ */
public interface IAppletService { public interface IAppletService {
Long relevance(AppletParamEntry appletParamEntry); Long relevance(AppletParamEntry appletParamEntry);
LoginVo login(String appName, String openId,String utmSource); LoginVo login(String appName, String openId, String tenantId, String utmSource);
} }
...@@ -9,11 +9,13 @@ import cn.quantgroup.xyqb.exception.AppletException; ...@@ -9,11 +9,13 @@ import cn.quantgroup.xyqb.exception.AppletException;
import cn.quantgroup.xyqb.repository.IWeChatUserRepository; import cn.quantgroup.xyqb.repository.IWeChatUserRepository;
import cn.quantgroup.xyqb.service.middleoffice.applet.IAppletService; import cn.quantgroup.xyqb.service.middleoffice.applet.IAppletService;
import cn.quantgroup.xyqb.service.register.IUserRegisterService; import cn.quantgroup.xyqb.service.register.IUserRegisterService;
import cn.quantgroup.xyqb.service.user.IOauthLoginInfoService;
import cn.quantgroup.xyqb.service.user.IUserService; import cn.quantgroup.xyqb.service.user.IUserService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
/** /**
* @author :dongjianhua * @author :dongjianhua
...@@ -34,6 +36,9 @@ public class AppletServiceImpl implements IAppletService { ...@@ -34,6 +36,9 @@ public class AppletServiceImpl implements IAppletService {
private final IUserService userService; private final IUserService userService;
private ILoginModule loginModule; private ILoginModule loginModule;
@Autowired
private IOauthLoginInfoService iOauthLoginInfoService;
@Autowired @Autowired
public AppletServiceImpl(IWeChatUserRepository iWeChatUserRepository, public AppletServiceImpl(IWeChatUserRepository iWeChatUserRepository,
IUserRegisterService iUserRegisterService, IUserRegisterService iUserRegisterService,
...@@ -80,7 +85,7 @@ public class AppletServiceImpl implements IAppletService { ...@@ -80,7 +85,7 @@ public class AppletServiceImpl implements IAppletService {
} }
@Override @Override
public LoginVo login(String appName, String openId, String utmSource) { public LoginVo login(String appName, String openId, String tenantId, String utmSource) {
WechatUserInfo wechatUserInfo = iWeChatUserRepository.findByOpenIdAndAppName(openId, appName); WechatUserInfo wechatUserInfo = iWeChatUserRepository.findByOpenIdAndAppName(openId, appName);
if (null == wechatUserInfo) { if (null == wechatUserInfo) {
log.warn("未找到此用户,appName:{} ,openId:{}", appName, openId); log.warn("未找到此用户,appName:{} ,openId:{}", appName, openId);
...@@ -96,9 +101,12 @@ public class AppletServiceImpl implements IAppletService { ...@@ -96,9 +101,12 @@ public class AppletServiceImpl implements IAppletService {
log.warn("未找到此用户,appName:{} ,openId:{}", appName, openId); log.warn("未找到此用户,appName:{} ,openId:{}", appName, openId);
throw new AppletException("未找到此用户","0401"); throw new AppletException("未找到此用户","0401");
} }
//校验租户ID tenantId
if (!"defualt".equals(tenantId)) {
iOauthLoginInfoService.addLoginInfo(user, tenantId);
}
LoginVo loginVo = loginModule.loginByUserId(user.getRegisteredFrom(), LoginVo loginVo = loginModule.loginByUserId(user.getRegisteredFrom(),
utmSource == null ? "" : utmSource, user.getId()); utmSource == null ? "" : utmSource, user.getId(), tenantId);
return loginVo; return loginVo;
} }
......
...@@ -103,7 +103,11 @@ public class SessionServiceImpl implements ISessionService { ...@@ -103,7 +103,11 @@ public class SessionServiceImpl implements ISessionService {
* @return redisKey. 用来标识这个渠道的用户 Session 是否存在 * @return redisKey. 用来标识这个渠道的用户 Session 是否存在
*/ */
private String generateLoginPropertiesKey(Long userId, LoginProperties properties) { private String generateLoginPropertiesKey(Long userId, LoginProperties properties) {
if (properties.getTenantId() == null || "defualt".equals(properties.getTenantId())) {
return Constants.Session.USER_SESSION_ID_CACHE + ":" + userId + ":" + properties.getMerchantName() + ":" + properties.getCreatedFrom(); return Constants.Session.USER_SESSION_ID_CACHE + ":" + userId + ":" + properties.getMerchantName() + ":" + properties.getCreatedFrom();
}else {
return Constants.Session.USER_SESSION_ID_CACHE + ":" + userId + ":" + properties.getMerchantName() + ":" + properties.getCreatedFrom() + ":" + properties.getTenantId();
}
} }
private String findSessionValueBySessionId(String sessionId) { private String findSessionValueBySessionId(String sessionId) {
......
...@@ -390,7 +390,7 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -390,7 +390,7 @@ public class UserServiceImpl implements IUserService, IBaseController {
} catch (Exception e) { } catch (Exception e) {
log.info("神策埋点出现问题", e); log.info("神策埋点出现问题", e);
} }
LoginProperties loginProperties = new LoginProperties("", 3, channelId, createdFrom, appChannel, merchant.getId(), merchant.getName()); LoginProperties loginProperties = new LoginProperties("", 3, channelId, createdFrom, appChannel, merchant.getId(), merchant.getName(), null);
AuthBean session = sessionService.createSession(user, loginProperties); AuthBean session = sessionService.createSession(user, loginProperties);
session.setRegister(register); session.setRegister(register);
lockIpv4Service.unLockPhone(phoneNo); lockIpv4Service.unLockPhone(phoneNo);
......
Markdown is supported
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