From 1d86104289e621ba2d0916d589bcfa411089a17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Mon, 5 Jun 2023 15:14:34 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=9C=AC=E5=9C=B0=E8=99=9A=E6=8B=9F=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/controller/TokenController.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java b/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java index 12d7d479..227af511 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java @@ -51,7 +51,10 @@ public class TokenController { public R login(@Validated @RequestBody LoginBody body) { LoginVo loginVo = new LoginVo(); // 生成令牌 - String token = sysLoginService.login(body.getTenantId(), body.getUsername(), body.getPassword()); + String token = sysLoginService.login( + body.getTenantId(), + body.getUsername(), + body.getPassword()); loginVo.setToken(token); return R.ok(loginVo); } @@ -66,7 +69,10 @@ public class TokenController { public R smsLogin(@Validated @RequestBody SmsLoginBody smsLoginBody) { LoginVo loginVo = new LoginVo(); // 生成令牌 - String token = sysLoginService.smsLogin(smsLoginBody.getTenantId(),smsLoginBody.getPhonenumber(), smsLoginBody.getSmsCode()); + String token = sysLoginService.smsLogin( + smsLoginBody.getTenantId(), + smsLoginBody.getPhonenumber(), + smsLoginBody.getSmsCode()); loginVo.setToken(token); return R.ok(loginVo); } @@ -81,7 +87,10 @@ public class TokenController { public R emailLogin(@Validated @RequestBody EmailLoginBody body) { LoginVo loginVo = new LoginVo(); // 生成令牌 - String token = sysLoginService.emailLogin(body.getTenantId(), body.getEmail(), body.getEmailCode()); + String token = sysLoginService.emailLogin( + body.getTenantId(), + body.getEmail(), + body.getEmailCode()); loginVo.setToken(token); return R.ok(loginVo); } @@ -130,9 +139,17 @@ public class TokenController { List tenantList = remoteTenantService.queryList(); 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)); + List list = StreamUtils.filter(voList, vo -> + StringUtils.equals(vo.getDomain(), host)); // 返回对象 LoginTenantVo vo = new LoginTenantVo(); vo.setVoList(CollUtil.isNotEmpty(list) ? list : voList);