From 453514017ceeb6fecff927fe6ea76372860641d3 Mon Sep 17 00:00:00 2001 From: OpenCode Date: Wed, 22 Jul 2026 15:42:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=99=BB=E5=BD=95=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E9=85=8D=E7=BD=AECRUD=E5=8F=8A=E8=8F=9C=E5=8D=95=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/AdminUserLoginConfigController.java | 22 +++++ .../app/AppUserLoginConfigController.java | 27 ++++++ .../app/AppUserLoginController.java | 23 +++++ .../controller/app/params/LoginParam.java | 3 + .../user/entity/UserLoginConfigEntity.java | 34 ++++++++ .../user/mapper/UserLoginConfigMapper.java | 7 ++ .../user/service/UserLoginConfigService.java | 13 +++ .../user/service/UserLoginService.java | 10 +++ .../impl/UserLoginConfigServiceImpl.java | 22 +++++ .../service/impl/UserLoginServiceImpl.java | 31 +++++++ src/main/resources/cool/data/db/base.json | 62 ++++++++++++++ src/main/resources/cool/data/menu/menu.json | 85 +++++++++++++++++++ 12 files changed, 339 insertions(+) create mode 100644 src/main/java/com/cool/modules/user/controller/admin/AdminUserLoginConfigController.java create mode 100644 src/main/java/com/cool/modules/user/controller/app/AppUserLoginConfigController.java create mode 100644 src/main/java/com/cool/modules/user/entity/UserLoginConfigEntity.java create mode 100644 src/main/java/com/cool/modules/user/mapper/UserLoginConfigMapper.java create mode 100644 src/main/java/com/cool/modules/user/service/UserLoginConfigService.java create mode 100644 src/main/java/com/cool/modules/user/service/impl/UserLoginConfigServiceImpl.java diff --git a/src/main/java/com/cool/modules/user/controller/admin/AdminUserLoginConfigController.java b/src/main/java/com/cool/modules/user/controller/admin/AdminUserLoginConfigController.java new file mode 100644 index 0000000..2608e71 --- /dev/null +++ b/src/main/java/com/cool/modules/user/controller/admin/AdminUserLoginConfigController.java @@ -0,0 +1,22 @@ +package com.cool.modules.user.controller.admin; + +import static com.cool.modules.user.entity.table.UserLoginConfigEntityTableDef.USER_LOGIN_CONFIG_ENTITY; + +import cn.hutool.json.JSONObject; +import com.cool.core.annotation.CoolRestController; +import com.cool.core.base.BaseController; +import com.cool.modules.user.entity.UserLoginConfigEntity; +import com.cool.modules.user.service.UserLoginConfigService; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletRequest; + +@Tag(name = "App登录注册配置", description = "7管理App端登录注册方式") +@CoolRestController(api = {"add", "delete", "update", "page", "list", "info"}, cname = "loginConfig") +public class AdminUserLoginConfigController extends BaseController { + + @Override + protected void init(HttpServletRequest request, JSONObject requestParams) { + setPageOption(createOp().fieldEq(USER_LOGIN_CONFIG_ENTITY.TYPE, USER_LOGIN_CONFIG_ENTITY.ENABLED) + .keyWordLikeFields(USER_LOGIN_CONFIG_ENTITY.LABEL)); + } +} diff --git a/src/main/java/com/cool/modules/user/controller/app/AppUserLoginConfigController.java b/src/main/java/com/cool/modules/user/controller/app/AppUserLoginConfigController.java new file mode 100644 index 0000000..e52dcb5 --- /dev/null +++ b/src/main/java/com/cool/modules/user/controller/app/AppUserLoginConfigController.java @@ -0,0 +1,27 @@ +package com.cool.modules.user.controller.app; + +import com.cool.core.annotation.CoolRestController; +import com.cool.core.annotation.TokenIgnore; +import com.cool.modules.user.entity.UserLoginConfigEntity; +import com.cool.modules.user.service.UserLoginConfigService; +import com.cool.core.request.R; +import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "App登录注册配置", description = "App端获取登录注册方式配置") +@RestController +@RequiredArgsConstructor +public class AppUserLoginConfigController { + + private final UserLoginConfigService userLoginConfigService; + + @TokenIgnore + @GetMapping("/app/user/login/config") + public R> getConfig(@RequestParam String type) { + return R.ok(userLoginConfigService.getEnabledConfigs(type)); + } +} diff --git a/src/main/java/com/cool/modules/user/controller/app/AppUserLoginController.java b/src/main/java/com/cool/modules/user/controller/app/AppUserLoginController.java index 955b86a..478aabd 100644 --- a/src/main/java/com/cool/modules/user/controller/app/AppUserLoginController.java +++ b/src/main/java/com/cool/modules/user/controller/app/AppUserLoginController.java @@ -207,4 +207,27 @@ public class AppUserLoginController { CoolPreconditions.checkEmpty(password); return R.ok(userLoginService.usernameLogin(username, password)); } + + @TokenIgnore + @Operation(summary = "邮箱注册") + @PostMapping("/emailRegister") + public R emailRegister(@RequestBody LoginParam param) { + String email = param.getEmail(); + String password = param.getPassword(); + String nickName = param.getNickName(); + CoolPreconditions.checkEmpty(email); + CoolPreconditions.checkEmpty(password); + return R.ok(userLoginService.emailRegister(email, password, nickName)); + } + + @TokenIgnore + @Operation(summary = "用户名注册") + @PostMapping("/usernameRegister") + public R usernameRegister(@RequestBody LoginParam param) { + String username = param.getUsername(); + String password = param.getPassword(); + CoolPreconditions.checkEmpty(username); + CoolPreconditions.checkEmpty(password); + return R.ok(userLoginService.usernameRegister(username, password)); + } } diff --git a/src/main/java/com/cool/modules/user/controller/app/params/LoginParam.java b/src/main/java/com/cool/modules/user/controller/app/params/LoginParam.java index 2bcf567..eef7524 100644 --- a/src/main/java/com/cool/modules/user/controller/app/params/LoginParam.java +++ b/src/main/java/com/cool/modules/user/controller/app/params/LoginParam.java @@ -37,4 +37,7 @@ public class LoginParam { /*******用户名登录*******/ private String username; + + /*******注册*******/ + private String nickName; } diff --git a/src/main/java/com/cool/modules/user/entity/UserLoginConfigEntity.java b/src/main/java/com/cool/modules/user/entity/UserLoginConfigEntity.java new file mode 100644 index 0000000..642a664 --- /dev/null +++ b/src/main/java/com/cool/modules/user/entity/UserLoginConfigEntity.java @@ -0,0 +1,34 @@ +package com.cool.modules.user.entity; + +import com.cool.core.base.BaseEntity; +import com.mybatisflex.annotation.Table; +import com.cool.core.annotation.ColumnDefine; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@Table(value = "user_login_config", comment = "App登录注册方式配置") +public class UserLoginConfigEntity extends BaseEntity { + + @ColumnDefine(comment = "方式标识 email/username/phone/wx", notNull = true, length = 50) + private String methodKey; + + @ColumnDefine(comment = "显示名称", notNull = true, length = 50) + private String label; + + @ColumnDefine(comment = "图标", length = 100) + private String icon; + + @ColumnDefine(comment = "类型 login/register", notNull = true, length = 20) + private String type; + + @ColumnDefine(comment = "是否启用 0-禁用 1-启用", defaultValue = "1") + private Integer enabled; + + @ColumnDefine(comment = "排序号,越小越靠前", defaultValue = "0") + private Integer orderNum; + + @ColumnDefine(comment = "是否为默认方式 0-否 1-是", defaultValue = "0") + private Integer isDefault; +} diff --git a/src/main/java/com/cool/modules/user/mapper/UserLoginConfigMapper.java b/src/main/java/com/cool/modules/user/mapper/UserLoginConfigMapper.java new file mode 100644 index 0000000..c4c50c7 --- /dev/null +++ b/src/main/java/com/cool/modules/user/mapper/UserLoginConfigMapper.java @@ -0,0 +1,7 @@ +package com.cool.modules.user.mapper; + +import com.mybatisflex.core.BaseMapper; +import com.cool.modules.user.entity.UserLoginConfigEntity; + +public interface UserLoginConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/cool/modules/user/service/UserLoginConfigService.java b/src/main/java/com/cool/modules/user/service/UserLoginConfigService.java new file mode 100644 index 0000000..141adff --- /dev/null +++ b/src/main/java/com/cool/modules/user/service/UserLoginConfigService.java @@ -0,0 +1,13 @@ +package com.cool.modules.user.service; + +import com.cool.core.base.BaseService; +import com.cool.modules.user.entity.UserLoginConfigEntity; +import java.util.List; + +public interface UserLoginConfigService extends BaseService { + + /** + * 获取启用的登录/注册方式配置(App端使用) + */ + List getEnabledConfigs(String type); +} diff --git a/src/main/java/com/cool/modules/user/service/UserLoginService.java b/src/main/java/com/cool/modules/user/service/UserLoginService.java index ed9b436..6c2bc3e 100644 --- a/src/main/java/com/cool/modules/user/service/UserLoginService.java +++ b/src/main/java/com/cool/modules/user/service/UserLoginService.java @@ -60,8 +60,18 @@ public interface UserLoginService { */ Object emailLogin(String email, String password); + /** + * 邮箱注册 + */ + Object emailRegister(String email, String password, String nickName); + /** * 用户名密码登录 */ Object usernameLogin(String username, String password); + + /** + * 用户名注册 + */ + Object usernameRegister(String username, String password); } diff --git a/src/main/java/com/cool/modules/user/service/impl/UserLoginConfigServiceImpl.java b/src/main/java/com/cool/modules/user/service/impl/UserLoginConfigServiceImpl.java new file mode 100644 index 0000000..80039bb --- /dev/null +++ b/src/main/java/com/cool/modules/user/service/impl/UserLoginConfigServiceImpl.java @@ -0,0 +1,22 @@ +package com.cool.modules.user.service.impl; + +import com.cool.core.base.BaseServiceImpl; +import com.cool.modules.user.entity.UserLoginConfigEntity; +import com.cool.modules.user.mapper.UserLoginConfigMapper; +import com.cool.modules.user.service.UserLoginConfigService; +import com.mybatisflex.core.query.QueryWrapper; +import java.util.List; +import org.springframework.stereotype.Service; + +@Service +public class UserLoginConfigServiceImpl extends BaseServiceImpl + implements UserLoginConfigService { + + @Override + public List getEnabledConfigs(String type) { + return list(QueryWrapper.create() + .eq(UserLoginConfigEntity::getType, type) + .eq(UserLoginConfigEntity::getEnabled, 1) + .orderBy(UserLoginConfigEntity::getOrderNum, true)); + } +} diff --git a/src/main/java/com/cool/modules/user/service/impl/UserLoginServiceImpl.java b/src/main/java/com/cool/modules/user/service/impl/UserLoginServiceImpl.java index 62344ae..e1ecf2d 100644 --- a/src/main/java/com/cool/modules/user/service/impl/UserLoginServiceImpl.java +++ b/src/main/java/com/cool/modules/user/service/impl/UserLoginServiceImpl.java @@ -165,6 +165,37 @@ public class UserLoginServiceImpl implements UserLoginService { return null; } + @Override + public Object emailRegister(String email, String password, String nickName) { + CoolPreconditions.checkEmpty(email, "邮箱不能为空"); + CoolPreconditions.checkEmpty(password, "密码不能为空"); + UserInfoEntity existing = userInfoService.getOne( + QueryWrapper.create().eq(UserInfoEntity::getEmail, email)); + CoolPreconditions.check(ObjUtil.isNotEmpty(existing), "该邮箱已注册"); + UserInfoEntity userInfoEntity = new UserInfoEntity(); + userInfoEntity.setEmail(email); + userInfoEntity.setPassword(MD5.create().digestHex(password)); + userInfoEntity.setNickName(ObjUtil.isNotEmpty(nickName) ? nickName : email.split("@")[0]); + userInfoEntity.setLoginType("2"); + userInfoEntity.save(); + return generateToken(userInfoEntity, null); + } + + @Override + public Object usernameRegister(String username, String password) { + CoolPreconditions.checkEmpty(username, "用户名不能为空"); + CoolPreconditions.checkEmpty(password, "密码不能为空"); + UserInfoEntity existing = userInfoService.getOne( + QueryWrapper.create().eq(UserInfoEntity::getNickName, username)); + CoolPreconditions.check(ObjUtil.isNotEmpty(existing), "该用户名已注册"); + UserInfoEntity userInfoEntity = new UserInfoEntity(); + userInfoEntity.setNickName(username); + userInfoEntity.setPassword(MD5.create().digestHex(password)); + userInfoEntity.setLoginType("2"); + userInfoEntity.save(); + return generateToken(userInfoEntity, null); + } + /** * 前置已校验用户的手机号, * 根据手机号找到用户生成token diff --git a/src/main/resources/cool/data/db/base.json b/src/main/resources/cool/data/db/base.json index b9fdb1a..04f0a38 100644 --- a/src/main/resources/cool/data/db/base.json +++ b/src/main/resources/cool/data/db/base.json @@ -147,5 +147,67 @@ "order_num": 1, "remark": "青龙面板脚本任务" } + ], + "user_login_config": [ + { + "id": 1, + "methodKey": "email", + "label": "邮箱登录", + "icon": "mail-fill", + "type": "login", + "enabled": 1, + "orderNum": 1, + "isDefault": 1 + }, + { + "id": 2, + "methodKey": "phone", + "label": "手机登录", + "icon": "device-fill", + "type": "login", + "enabled": 1, + "orderNum": 2, + "isDefault": 0 + }, + { + "id": 3, + "methodKey": "username", + "label": "用户名登录", + "icon": "user-fill", + "type": "login", + "enabled": 1, + "orderNum": 3, + "isDefault": 0 + }, + { + "id": 4, + "methodKey": "wx", + "label": "微信登录", + "icon": "wechat-fill", + "type": "login", + "enabled": 1, + "orderNum": 4, + "isDefault": 0 + }, + { + "id": 5, + "methodKey": "email", + "label": "邮箱注册", + "icon": "mail-fill", + "type": "register", + "enabled": 1, + "orderNum": 1, + "isDefault": 1 + }, + { + "id": 6, + "methodKey": "username", + "label": "用户名注册", + "icon": "user-fill", + "type": "register", + "enabled": 1, + "orderNum": 2, + "isDefault": 0 + } ] } \ No newline at end of file diff --git a/src/main/resources/cool/data/menu/menu.json b/src/main/resources/cool/data/menu/menu.json index 116d08d..d2379af 100644 --- a/src/main/resources/cool/data/menu/menu.json +++ b/src/main/resources/cool/data/menu/menu.json @@ -907,6 +907,91 @@ "childMenus": [] } ] + }, + { + "name": "登录注册配置", + "router": "/user/login-config", + "perms": null, + "type": 1, + "icon": "icon-menu", + "orderNum": 2, + "viewPath": "modules/user/views/login-config.vue", + "keepAlive": true, + "isShow": true, + "childMenus": [ + { + "name": "删除", + "router": null, + "perms": "user:loginConfig:delete", + "type": 2, + "icon": null, + "orderNum": 0, + "viewPath": null, + "keepAlive": true, + "isShow": true, + "childMenus": [] + }, + { + "name": "修改", + "router": null, + "perms": "user:loginConfig:update,user:loginConfig:info", + "type": 2, + "icon": null, + "orderNum": 0, + "viewPath": null, + "keepAlive": true, + "isShow": true, + "childMenus": [] + }, + { + "name": "单个信息", + "router": null, + "perms": "user:loginConfig:info", + "type": 2, + "icon": null, + "orderNum": 0, + "viewPath": null, + "keepAlive": true, + "isShow": true, + "childMenus": [] + }, + { + "name": "列表查询", + "router": null, + "perms": "user:loginConfig:list", + "type": 2, + "icon": null, + "orderNum": 0, + "viewPath": null, + "keepAlive": true, + "isShow": true, + "childMenus": [] + }, + { + "name": "分页查询", + "router": null, + "perms": "user:loginConfig:page", + "type": 2, + "icon": null, + "orderNum": 0, + "viewPath": null, + "keepAlive": true, + "isShow": true, + "childMenus": [] + }, + { + "name": "新增", + "router": null, + "perms": "user:loginConfig:add", + "type": 2, + "icon": null, + "orderNum": 0, + "viewPath": null, + "keepAlive": true, + "isShow": true, + "childMenus": [] + } + ] } ] }