From ffedfd89a1b3588a21fbc8b3042f6b628eb144ca 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:12:46 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20!pr363=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9C=AC=E5=9C=B0=E8=99=9A=E6=8B=9F=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/AuthController.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 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 9defb836..bba6113d 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 @@ -2,6 +2,9 @@ package org.dromara.web.controller; import cn.dev33.satoken.annotation.SaIgnore; import cn.hutool.core.collection.CollUtil; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.constraints.NotBlank; +import lombok.RequiredArgsConstructor; import org.dromara.common.core.domain.R; import org.dromara.common.core.domain.model.EmailLoginBody; import org.dromara.common.core.domain.model.LoginBody; @@ -20,9 +23,6 @@ import org.dromara.web.domain.vo.LoginVo; import org.dromara.web.domain.vo.TenantListVo; import org.dromara.web.service.SysLoginService; import org.dromara.web.service.SysRegisterService; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.validation.constraints.NotBlank; -import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -74,8 +74,10 @@ 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); } @@ -90,8 +92,10 @@ 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); } @@ -142,19 +146,17 @@ public class AuthController { List tenantList = tenantService.queryList(new SysTenantBo()); List voList = MapstructUtils.convert(tenantList, TenantListVo.class); // 获取域名 - String host = ""; + String host; String referer = request.getHeader("referer"); if (StringUtils.isNotBlank(referer)) { - //这里从referer中取值是为了本地使用hosts添加虚拟域名,方便本地环境调试 + // 这里从referer中取值是为了本地使用hosts添加虚拟域名,方便本地环境调试 host = referer.split("//")[1].split("/")[0]; } else { host = new URL(request.getRequestURL().toString()).getHost(); } // 根据域名进行筛选 - String finalHost = host; - List list = - StreamUtils.filter(voList, vo -> StringUtils.equals(vo.getDomain(), - finalHost)); + List list = StreamUtils.filter(voList, vo -> + StringUtils.equals(vo.getDomain(), host)); // 返回对象 LoginTenantVo vo = new LoginTenantVo(); vo.setVoList(CollUtil.isNotEmpty(list) ? list : voList);