|
@@ -1,7 +1,10 @@
|
|
|
package com.qs.mp.framework.web.service;
|
|
|
|
|
|
+import com.qs.mp.channel.domain.Channel;
|
|
|
+import com.qs.mp.channel.service.IChannelService;
|
|
|
import com.qs.mp.common.constant.Constants;
|
|
|
import com.qs.mp.common.core.redis.RedisCache;
|
|
|
+import com.qs.mp.common.enums.UserIdentityEnum;
|
|
|
import com.qs.mp.common.exception.ServiceException;
|
|
|
import com.qs.mp.common.exception.user.CaptchaException;
|
|
|
import com.qs.mp.common.exception.user.CaptchaExpireException;
|
|
@@ -18,6 +21,7 @@ import com.qs.mp.sms.domain.SmsCode;
|
|
|
import com.qs.mp.system.domain.SysUser;
|
|
|
import com.qs.mp.system.service.ISysConfigService;
|
|
|
import com.qs.mp.system.service.ISysUserService;
|
|
|
+
|
|
|
import javax.annotation.Resource;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -30,7 +34,7 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
/**
|
|
|
* 登录校验方法
|
|
|
- *
|
|
|
+ *
|
|
|
* @author ygp
|
|
|
*/
|
|
|
@Component
|
|
@@ -47,16 +51,19 @@ public class SysLoginService
|
|
|
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
private ISysUserService userService;
|
|
|
|
|
|
@Autowired
|
|
|
private ISysConfigService configService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IChannelService channelService;
|
|
|
+
|
|
|
/**
|
|
|
* 登录验证
|
|
|
- *
|
|
|
+ *
|
|
|
* @param username 用户名
|
|
|
* @param password 密码
|
|
|
* @param code 验证码
|
|
@@ -91,6 +98,11 @@ public class SysLoginService
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
|
recordLoginInfo(loginUser.getUser());
|
|
|
+
|
|
|
+ loginUser.setIdentity(UserIdentityEnum.valueOf(identity));
|
|
|
+ if (UserIdentityEnum.isChannel(loginUser.getIdentity())) {
|
|
|
+ fillChannelInfo(loginUser);
|
|
|
+ }
|
|
|
/*
|
|
|
// 根据用户身份,设置对应的属性
|
|
|
loginUser.setIdentity(UserIdentityEnum.valueOf(identity));
|
|
@@ -104,10 +116,10 @@ public class SysLoginService
|
|
|
// 生成token
|
|
|
return tokenService.createToken(loginUser);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 登录验证
|
|
|
- *
|
|
|
+ *
|
|
|
* @param username 用户名
|
|
|
* @param code 验证码
|
|
|
* @param uuid 唯一标识
|
|
@@ -118,7 +130,7 @@ public class SysLoginService
|
|
|
{
|
|
|
// 校验短信验证码
|
|
|
validateSMSCaptcha(username, code, uuid);
|
|
|
-
|
|
|
+
|
|
|
// 用户验证
|
|
|
Authentication authentication = null;
|
|
|
try
|
|
@@ -143,6 +155,11 @@ public class SysLoginService
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
|
recordLoginInfo(loginUser.getUser());
|
|
|
+
|
|
|
+ loginUser.setIdentity(UserIdentityEnum.valueOf(identity));
|
|
|
+ if (UserIdentityEnum.isChannel(loginUser.getIdentity())) {
|
|
|
+ fillChannelInfo(loginUser);
|
|
|
+ }
|
|
|
/*
|
|
|
// 根据用户身份,设置对应的属性
|
|
|
loginUser.setIdentity(UserIdentityEnum.valueOf(identity));
|
|
@@ -185,6 +202,11 @@ public class SysLoginService
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(smsCode.getMobile(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
|
recordLoginInfo(loginUser.getUser());
|
|
|
+
|
|
|
+ loginUser.setIdentity(UserIdentityEnum.valueOf(smsCode.getIdentity()));
|
|
|
+ if (UserIdentityEnum.isChannel(loginUser.getIdentity())) {
|
|
|
+ fillChannelInfo(loginUser);
|
|
|
+ }
|
|
|
/*
|
|
|
// 根据用户身份,设置对应的属性
|
|
|
loginUser.setIdentity(UserIdentityEnum.valueOf(smsCode.getIdentity()));
|
|
@@ -206,7 +228,7 @@ public class SysLoginService
|
|
|
|
|
|
/**
|
|
|
* 校验验证码
|
|
|
- *
|
|
|
+ *
|
|
|
* @param username 用户名
|
|
|
* @param code 验证码
|
|
|
* @param uuid 唯一标识
|
|
@@ -228,10 +250,10 @@ public class SysLoginService
|
|
|
throw new CaptchaException();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 校验验证码
|
|
|
- *
|
|
|
+ *
|
|
|
* @param username 用户名
|
|
|
* @param code 短信验证码
|
|
|
* @param uuid 唯一标识
|
|
@@ -264,4 +286,26 @@ public class SysLoginService
|
|
|
userService.updateUserProfile(user);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 填充注入Channel 渠道/经销商 信息
|
|
|
+ * @param loginUser
|
|
|
+ */
|
|
|
+ public void fillChannelInfo(LoginUser loginUser){
|
|
|
+ Channel channel = channelService.getChannelByUserId(loginUser.getUserId());
|
|
|
+ if (null != channel && null != channel.getId()){
|
|
|
+ // 校验渠道身份标识
|
|
|
+ if (loginUser.getIdentity() == UserIdentityEnum.CHANNEL && channel.getLevel() <= 0) {
|
|
|
+ throw new ServiceException("此账号的渠道不存在");
|
|
|
+ } else if (loginUser.getIdentity() == UserIdentityEnum.SALESITE && channel.getLevel() != 0) {
|
|
|
+ throw new ServiceException("此账号的经销商不存在");
|
|
|
+ }
|
|
|
+ loginUser.setChannelId(channel.getId());
|
|
|
+ loginUser.setChannelNo(channel.getChannelNo());
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("登录账号不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|