update 优化 !pr363 支持本地虚拟域名调试

feature/model
疯狂的狮子Li 1 year ago
parent ef77672466
commit ffedfd89a1

@ -2,6 +2,9 @@ package org.dromara.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 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.R;
import org.dromara.common.core.domain.model.EmailLoginBody; import org.dromara.common.core.domain.model.EmailLoginBody;
import org.dromara.common.core.domain.model.LoginBody; 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.domain.vo.TenantListVo;
import org.dromara.web.service.SysLoginService; import org.dromara.web.service.SysLoginService;
import org.dromara.web.service.SysRegisterService; 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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -74,8 +74,10 @@ public class AuthController {
public R<LoginVo> smsLogin(@Validated @RequestBody SmsLoginBody body) { public R<LoginVo> smsLogin(@Validated @RequestBody SmsLoginBody body) {
LoginVo loginVo = new LoginVo(); LoginVo loginVo = new LoginVo();
// 生成令牌 // 生成令牌
String token = String token = loginService.smsLogin(
loginService.smsLogin(body.getTenantId(), body.getPhonenumber(), body.getSmsCode()); body.getTenantId(),
body.getPhonenumber(),
body.getSmsCode());
loginVo.setToken(token); loginVo.setToken(token);
return R.ok(loginVo); return R.ok(loginVo);
} }
@ -90,8 +92,10 @@ public class AuthController {
public R<LoginVo> emailLogin(@Validated @RequestBody EmailLoginBody body) { public R<LoginVo> emailLogin(@Validated @RequestBody EmailLoginBody body) {
LoginVo loginVo = new LoginVo(); LoginVo loginVo = new LoginVo();
// 生成令牌 // 生成令牌
String token = String token = loginService.emailLogin(
loginService.emailLogin(body.getTenantId(), body.getEmail(), body.getEmailCode()); body.getTenantId(),
body.getEmail(),
body.getEmailCode());
loginVo.setToken(token); loginVo.setToken(token);
return R.ok(loginVo); return R.ok(loginVo);
} }
@ -142,7 +146,7 @@ public class AuthController {
List<SysTenantVo> tenantList = tenantService.queryList(new SysTenantBo()); List<SysTenantVo> tenantList = tenantService.queryList(new SysTenantBo());
List<TenantListVo> voList = MapstructUtils.convert(tenantList, TenantListVo.class); List<TenantListVo> voList = MapstructUtils.convert(tenantList, TenantListVo.class);
// 获取域名 // 获取域名
String host = ""; String host;
String referer = request.getHeader("referer"); String referer = request.getHeader("referer");
if (StringUtils.isNotBlank(referer)) { if (StringUtils.isNotBlank(referer)) {
// 这里从referer中取值是为了本地使用hosts添加虚拟域名方便本地环境调试 // 这里从referer中取值是为了本地使用hosts添加虚拟域名方便本地环境调试
@ -151,10 +155,8 @@ public class AuthController {
host = new URL(request.getRequestURL().toString()).getHost(); host = new URL(request.getRequestURL().toString()).getHost();
} }
// 根据域名进行筛选 // 根据域名进行筛选
String finalHost = host; List<TenantListVo> list = StreamUtils.filter(voList, vo ->
List<TenantListVo> list = StringUtils.equals(vo.getDomain(), host));
StreamUtils.filter(voList, vo -> StringUtils.equals(vo.getDomain(),
finalHost));
// 返回对象 // 返回对象
LoginTenantVo vo = new LoginTenantVo(); LoginTenantVo vo = new LoginTenantVo();
vo.setVoList(CollUtil.isNotEmpty(list) ? list : voList); vo.setVoList(CollUtil.isNotEmpty(list) ? list : voList);

Loading…
Cancel
Save