Преглед на файлове

Merge branch 'feature/0721-tenant' into develop

yuanliang преди 1 година
родител
ревизия
065ac672f9

+ 6 - 0
cooleshow-auth/auth-api/src/main/java/com/yonge/cooleshow/auth/api/client/SysUserFeignService.java

@@ -70,6 +70,12 @@ public interface SysUserFeignService {
 	@ApiOperation(value = "退出登录")
 	HttpResponseResult<String> logout(@PathVariable("clientId") String clientId, @PathVariable("phone") String phone);
 
+	@PostMapping(value = "exit/{clientId}/{phone}/{openId}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
+	@ApiOperation(value = "指定机构用户退出登录")
+	HttpResponseResult<String> exitByPhoneAndOpenId(@PathVariable("clientId") String clientId,
+														   @PathVariable("phone") String phone,
+														   @PathVariable("openId") String openId);
+
 	@PostMapping(value = "user/list")
 	HttpResponseResult<List<SysUser>> page(@RequestBody SysUserQueryInfo queryInfo);
 

+ 22 - 0
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/core/service/CustomTokenServices.java

@@ -30,6 +30,7 @@ import org.springframework.security.web.authentication.preauth.PreAuthenticatedA
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
 
+import java.text.MessageFormat;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Set;
@@ -294,6 +295,27 @@ public class CustomTokenServices implements AuthorizationServerTokenServices, Re
 		return true;
 	}
 
+
+    public boolean revokeTokenByOpenId(String clientId, String phone,String openId) {
+        Collection<OAuth2AccessToken> list = tokenStore.findTokensByClientIdAndUserName(clientId, SecurityConstants.PHONE_PRINCIPAL_PREFIX + phone);
+
+        if (list == null || list.size() == 0) {
+            list = tokenStore.findTokensByClientIdAndUserName(clientId, MessageFormat.format("{0}:{1}:{2}", SecurityConstants.MA_PRINCIPAL_PREFIX, openId, phone));
+        }
+
+        if (list != null) {
+            for (OAuth2AccessToken accessToken : list) {
+                if (accessToken != null) {
+                    if (accessToken.getRefreshToken() != null) {
+                        tokenStore.removeRefreshToken(accessToken.getRefreshToken());
+                    }
+                    tokenStore.removeAccessToken(accessToken);
+                }
+            }
+        }
+        return true;
+    }
+
 	public void revokeTokenByPhone(String phone) {
 		String[] clientIds = new String[] {"system", "student", "teacher","website"};
 		for (String cId : clientIds) {

+ 11 - 0
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/web/controller/TokenController.java

@@ -1,5 +1,6 @@
 package com.yonge.cooleshow.auth.web.controller;
 
+import cn.hutool.core.net.URLEncodeUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -189,6 +190,16 @@ public class TokenController extends BaseController {
         return tokenService.revokeToken(clientId, phone) ? succeed("退出成功") : failed();
     }
 
+
+    @PostMapping(value = "exit/{clientId}/{phone}/{openId}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
+    @ApiOperation(value = "指定机构用户退出登录")
+    public HttpResponseResult<String> exitByPhoneAndOpenId(@PathVariable("clientId") String clientId,
+                                                           @PathVariable("phone") String phone,@PathVariable("openId") String openId) {
+
+        return tokenService.revokeTokenByOpenId(clientId, phone,openId) ? succeed("退出成功") : failed();
+    }
+
+
     @GetMapping(value = "/checkToken", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
     @ApiOperation(value = "检查token")
     public HttpResponseResult<Object> checkToken(HttpServletRequest request) throws IOException {

+ 5 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantInfoServiceImpl.java

@@ -432,7 +432,11 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
         //判断修改手机号后所属
         if (!info.getPhone().equals(oldTenantInfo.getPhone())) {
             // 清除登录token信息
-            sysUserFeignService.logout(ClientEnum.ORGANIZATION.getCode().toLowerCase(), oldTenantInfo.getPhone());
+            TenantStaff tenantStaff = tenantStaffMapper.selectByUserId(sysUser.getId());
+            if(tenantStaff != null){
+                sysUserFeignService.exitByPhoneAndOpenId(ClientEnum.ORGANIZATION.getCode().toLowerCase(),
+                        oldTenantInfo.getPhone(),tenantStaff.getWxOpenid());
+            }
         }
         tenantInfoMapper.update(null, Wrappers.<TenantInfo>lambdaUpdate()
                 .set(TenantInfo::getName, info.getName())