|
|
@@ -1,6 +1,7 @@
|
|
|
package com.cyksj.web.controller.cps;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
|
|
@@ -26,16 +27,22 @@ import com.cyksj.model.dto.CpsAuthDto;
|
|
|
import com.cyksj.model.dto.GzhOAuth2UserInfo;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.request.LoginReq;
|
|
|
+import com.cyksj.model.response.GoogleLoginRep;
|
|
|
+import com.cyksj.model.response.UserAuthLoginResp;
|
|
|
import com.cyksj.model.views.UserInfoView;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.authorization.AuthorizationService;
|
|
|
import com.cyksj.service.cps.CpsManageService;
|
|
|
+import com.cyksj.service.user.UserService;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
|
import com.cyksj.web.util.StpCpsManageUser;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
/*
|
|
|
@@ -47,6 +54,7 @@ import java.util.Optional;
|
|
|
@RestController
|
|
|
@RequestMapping("/cps/manage")
|
|
|
@RequiredArgsConstructor
|
|
|
+@Slf4j
|
|
|
public class CpsBackLoginController {
|
|
|
private final CpsManageService cpsManageService;
|
|
|
|
|
|
@@ -72,6 +80,10 @@ public class CpsBackLoginController {
|
|
|
|
|
|
private final CpsUserGuideRecordMapper cpsUserGuideRecordMapper;
|
|
|
|
|
|
+ private final HttpServletRequest request;
|
|
|
+
|
|
|
+ private final UserService userService;
|
|
|
+
|
|
|
/**
|
|
|
* 获取登录验证码
|
|
|
*/
|
|
|
@@ -228,4 +240,38 @@ public class CpsBackLoginController {
|
|
|
}
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(flag);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * cps谷歌授权登录
|
|
|
+ */
|
|
|
+ @PostMapping("/google/login")
|
|
|
+ public Result<UserAuthLoginResp> googleLogin(LoginReq loginReq, String credential) throws Exception {
|
|
|
+ log.info("google loginReq:{},credential:{}", loginReq, credential);
|
|
|
+ String result = HttpUtil.post("https://galaxyva.com/8081/api/auth/google/login/inner?credential=" + credential, new HashMap<>());
|
|
|
+ log.info("google result:{}", result);
|
|
|
+ GoogleLoginRep googleLoginRep = Jsons.parseObject(Jsons.toMap(result).get("data"), GoogleLoginRep.class);
|
|
|
+ loginReq.setType(3);
|
|
|
+ loginReq.setEmail(googleLoginRep.getEmail());
|
|
|
+ loginReq.setSubject(googleLoginRep.getSubject());
|
|
|
+ User user = userService.webLogin(loginReq, request);
|
|
|
+
|
|
|
+ //是否非cps分销用户
|
|
|
+ UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class)
|
|
|
+ .eq(UserDistribute::getUserId, user.getId())
|
|
|
+ .eq(UserDistribute::getDeleted, 1).last("limit 1"));
|
|
|
+ if (userDistribute == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("只支持分销用户登录");
|
|
|
+ }
|
|
|
+
|
|
|
+ Optional.ofNullable(user.getIsBlack())
|
|
|
+ .ifPresent(black -> {
|
|
|
+ if (black) {
|
|
|
+ throw BusinessRuntimeException.getInstance("您的账号已被注销...");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //写回登陆信息
|
|
|
+ StpCpsManageUser.login(user.getId());
|
|
|
+ UserAuthLoginResp loginPhoneRep = new UserAuthLoginResp(StpCpsManageUser.getTokenValue(), user.getShowId(), user.getNickname(), user.getHeadimgurl());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(loginPhoneRep);
|
|
|
+ }
|
|
|
}
|