|
@@ -3,11 +3,11 @@ package org.eco.web.controller;
|
|
import cn.dev33.satoken.annotation.SaIgnore;
|
|
import cn.dev33.satoken.annotation.SaIgnore;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
-import org.eco.web.domain.vo.LoginTenantVo;
|
|
|
|
-import org.eco.web.domain.vo.LoginVo;
|
|
|
|
-import org.eco.web.domain.vo.TenantListVo;
|
|
|
|
-import org.eco.web.service.IAuthStrategy;
|
|
|
|
-import org.eco.web.service.SysLoginService;
|
|
|
|
|
|
+import com.mybatisflex.core.query.QueryWrapper;
|
|
|
|
+import jakarta.annotation.Resource;
|
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.eco.common.core.constant.UserConstants;
|
|
import org.eco.common.core.constant.UserConstants;
|
|
import org.eco.common.core.core.domain.CommonResult;
|
|
import org.eco.common.core.core.domain.CommonResult;
|
|
import org.eco.common.core.core.domain.model.LoginBody;
|
|
import org.eco.common.core.core.domain.model.LoginBody;
|
|
@@ -19,16 +19,19 @@ import org.eco.common.core.utils.StringUtils;
|
|
import org.eco.common.core.utils.ValidatorUtils;
|
|
import org.eco.common.core.utils.ValidatorUtils;
|
|
import org.eco.common.encrypt.annotation.ApiEncrypt;
|
|
import org.eco.common.encrypt.annotation.ApiEncrypt;
|
|
import org.eco.common.json.utils.JsonUtils;
|
|
import org.eco.common.json.utils.JsonUtils;
|
|
|
|
+import org.eco.common.security.utils.LoginHelper;
|
|
|
|
+import org.eco.common.websocket.dto.WebSocketMessageDto;
|
|
|
|
+import org.eco.common.websocket.utils.WebSocketUtils;
|
|
import org.eco.system.domain.SysClient;
|
|
import org.eco.system.domain.SysClient;
|
|
import org.eco.system.domain.bo.SysTenantBo;
|
|
import org.eco.system.domain.bo.SysTenantBo;
|
|
import org.eco.system.domain.vo.SysTenantVo;
|
|
import org.eco.system.domain.vo.SysTenantVo;
|
|
import org.eco.system.service.ISysClientService;
|
|
import org.eco.system.service.ISysClientService;
|
|
import org.eco.system.service.ISysTenantService;
|
|
import org.eco.system.service.ISysTenantService;
|
|
-import com.mybatisflex.core.query.QueryWrapper;
|
|
|
|
-import jakarta.annotation.Resource;
|
|
|
|
-import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
+import org.eco.web.domain.vo.LoginTenantVo;
|
|
|
|
+import org.eco.web.domain.vo.LoginVo;
|
|
|
|
+import org.eco.web.domain.vo.TenantListVo;
|
|
|
|
+import org.eco.web.service.IAuthStrategy;
|
|
|
|
+import org.eco.web.service.SysLoginService;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -38,6 +41,8 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static org.eco.system.domain.table.SysClientTableDef.SYS_CLIENT;
|
|
import static org.eco.system.domain.table.SysClientTableDef.SYS_CLIENT;
|
|
|
|
|
|
@@ -61,6 +66,8 @@ public class AuthController {
|
|
private ISysClientService clientService;
|
|
private ISysClientService clientService;
|
|
@Resource
|
|
@Resource
|
|
private ISysTenantService tenantService;
|
|
private ISysTenantService tenantService;
|
|
|
|
+ @Resource
|
|
|
|
+ private ScheduledExecutorService scheduledExecutorService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 登录方法
|
|
* 登录方法
|
|
@@ -86,11 +93,19 @@ public class AuthController {
|
|
} else if (!UserConstants.NORMAL.equals(client.getStatus())) {
|
|
} else if (!UserConstants.NORMAL.equals(client.getStatus())) {
|
|
return CommonResult.fail(MessageUtils.message("auth.grant.type.blocked"));
|
|
return CommonResult.fail(MessageUtils.message("auth.grant.type.blocked"));
|
|
}
|
|
}
|
|
- // 校验租户 TODO 不需要校验租户
|
|
|
|
- // loginService.checkTenant(loginBody.getTenantId());
|
|
|
|
-
|
|
|
|
|
|
+ // 校验租户
|
|
|
|
+ loginService.checkTenant(loginBody.getTenantId());
|
|
|
|
+ // 登录
|
|
|
|
+ LoginVo loginVo = IAuthStrategy.login(body, client, grantType);
|
|
|
|
+ Long userId = LoginHelper.getUserId();
|
|
|
|
+ scheduledExecutorService.schedule(() -> {
|
|
|
|
+ WebSocketMessageDto dto = new WebSocketMessageDto();
|
|
|
|
+ dto.setMessage("欢迎登录");
|
|
|
|
+ dto.setSessionKeys(List.of(userId));
|
|
|
|
+ WebSocketUtils.publishMessage(dto);
|
|
|
|
+ }, 3, TimeUnit.SECONDS);
|
|
// 登录
|
|
// 登录
|
|
- return CommonResult.success(IAuthStrategy.login(body, client, grantType));
|
|
|
|
|
|
+ return CommonResult.success(loginVo);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -108,9 +123,10 @@ public class AuthController {
|
|
@PostMapping("/register")
|
|
@PostMapping("/register")
|
|
public CommonResult<Void> register(@Validated @RequestBody RegisterBody user) {
|
|
public CommonResult<Void> register(@Validated @RequestBody RegisterBody user) {
|
|
//if (!configService.selectRegisterEnabled(user.getTenantId())) // TODO:注册代码
|
|
//if (!configService.selectRegisterEnabled(user.getTenantId())) // TODO:注册代码
|
|
- {
|
|
|
|
- return CommonResult.fail("当前系统没有开启注册功能!");
|
|
|
|
- }
|
|
|
|
|
|
+// {
|
|
|
|
+ log.info(user.getUserType());
|
|
|
|
+ return CommonResult.fail("当前系统没有开启注册功能!");
|
|
|
|
+// }
|
|
// registerService.register(user);
|
|
// registerService.register(user);
|
|
// return R.ok();
|
|
// return R.ok();
|
|
}
|
|
}
|
|
@@ -134,8 +150,7 @@ public class AuthController {
|
|
host = new URL(request.getRequestURL().toString()).getHost();
|
|
host = new URL(request.getRequestURL().toString()).getHost();
|
|
}
|
|
}
|
|
// 根据域名进行筛选
|
|
// 根据域名进行筛选
|
|
- List<TenantListVo> list = StreamUtils.filter(voList, vo ->
|
|
|
|
- StringUtils.equals(vo.getDomain(), host));
|
|
|
|
|
|
+ List<TenantListVo> list = StreamUtils.filter(voList, vo -> StringUtils.equals(vo.getDomain(), host));
|
|
// 返回对象
|
|
// 返回对象
|
|
LoginTenantVo vo = new LoginTenantVo();
|
|
LoginTenantVo vo = new LoginTenantVo();
|
|
vo.setTenantEnabled(true);
|
|
vo.setTenantEnabled(true);
|