Commit 535d3c9c01839d58ea65378fbc71e98a511cc49c

Authored by YunaiV
1 parent 0cb4823b

登陆界面,优化成输入租户名

yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/framework/security/SecurityConfiguration.java
... ... @@ -22,9 +22,11 @@ public class SecurityConfiguration {
22 22 @Bean
23 23 public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() {
24 24 return registry -> {
25   - // 通用的接口,可匿名访问 TODO 芋艿:需要抽象出去
  25 + // 验证码的接口
26 26 registry.antMatchers(api("/system/captcha/**")).anonymous();
27   - // Spring Boot Admin Server 的安全配置 TODO 芋艿:需要抽象出去
  27 + // 获得租户编号的接口
  28 + registry.antMatchers(api("/system/tenant/get-id-by-name")).anonymous();
  29 + // Spring Boot Admin Server 的安全配置
28 30 registry.antMatchers(adminSeverContextPath).anonymous()
29 31 .antMatchers(adminSeverContextPath + "/**").anonymous();
30 32 // 短信回调 API
... ...
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/tenant/SysTenantController.java 0 → 100644
  1 +package cn.iocoder.yudao.adminserver.modules.system.controller.tenant;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import io.swagger.annotations.Api;
  5 +import io.swagger.annotations.ApiImplicitParam;
  6 +import io.swagger.annotations.ApiOperation;
  7 +import org.springframework.web.bind.annotation.GetMapping;
  8 +import org.springframework.web.bind.annotation.RequestMapping;
  9 +import org.springframework.web.bind.annotation.RequestParam;
  10 +import org.springframework.web.bind.annotation.RestController;
  11 +
  12 +import java.util.Objects;
  13 +
  14 +@Api(tags = "租户")
  15 +@RestController
  16 +@RequestMapping("/system/tenant")
  17 +public class SysTenantController {
  18 +
  19 + @GetMapping("/get-id-by-name")
  20 + @ApiOperation(value = "使用租户名,获得租户编号", notes = "登录界面,根据用户的租户名,获得租户编号")
  21 + @ApiImplicitParam(name = "name", value = "租户名", required = true, example = "芋道源码", dataTypeClass = Long.class)
  22 + public CommonResult<Long> getTenantIdByName(@RequestParam("name") String name) {
  23 + if (Objects.equals("芋道源码", name)) {
  24 + return CommonResult.success(0L);
  25 + }
  26 + return CommonResult.success(null);
  27 + }
  28 +
  29 +}
... ...
yudao-admin-ui/src/api/system/tenant.js 0 → 100644
  1 +import request from '@/utils/request'
  2 +
  3 +// 使用租户名,获得租户编号
  4 +export function getTenantIdByName(name) {
  5 + return request({
  6 + url: '/system/tenant/get-id-by-name',
  7 + method: 'get',
  8 + params: {
  9 + name
  10 + }
  11 + })
  12 +}
... ...
yudao-admin-ui/src/views/login.vue
... ... @@ -2,8 +2,8 @@
2 2 <div class="login">
3 3 <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
4 4 <h3 class="title">芋道后台管理系统</h3>
5   - <el-form-item prop="username">
6   - <el-input v-model="loginForm.tenantId" type="text" auto-complete="off" placeholder="租户">
  5 + <el-form-item prop="tenantName">
  6 + <el-input v-model="loginForm.tenantName" type="text" auto-complete="off" placeholder='租户'>
7 7 <svg-icon slot="prefix" icon-class="tree" class="el-input__icon input-icon" />
8 8 </el-input>
9 9 </el-form-item>
... ... @@ -51,6 +51,7 @@
51 51  
52 52 <script>
53 53 import { getCodeImg,socialAuthRedirect } from "@/api/login";
  54 +import { getTenantIdByName } from "@/api/system/tenant";
54 55 import Cookies from "js-cookie";
55 56 import { encrypt, decrypt } from '@/utils/jsencrypt'
56 57 import {InfApiErrorLogProcessStatusEnum, SysUserSocialTypeEnum} from "@/utils/constants";
... ... @@ -61,16 +62,32 @@ export default {
61 62 return {
62 63 codeUrl: "",
63 64 loginForm: {
64   - tenantId: "",
65 65 username: "admin",
66 66 password: "admin123",
67 67 rememberMe: false,
68 68 code: "",
69   - uuid: ""
  69 + uuid: "",
  70 + tenantName: "芋道源码",
70 71 },
71 72 loginRules: {
72   - tenantId: [
  73 + tenantName: [
73 74 { required: true, trigger: "blur", message: "租户不能为空" },
  75 + {
  76 + validator: (rule, value, callback) => {
  77 + // debugger
  78 + getTenantIdByName(value).then(res => {
  79 + const tenantId = res.data;
  80 + if (tenantId >= 0) {
  81 + // 设置租户
  82 + Cookies.set("tenantId", tenantId);
  83 + callback();
  84 + } else {
  85 + callback('租户不存在');
  86 + }
  87 + });
  88 + },
  89 + trigger: 'blur'
  90 + }
74 91 ],
75 92 username: [
76 93 { required: true, trigger: "blur", message: "用户名不能为空" }
... ... @@ -112,12 +129,12 @@ export default {
112 129 const username = Cookies.get("username");
113 130 const password = Cookies.get("password");
114 131 const rememberMe = Cookies.get('rememberMe')
115   - const tenantId = Cookies.get('tenantId');
  132 + const tenantName = Cookies.get('tenantName');
116 133 this.loginForm = {
117 134 username: username === undefined ? this.loginForm.username : username,
118 135 password: password === undefined ? this.loginForm.password : decrypt(password),
119 136 rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
120   - tenantId: tenantId === undefined ? 0 : tenantId, // TODO 芋艿:优化下,magic number
  137 + tenantName: tenantName === undefined ? this.loginForm.tenantName : tenantName,
121 138 };
122 139 },
123 140 handleLogin() {
... ... @@ -129,13 +146,13 @@ export default {
129 146 Cookies.set("username", this.loginForm.username, { expires: 30 });
130 147 Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
131 148 Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  149 + Cookies.set('tenantName', this.loginForm.tenantName, { expires: 30 });
132 150 } else {
133 151 Cookies.remove("username");
134 152 Cookies.remove("password");
135 153 Cookies.remove('rememberMe');
  154 + Cookies.remove('tenantName');
136 155 }
137   - // 设置租户
138   - Cookies.set("tenantId", this.loginForm.tenantId);
139 156 // 发起登陆
140 157 this.$store.dispatch("Login", this.loginForm).then(() => {
141 158 this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
... ...