[update] 更改 /auth/tenant/list api,获取租户列表时,从请求头中referer属性中取值,方便本地通过修改hosts文件来达到域名测试的场景

feature/model
代星登 1 year ago
parent cff90251ef
commit 789858199b

@ -57,9 +57,9 @@ public class AuthController {
LoginVo loginVo = new LoginVo(); LoginVo loginVo = new LoginVo();
// 生成令牌 // 生成令牌
String token = loginService.login( String token = loginService.login(
body.getTenantId(), body.getTenantId(),
body.getUsername(), body.getPassword(), body.getUsername(), body.getPassword(),
body.getCode(), body.getUuid()); body.getCode(), body.getUuid());
loginVo.setToken(token); loginVo.setToken(token);
return R.ok(loginVo); return R.ok(loginVo);
} }
@ -74,7 +74,8 @@ 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 = loginService.smsLogin(body.getTenantId(), body.getPhonenumber(), body.getSmsCode()); String token =
loginService.smsLogin(body.getTenantId(), body.getPhonenumber(), body.getSmsCode());
loginVo.setToken(token); loginVo.setToken(token);
return R.ok(loginVo); return R.ok(loginVo);
} }
@ -89,7 +90,8 @@ 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 = loginService.emailLogin(body.getTenantId(), body.getEmail(), body.getEmailCode()); String token =
loginService.emailLogin(body.getTenantId(), body.getEmail(), body.getEmailCode());
loginVo.setToken(token); loginVo.setToken(token);
return R.ok(loginVo); return R.ok(loginVo);
} }
@ -140,9 +142,19 @@ 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 = 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<TenantListVo> list = StreamUtils.filter(voList, vo -> StringUtils.equals(vo.getDomain(), host)); String finalHost = host;
List<TenantListVo> list =
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