From 789858199b96626be2844a39ee2849d2534c6081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=A3=E6=98=9F=E7=99=BB?= <2283268848@qq.com> Date: Mon, 5 Jun 2023 14:57:15 +0800 Subject: [PATCH] =?UTF-8?q?[update]=20=E6=9B=B4=E6=94=B9=20/auth/tenant/li?= =?UTF-8?q?st=20api,=E8=8E=B7=E5=8F=96=E7=A7=9F=E6=88=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=BB=8E=E8=AF=B7=E6=B1=82=E5=A4=B4=E4=B8=AD?= =?UTF-8?q?referer=E5=B1=9E=E6=80=A7=E4=B8=AD=E5=8F=96=E5=80=BC=EF=BC=8C?= =?UTF-8?q?=E6=96=B9=E4=BE=BF=E6=9C=AC=E5=9C=B0=E9=80=9A=E8=BF=87=E4=BF=AE?= =?UTF-8?q?=E6=94=B9hosts=E6=96=87=E4=BB=B6=E6=9D=A5=E8=BE=BE=E5=88=B0?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E6=B5=8B=E8=AF=95=E7=9A=84=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/AuthController.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java b/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java index f39fd306..9defb836 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java @@ -57,9 +57,9 @@ public class AuthController { LoginVo loginVo = new LoginVo(); // 生成令牌 String token = loginService.login( - body.getTenantId(), - body.getUsername(), body.getPassword(), - body.getCode(), body.getUuid()); + body.getTenantId(), + body.getUsername(), body.getPassword(), + body.getCode(), body.getUuid()); loginVo.setToken(token); return R.ok(loginVo); } @@ -74,7 +74,8 @@ public class AuthController { public R smsLogin(@Validated @RequestBody SmsLoginBody body) { LoginVo loginVo = new LoginVo(); // 生成令牌 - String token = loginService.smsLogin(body.getTenantId(), body.getPhonenumber(), body.getSmsCode()); + String token = + loginService.smsLogin(body.getTenantId(), body.getPhonenumber(), body.getSmsCode()); loginVo.setToken(token); return R.ok(loginVo); } @@ -89,7 +90,8 @@ public class AuthController { public R emailLogin(@Validated @RequestBody EmailLoginBody body) { LoginVo loginVo = new LoginVo(); // 生成令牌 - String token = loginService.emailLogin(body.getTenantId(), body.getEmail(), body.getEmailCode()); + String token = + loginService.emailLogin(body.getTenantId(), body.getEmail(), body.getEmailCode()); loginVo.setToken(token); return R.ok(loginVo); } @@ -140,9 +142,19 @@ public class AuthController { List tenantList = tenantService.queryList(new SysTenantBo()); List voList = MapstructUtils.convert(tenantList, TenantListVo.class); // 获取域名 - String host = new URL(request.getRequestURL().toString()).getHost(); + String host = ""; + String referer = request.getHeader("referer"); + if (StringUtils.isNotBlank(referer)) { + //这里从referer中取值是为了本地使用hosts添加虚拟域名,方便本地环境调试 + host = referer.split("//")[1].split("/")[0]; + } else { + host = new URL(request.getRequestURL().toString()).getHost(); + } // 根据域名进行筛选 - List list = StreamUtils.filter(voList, vo -> StringUtils.equals(vo.getDomain(), host)); + String finalHost = host; + List list = + StreamUtils.filter(voList, vo -> StringUtils.equals(vo.getDomain(), + finalHost)); // 返回对象 LoginTenantVo vo = new LoginTenantVo(); vo.setVoList(CollUtil.isNotEmpty(list) ? list : voList);