Commit 535d3c9c01839d58ea65378fbc71e98a511cc49c
1 parent
0cb4823b
登陆界面,优化成输入租户名
Showing
4 changed files
with
71 additions
and
11 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/framework/security/SecurityConfiguration.java
| @@ -22,9 +22,11 @@ public class SecurityConfiguration { | @@ -22,9 +22,11 @@ public class SecurityConfiguration { | ||
| 22 | @Bean | 22 | @Bean |
| 23 | public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() { | 23 | public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() { |
| 24 | return registry -> { | 24 | return registry -> { |
| 25 | - // 通用的接口,可匿名访问 TODO 芋艿:需要抽象出去 | 25 | + // 验证码的接口 |
| 26 | registry.antMatchers(api("/system/captcha/**")).anonymous(); | 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 | registry.antMatchers(adminSeverContextPath).anonymous() | 30 | registry.antMatchers(adminSeverContextPath).anonymous() |
| 29 | .antMatchers(adminSeverContextPath + "/**").anonymous(); | 31 | .antMatchers(adminSeverContextPath + "/**").anonymous(); |
| 30 | // 短信回调 API | 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
yudao-admin-ui/src/views/login.vue
| @@ -2,8 +2,8 @@ | @@ -2,8 +2,8 @@ | ||
| 2 | <div class="login"> | 2 | <div class="login"> |
| 3 | <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> | 3 | <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> |
| 4 | <h3 class="title">芋道后台管理系统</h3> | 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 | <svg-icon slot="prefix" icon-class="tree" class="el-input__icon input-icon" /> | 7 | <svg-icon slot="prefix" icon-class="tree" class="el-input__icon input-icon" /> |
| 8 | </el-input> | 8 | </el-input> |
| 9 | </el-form-item> | 9 | </el-form-item> |
| @@ -51,6 +51,7 @@ | @@ -51,6 +51,7 @@ | ||
| 51 | 51 | ||
| 52 | <script> | 52 | <script> |
| 53 | import { getCodeImg,socialAuthRedirect } from "@/api/login"; | 53 | import { getCodeImg,socialAuthRedirect } from "@/api/login"; |
| 54 | +import { getTenantIdByName } from "@/api/system/tenant"; | ||
| 54 | import Cookies from "js-cookie"; | 55 | import Cookies from "js-cookie"; |
| 55 | import { encrypt, decrypt } from '@/utils/jsencrypt' | 56 | import { encrypt, decrypt } from '@/utils/jsencrypt' |
| 56 | import {InfApiErrorLogProcessStatusEnum, SysUserSocialTypeEnum} from "@/utils/constants"; | 57 | import {InfApiErrorLogProcessStatusEnum, SysUserSocialTypeEnum} from "@/utils/constants"; |
| @@ -61,16 +62,32 @@ export default { | @@ -61,16 +62,32 @@ export default { | ||
| 61 | return { | 62 | return { |
| 62 | codeUrl: "", | 63 | codeUrl: "", |
| 63 | loginForm: { | 64 | loginForm: { |
| 64 | - tenantId: "", | ||
| 65 | username: "admin", | 65 | username: "admin", |
| 66 | password: "admin123", | 66 | password: "admin123", |
| 67 | rememberMe: false, | 67 | rememberMe: false, |
| 68 | code: "", | 68 | code: "", |
| 69 | - uuid: "" | 69 | + uuid: "", |
| 70 | + tenantName: "芋道源码", | ||
| 70 | }, | 71 | }, |
| 71 | loginRules: { | 72 | loginRules: { |
| 72 | - tenantId: [ | 73 | + tenantName: [ |
| 73 | { required: true, trigger: "blur", message: "租户不能为空" }, | 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 | username: [ | 92 | username: [ |
| 76 | { required: true, trigger: "blur", message: "用户名不能为空" } | 93 | { required: true, trigger: "blur", message: "用户名不能为空" } |
| @@ -112,12 +129,12 @@ export default { | @@ -112,12 +129,12 @@ export default { | ||
| 112 | const username = Cookies.get("username"); | 129 | const username = Cookies.get("username"); |
| 113 | const password = Cookies.get("password"); | 130 | const password = Cookies.get("password"); |
| 114 | const rememberMe = Cookies.get('rememberMe') | 131 | const rememberMe = Cookies.get('rememberMe') |
| 115 | - const tenantId = Cookies.get('tenantId'); | 132 | + const tenantName = Cookies.get('tenantName'); |
| 116 | this.loginForm = { | 133 | this.loginForm = { |
| 117 | username: username === undefined ? this.loginForm.username : username, | 134 | username: username === undefined ? this.loginForm.username : username, |
| 118 | password: password === undefined ? this.loginForm.password : decrypt(password), | 135 | password: password === undefined ? this.loginForm.password : decrypt(password), |
| 119 | rememberMe: rememberMe === undefined ? false : Boolean(rememberMe), | 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 | handleLogin() { | 140 | handleLogin() { |
| @@ -129,13 +146,13 @@ export default { | @@ -129,13 +146,13 @@ export default { | ||
| 129 | Cookies.set("username", this.loginForm.username, { expires: 30 }); | 146 | Cookies.set("username", this.loginForm.username, { expires: 30 }); |
| 130 | Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 }); | 147 | Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 }); |
| 131 | Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 }); | 148 | Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 }); |
| 149 | + Cookies.set('tenantName', this.loginForm.tenantName, { expires: 30 }); | ||
| 132 | } else { | 150 | } else { |
| 133 | Cookies.remove("username"); | 151 | Cookies.remove("username"); |
| 134 | Cookies.remove("password"); | 152 | Cookies.remove("password"); |
| 135 | Cookies.remove('rememberMe'); | 153 | Cookies.remove('rememberMe'); |
| 154 | + Cookies.remove('tenantName'); | ||
| 136 | } | 155 | } |
| 137 | - // 设置租户 | ||
| 138 | - Cookies.set("tenantId", this.loginForm.tenantId); | ||
| 139 | // 发起登陆 | 156 | // 发起登陆 |
| 140 | this.$store.dispatch("Login", this.loginForm).then(() => { | 157 | this.$store.dispatch("Login", this.loginForm).then(() => { |
| 141 | this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); | 158 | this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); |