From b69da4b16026c867e2e5de42e8b72cd0b29a50d8 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Tue, 15 Apr 2025 13:01:52 +0800 Subject: [PATCH] =?UTF-8?q?update:=E6=99=BA=E6=8E=A7=E5=8F=B0=E5=8F=AF?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=85=81=E8=AE=B8=E7=94=A8=E6=88=B7=E8=87=AA?= =?UTF-8?q?=E7=94=B1=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiaozhi/common/constant/Constant.java | 10 +++++++ .../service/impl/DeviceServiceImpl.java | 6 ++-- .../security/controller/LoginController.java | 4 +++ .../modules/sys/service/SysUserService.java | 7 +++++ .../sys/service/impl/SysUserServiceImpl.java | 16 +++++++++++ .../src/main/resources/application.yml | 5 +--- .../{202504131543.sql => 202504151205.sql} | 7 ++++- .../db/changelog/db.changelog-master.yaml | 4 +-- .../src/components/VersionFooter.vue | 28 ++++--------------- main/manager-web/src/store/index.js | 24 +++++++++++++++- main/manager-web/src/views/login.vue | 28 ++++++------------- main/manager-web/src/views/register.vue | 14 ++++++++++ 12 files changed, 101 insertions(+), 52 deletions(-) rename main/manager-api/src/main/resources/db/changelog/{202504131543.sql => 202504151205.sql} (78%) diff --git a/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java b/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java index 8daeb25e2..1ff70fd46 100644 --- a/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java +++ b/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java @@ -84,6 +84,16 @@ public interface Constant { */ String SERVER_SECRET = "server.secret"; + /** + * 是否允许用户注册 + */ + String SERVER_ALLOW_USER_REGISTER = "server.allow_user_register"; + + /** + * 下发六位验证码时显示的控制面板地址 + */ + String SERVER_FRONTED_URL = "server.fronted_url"; + /** * 路径分割符 */ diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java index f2351800d..840f5ad65 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java @@ -9,7 +9,6 @@ import java.util.TimeZone; import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -34,6 +33,7 @@ import xiaozhi.modules.device.entity.DeviceEntity; import xiaozhi.modules.device.service.DeviceService; import xiaozhi.modules.device.vo.UserShowDeviceListVO; import xiaozhi.modules.security.user.SecurityUser; +import xiaozhi.modules.sys.service.SysParamsService; import xiaozhi.modules.sys.service.SysUserUtilService; @Service @@ -49,11 +49,11 @@ public class DeviceServiceImpl extends BaseServiceImpl // 添加构造函数来初始化 deviceMapper public DeviceServiceImpl(DeviceDao deviceDao, SysUserUtilService sysUserUtilService, - @Value("${app.fronted-url:http://localhost:8001}") String frontedUrl, + SysParamsService sysParamsService, RedisTemplate redisTemplate) { this.deviceDao = deviceDao; this.sysUserUtilService = sysUserUtilService; - this.frontedUrl = frontedUrl; + this.frontedUrl = sysParamsService.getValue(Constant.SERVER_FRONTED_URL, true); this.redisTemplate = redisTemplate; } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/security/controller/LoginController.java b/main/manager-api/src/main/java/xiaozhi/modules/security/controller/LoginController.java index 0ee6a1ced..f83e49db2 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/security/controller/LoginController.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/security/controller/LoginController.java @@ -77,6 +77,9 @@ public class LoginController { @PostMapping("/register") @Operation(summary = "注册") public Result register(@RequestBody LoginDTO login) { + if (!sysUserService.getAllowUserRegister()) { + throw new RenException("当前不允许普通用户注册"); + } // 验证是否正确输入验证码 boolean validate = captchaService.validate(login.getCaptchaId(), login.getCaptcha()); if (!validate) { @@ -119,6 +122,7 @@ public class LoginController { public Result> pubConfig() { Map config = new HashMap<>(); config.put("version", "0.3.3"); + config.put("allowUserRegister", sysUserService.getAllowUserRegister()); return new Result>().ok(config); } } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/sys/service/SysUserService.java b/main/manager-api/src/main/java/xiaozhi/modules/sys/service/SysUserService.java index d5d103afa..7a35da321 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/sys/service/SysUserService.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/sys/service/SysUserService.java @@ -65,4 +65,11 @@ public interface SysUserService extends BaseService { * @param userIds 用户ID数组 */ void changeStatus(Integer status, String[] userIds); + + /** + * 获取是否允许用户注册 + * + * @return 是否允许用户注册 + */ + boolean getAllowUserRegister(); } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/sys/service/impl/SysUserServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/sys/service/impl/SysUserServiceImpl.java index e5b57159c..309762291 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/sys/service/impl/SysUserServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/sys/service/impl/SysUserServiceImpl.java @@ -30,6 +30,7 @@ import xiaozhi.modules.sys.dto.PasswordDTO; import xiaozhi.modules.sys.dto.SysUserDTO; import xiaozhi.modules.sys.entity.SysUserEntity; import xiaozhi.modules.sys.enums.SuperAdminEnum; +import xiaozhi.modules.sys.service.SysParamsService; import xiaozhi.modules.sys.service.SysUserService; import xiaozhi.modules.sys.vo.AdminPageUserVO; @@ -45,6 +46,8 @@ public class SysUserServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); @@ -205,4 +208,17 @@ public class SysUserServiceImpl extends BaseServiceImpl()); + if (userCount == 0) { + return true; + } + return false; + } } diff --git a/main/manager-api/src/main/resources/application.yml b/main/manager-api/src/main/resources/application.yml index abccb0b55..3daf48a14 100644 --- a/main/manager-api/src/main/resources/application.yml +++ b/main/manager-api/src/main/resources/application.yml @@ -63,7 +63,4 @@ mybatis-plus: configuration-properties: prefix: blobType: BLOB - boolValue: TRUE - -app: - fronted-url: http://localhost:8001 \ No newline at end of file + boolValue: TRUE \ No newline at end of file diff --git a/main/manager-api/src/main/resources/db/changelog/202504131543.sql b/main/manager-api/src/main/resources/db/changelog/202504151205.sql similarity index 78% rename from main/manager-api/src/main/resources/db/changelog/202504131543.sql rename to main/manager-api/src/main/resources/db/changelog/202504151205.sql index 55c699121..0b72121e5 100644 --- a/main/manager-api/src/main/resources/db/changelog/202504131543.sql +++ b/main/manager-api/src/main/resources/db/changelog/202504151205.sql @@ -15,4 +15,9 @@ INSERT INTO `ai_tts_voice` VALUES ('TTS_EdgeTTS0008', 'TTS_EdgeTTS', 'EdgeTTS女声-陕西小妮', 'zh-CN-shaanxi-XiaoniNeural', '陕西', NULL, NULL, 1, NULL, NULL, NULL, NULL), ('TTS_EdgeTTS0009', 'TTS_EdgeTTS', 'EdgeTTS女声-香港海佳', 'zh-HK-HiuGaaiNeural', '粤语', 'General', 'Friendly, Positive', 1, NULL, NULL, NULL, NULL), ('TTS_EdgeTTS0010', 'TTS_EdgeTTS', 'EdgeTTS女声-香港海曼', 'zh-HK-HiuMaanNeural', '粤语', 'General', 'Friendly, Positive', 1, NULL, NULL, NULL, NULL), -('TTS_EdgeTTS0011', 'TTS_EdgeTTS', 'EdgeTTS男声-香港万龙', 'zh-HK-WanLungNeural', '粤语', 'General', 'Friendly, Positive', 1, NULL, NULL, NULL, NULL); \ No newline at end of file +('TTS_EdgeTTS0011', 'TTS_EdgeTTS', 'EdgeTTS男声-香港万龙', 'zh-HK-WanLungNeural', '粤语', 'General', 'Friendly, Positive', 1, NULL, NULL, NULL, NULL); + +-- 增加是否允许用户注册参数 +delete from `sys_params` where id in (103,104); +INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (103, 'server.allow_user_register', 'false', 'boolean', 1, '是否运行管理员以外的人注册'); +INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (104, 'server.fronted_url', 'http://xiaozhi.server.com', 'string', 1, '下发六位验证码时显示的控制面板地址'); diff --git a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml index 37797d3f3..7060e32c0 100755 --- a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml @@ -52,9 +52,9 @@ databaseChangeLog: encoding: utf8 path: classpath:db/changelog/202504112058.sql - changeSet: - id: 202504131543 + id: 202504151205 author: John changes: - sqlFile: encoding: utf8 - path: classpath:db/changelog/202504131543.sql + path: classpath:db/changelog/202504151205.sql diff --git a/main/manager-web/src/components/VersionFooter.vue b/main/manager-web/src/components/VersionFooter.vue index 8a8b76a01..6226bcc0d 100644 --- a/main/manager-web/src/components/VersionFooter.vue +++ b/main/manager-web/src/components/VersionFooter.vue @@ -5,33 +5,17 @@ diff --git a/main/manager-web/src/store/index.js b/main/manager-web/src/store/index.js index e359c479f..7a33ed61e 100644 --- a/main/manager-web/src/store/index.js +++ b/main/manager-web/src/store/index.js @@ -1,6 +1,7 @@ import { goToPage } from "@/utils"; import Vue from 'vue'; import Vuex from 'vuex'; +import Api from '../apis/api'; import Constant from '../utils/constant'; Vue.use(Vuex) @@ -9,7 +10,11 @@ export default new Vuex.Store({ state: { token: '', userInfo: {}, // 添加用户信息存储 - isSuperAdmin: false // 添加superAdmin状态 + isSuperAdmin: false, // 添加superAdmin状态 + pubConfig: { // 添加公共配置存储 + version: '', + allowUserRegister: false + } }, getters: { getToken(state) { @@ -26,6 +31,9 @@ export default new Vuex.Store({ return state.isSuperAdmin } return localStorage.getItem('isSuperAdmin') === 'true' + }, + getPubConfig(state) { + return state.pubConfig } }, mutations: { @@ -39,6 +47,9 @@ export default new Vuex.Store({ state.isSuperAdmin = isSuperAdmin localStorage.setItem('isSuperAdmin', isSuperAdmin) }, + setPubConfig(state, config) { + state.pubConfig = config + }, clearAuth(state) { state.token = '' state.userInfo = {} @@ -55,6 +66,17 @@ export default new Vuex.Store({ goToPage(Constant.PAGE.LOGIN, true); window.location.reload(); // 彻底重置状态 }) + }, + // 添加获取公共配置的 action + fetchPubConfig({ commit }) { + return new Promise((resolve) => { + Api.user.getPubConfig(({ data }) => { + if (data.code === 0) { + commit('setPubConfig', data.data); + } + resolve(); + }); + }); } }, modules: { diff --git a/main/manager-web/src/views/login.vue b/main/manager-web/src/views/login.vue index af50bc1cc..d97af807d 100644 --- a/main/manager-web/src/views/login.vue +++ b/main/manager-web/src/views/login.vue @@ -38,7 +38,7 @@
-
新用户注册
+
新用户注册
@@ -61,12 +61,18 @@ import Api from '@/apis/api'; import VersionFooter from '@/components/VersionFooter.vue'; import { getUUID, goToPage, showDanger, showSuccess } from '@/utils'; +import { mapState } from 'vuex'; export default { name: 'login', components: { VersionFooter }, + computed: { + ...mapState({ + allowUserRegister: state => state.pubConfig.allowUserRegister + }) + }, data() { return { activeName: "username", @@ -77,13 +83,12 @@ export default { captchaId: '' }, captchaUuid: '', - captchaUrl: '', - version: '' + captchaUrl: '' } }, mounted() { this.fetchCaptcha(); - this.getSystemVersion(); + this.$store.dispatch('fetchPubConfig'); }, methods: { fetchCaptcha() { @@ -148,21 +153,6 @@ export default { goToRegister() { goToPage('/register') }, - - getSystemVersion() { - const storedVersion = sessionStorage.getItem('systemVersion'); - if (storedVersion) { - this.version = storedVersion; - return; - } - - Api.user.getPubConfig(({ data }) => { - if (data.code === 0 && data.data.version) { - this.version = data.data.version; - sessionStorage.setItem('systemVersion', data.data.version); - } - }); - } } } diff --git a/main/manager-web/src/views/register.vue b/main/manager-web/src/views/register.vue index 234229c38..87d1139fe 100644 --- a/main/manager-web/src/views/register.vue +++ b/main/manager-web/src/views/register.vue @@ -82,12 +82,18 @@ import Api from '@/apis/api'; import VersionFooter from '@/components/VersionFooter.vue'; import { getUUID, goToPage, showDanger, showSuccess } from '@/utils'; +import { mapState } from 'vuex'; export default { name: 'register', components: { VersionFooter }, + computed: { + ...mapState({ + allowUserRegister: state => state.pubConfig.allowUserRegister + }) + }, data() { return { form: { @@ -101,6 +107,14 @@ export default { } }, mounted() { + this.$store.dispatch('fetchPubConfig').then(() => { + if (!this.allowUserRegister) { + showDanger('当前不允许普通用户注册'); + setTimeout(() => { + goToPage('/login'); + }, 1500); + } + }); this.fetchCaptcha(); }, methods: {