|
@@ -1,10 +1,9 @@
|
|
|
package com.fdkankan.platform.user.service.sso;
|
|
|
|
|
|
-import com.fdkankan.common.config.RedisDefaultConfig;
|
|
|
import com.fdkankan.common.constant.*;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.common.user.SSOLoginHelper;
|
|
|
import com.fdkankan.common.user.SSOUser;
|
|
|
-import com.fdkankan.common.util.JwtUtil;
|
|
|
import com.fdkankan.common.util.RandomUtil;
|
|
|
import com.fdkankan.common.util.SecurityUtil;
|
|
|
import com.fdkankan.common.util.SsoUtil;
|
|
@@ -18,14 +17,14 @@ import com.fdkankan.platform.user.request.RequestUser;
|
|
|
import com.fdkankan.platform.user.service.IUserService;
|
|
|
import com.fdkankan.platform.user.vo.ResponseUser;
|
|
|
import com.fdkankan.platform.user.vo.SSOUserVo;
|
|
|
+import com.fdkankan.redis.constant.RedisKey;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Set;
|
|
|
|
|
@@ -43,8 +42,10 @@ public class AppService {
|
|
|
private MsgService msgService;
|
|
|
@Autowired
|
|
|
private RegisterService registerService;
|
|
|
- @Resource
|
|
|
- private RedisTemplate<String,String> redisTemplate;
|
|
|
+ @Autowired
|
|
|
+ private SSOLoginHelper ssoLoginHelper;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
|
|
public String qrCodeLogin(RequestUser user) {
|
|
|
if(StringUtils.isEmpty(user.getAppUserName()) || StringUtils.isEmpty(user.getAppPassword())
|
|
@@ -59,7 +60,7 @@ public class AppService {
|
|
|
if (entity == null ){
|
|
|
throw new BusinessException(AppConstant.FAILURE_CODE_4012, AppConstant.FAILURE_MSG_4012);
|
|
|
}
|
|
|
- redisTemplate.opsForValue().set(user.getUuid(),user.getAppUserName(), RedisDefaultConfig.DEFAULT_EXPIRE_TIME, RedisDefaultConfig.DEFAULT_TIME_UNIT);
|
|
|
+ redisUtil.set(user.getUuid(),user.getAppUserName(), RedisKey.EXPIRE_TIME_2_HOUR);
|
|
|
return ServerCode.SUCCESS.message();
|
|
|
}
|
|
|
|
|
@@ -71,9 +72,7 @@ public class AppService {
|
|
|
if (cameraEntity == null){
|
|
|
throw new BusinessException(ErrorCode.PASSWORD_ERROR);
|
|
|
}
|
|
|
- String token = JwtUtil.createJWT(-1, cameraEntity.getChildName(), LoginType.APP.name());
|
|
|
- String key = SsoUtil.PREFIX_CACHE_CAMERA + cameraEntity.getChildName();
|
|
|
- redisTemplate.opsForValue().set(key, token, RedisDefaultConfig.CAMERA_EXPIRE_TIME,RedisDefaultConfig.DEFAULT_TIME_UNIT);
|
|
|
+ String token = ssoLoginHelper.login(LoginType.APP.name(), cameraEntity.getChildName(), RedisKey.CAMERA_EXPIRE_7_TIME);
|
|
|
HashMap<String,String> obj = new HashMap<>();
|
|
|
obj.put("token", token);
|
|
|
return obj;
|
|
@@ -98,23 +97,18 @@ public class AppService {
|
|
|
if(ssoUser == null){
|
|
|
throw new BusinessException(ErrorCode.USER_NOT_EXIST);
|
|
|
}
|
|
|
- redisTemplate.delete(SsoUtil.PREFIX_MSG_AUTH_CODE + user.getPhoneNum());
|
|
|
+ ssoLoginHelper.logout(LoginType.APP.name(),user.getPhoneNum());
|
|
|
return this.setRedisToken(ssoUser,dbUser,user.getCameraType());
|
|
|
}
|
|
|
|
|
|
private SSOUserVo setRedisToken(SSOUser ssoUser,User userEntity,Integer CameraType){
|
|
|
- String key = SsoUtil.PREFIX_CACHE_CAMERA + ssoUser.getUserName();
|
|
|
- String token = JwtUtil.createJWT(-1, ssoUser.getUserName(),LoginType.APP.name());
|
|
|
- redisTemplate.opsForValue().set(key, token, RedisDefaultConfig.USER_EXPIRE_TIME,RedisDefaultConfig.DEFAULT_TIME_UNIT);
|
|
|
+ String token = ssoLoginHelper.login(LoginType.APP.name(), ssoUser.getUserName());
|
|
|
Integer cameraType = CameraType == null ? 4 : CameraType;
|
|
|
return userService.getUserInfoByUser(cameraType, userEntity, token);
|
|
|
}
|
|
|
|
|
|
public String logout(String token) {
|
|
|
- String userName = JwtUtil.getUsername(token);
|
|
|
- if(redisTemplate.hasKey(SsoUtil.PREFIX_CACHE_CAMERA + userName)){
|
|
|
- redisTemplate.delete(SsoUtil.PREFIX_CACHE_CAMERA + userName);
|
|
|
- }
|
|
|
+ ssoLoginHelper.logout(token);
|
|
|
return ServerCode.SUCCESS.message();
|
|
|
}
|
|
|
|
|
@@ -170,7 +164,7 @@ public class AppService {
|
|
|
}
|
|
|
|
|
|
//验证码校验
|
|
|
- String codeValue = redisTemplate.opsForValue().get(SsoUtil.PREFIX_MSG_AUTH_CODE + user.getPhoneNum());
|
|
|
+ String codeValue = redisUtil.get(SsoUtil.PREFIX_MSG_AUTH_CODE + user.getPhoneNum());
|
|
|
if (StringUtils.isEmpty(codeValue)){
|
|
|
throw new BusinessException(ErrorCode.V_CODE_ERROR);
|
|
|
}
|
|
@@ -178,7 +172,7 @@ public class AppService {
|
|
|
throw new BusinessException(ErrorCode.V_CODE_ERROR);
|
|
|
}
|
|
|
userEntity.setPassword(SecurityUtil.MD5(user.getPassword()));
|
|
|
- redisTemplate.delete(SsoUtil.PREFIX_MSG_AUTH_CODE + user.getPhoneNum());
|
|
|
+ redisUtil.del(SsoUtil.PREFIX_MSG_AUTH_CODE + user.getPhoneNum());
|
|
|
if(!userService.updateById(userEntity)){
|
|
|
throw new BusinessException(ErrorCode.ERROR_MSG);
|
|
|
}
|