forked from github/cool-admin-java
feat: 登录注册配置CRUD及菜单数据
This commit is contained in:
+22
@@ -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<UserLoginConfigService, UserLoginConfigEntity> {
|
||||
|
||||
@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));
|
||||
}
|
||||
}
|
||||
@@ -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<List<UserLoginConfigEntity>> getConfig(@RequestParam String type) {
|
||||
return R.ok(userLoginConfigService.getEnabledConfigs(type));
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,7 @@ public class LoginParam {
|
||||
|
||||
/*******用户名登录*******/
|
||||
private String username;
|
||||
|
||||
/*******注册*******/
|
||||
private String nickName;
|
||||
}
|
||||
|
||||
@@ -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<UserLoginConfigEntity> {
|
||||
|
||||
@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;
|
||||
}
|
||||
@@ -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<UserLoginConfigEntity> {
|
||||
}
|
||||
@@ -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<UserLoginConfigEntity> {
|
||||
|
||||
/**
|
||||
* 获取启用的登录/注册方式配置(App端使用)
|
||||
*/
|
||||
List<UserLoginConfigEntity> getEnabledConfigs(String type);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<UserLoginConfigMapper, UserLoginConfigEntity>
|
||||
implements UserLoginConfigService {
|
||||
|
||||
@Override
|
||||
public List<UserLoginConfigEntity> getEnabledConfigs(String type) {
|
||||
return list(QueryWrapper.create()
|
||||
.eq(UserLoginConfigEntity::getType, type)
|
||||
.eq(UserLoginConfigEntity::getEnabled, 1)
|
||||
.orderBy(UserLoginConfigEntity::getOrderNum, true));
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user