mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-02 11:58:01 +08:00
引人参数验证器
This commit is contained in:
parent
a7fe054b5c
commit
157124599a
9
PLANS.md
9
PLANS.md
@ -1,7 +1,6 @@
|
||||
### 开发计划
|
||||
|
||||
1. 程序宕机处理
|
||||
2. 主要管理页面兼容移动端
|
||||
3. ssl 到期提醒、快捷续签
|
||||
4. layui插件升级
|
||||
5. 支持git仓库拉取自动编译项目
|
||||
1. 主要管理页面兼容移动端
|
||||
2. ssl 到期提醒、快捷续签
|
||||
3. layui插件升级
|
||||
4. 支持git仓库拉取自动编译项目
|
||||
|
@ -3,6 +3,7 @@ package cn.keepbx.jpom;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.jiangzeyin.common.ApplicationBuilder;
|
||||
import cn.jiangzeyin.common.EnableCommonBoot;
|
||||
import cn.jiangzeyin.common.validator.ParameterInterceptor;
|
||||
import cn.keepbx.jpom.common.JpomApplicationEvent;
|
||||
import cn.keepbx.jpom.common.Type;
|
||||
import cn.keepbx.jpom.common.interceptor.LoginInterceptor;
|
||||
@ -37,6 +38,8 @@ public class JpomServerApplication extends BaseJpomApplication {
|
||||
// 拦截器
|
||||
.addInterceptor(LoginInterceptor.class)
|
||||
.addInterceptor(PermissionInterceptor.class)
|
||||
// 参数拦截器
|
||||
.addInterceptor(ParameterInterceptor.class)
|
||||
//
|
||||
.addApplicationEventClient(new JpomApplicationEvent())
|
||||
.run(args);
|
||||
|
@ -40,6 +40,9 @@ public class IndexControl extends BaseServerController {
|
||||
@NotLogin
|
||||
public String error(String id) {
|
||||
String msg = GlobalDefaultExceptionHandler.getErrorMsg(id);
|
||||
if (msg == null) {
|
||||
msg = "页面已经失效";
|
||||
}
|
||||
setAttribute("msg", msg);
|
||||
return "error";
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
package cn.keepbx.jpom.controller;
|
||||
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.jiangzeyin.common.DefaultSystemLog;
|
||||
import cn.jiangzeyin.common.JsonMessage;
|
||||
import cn.jiangzeyin.common.validator.ValidatorConfig;
|
||||
import cn.jiangzeyin.common.validator.ValidatorItem;
|
||||
import cn.jiangzeyin.common.validator.ValidatorRule;
|
||||
import cn.keepbx.jpom.BaseJpomApplication;
|
||||
import cn.keepbx.jpom.common.BaseServerController;
|
||||
import cn.keepbx.jpom.common.interceptor.LoginInterceptor;
|
||||
@ -49,28 +50,21 @@ public class InstallController extends BaseServerController {
|
||||
@RequestMapping(value = "install_submit.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
@NotLogin
|
||||
@ResponseBody
|
||||
public String installSubmit(String userName, String userPwd) {
|
||||
public String installSubmit(
|
||||
@ValidatorConfig(value = {
|
||||
@ValidatorItem(value = ValidatorRule.NOT_EMPTY, msg = "登录名不能为空"),
|
||||
@ValidatorItem(value = ValidatorRule.NOT_BLANK, range = "3:20", msg = "登录名长度范围3-20"),
|
||||
@ValidatorItem(value = ValidatorRule.WORD, msg = "登录名不能包含汉字并且不能包含特殊字符")
|
||||
}) String userName,
|
||||
@ValidatorConfig(value = {
|
||||
@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "密码不能为空")
|
||||
}) String userPwd) {
|
||||
if (!userService.userListEmpty()) {
|
||||
return JsonMessage.getString(100, "系统已经初始化过啦,请勿重复初始化");
|
||||
}
|
||||
if (StrUtil.isEmpty(userName)) {
|
||||
return JsonMessage.getString(400, "登录名不能为空");
|
||||
}
|
||||
if (userName.length() < UserModel.USER_NAME_MIN_LEN) {
|
||||
return JsonMessage.getString(400, "登录名长度必须不小于" + UserModel.USER_NAME_MIN_LEN);
|
||||
}
|
||||
if (BaseJpomApplication.SYSTEM_ID.equalsIgnoreCase(userName)) {
|
||||
if (BaseJpomApplication.SYSTEM_ID.equalsIgnoreCase(userName) || UserModel.SYSTEM_ADMIN.equals(userName)) {
|
||||
return JsonMessage.getString(400, "当前登录名已经被系统占用啦");
|
||||
}
|
||||
if (Validator.isChinese(userName) || !checkPathSafe(userName)) {
|
||||
return JsonMessage.getString(400, "登录名不能包含汉字并且不能包含特殊字符");
|
||||
}
|
||||
if (StrUtil.isEmpty(userPwd)) {
|
||||
return JsonMessage.getString(400, "密码不能为空");
|
||||
}
|
||||
if (UserModel.SYSTEM_OCCUPY_NAME.equals(userName) || UserModel.SYSTEM_ADMIN.equals(userName)) {
|
||||
return JsonMessage.getString(401, "当前登录名已经被系统占用");
|
||||
}
|
||||
// 创建用户
|
||||
UserModel userModel = new UserModel();
|
||||
userModel.setName(UserModel.SYSTEM_OCCUPY_NAME);
|
||||
|
@ -7,6 +7,9 @@ import cn.hutool.core.date.BetweenFormater;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.jiangzeyin.common.JsonMessage;
|
||||
import cn.jiangzeyin.common.validator.ValidatorConfig;
|
||||
import cn.jiangzeyin.common.validator.ValidatorItem;
|
||||
import cn.jiangzeyin.common.validator.ValidatorRule;
|
||||
import cn.keepbx.jpom.common.BaseServerController;
|
||||
import cn.keepbx.jpom.common.interceptor.LoginInterceptor;
|
||||
import cn.keepbx.jpom.common.interceptor.NotLogin;
|
||||
@ -134,10 +137,14 @@ public class LoginControl extends BaseServerController {
|
||||
@ResponseBody
|
||||
@NotLogin
|
||||
@OperateType(UserOperateLogV1.OptType.Login)
|
||||
public String userLogin(String userName, String userPwd, String code) throws IOException {
|
||||
if (StrUtil.isEmpty(userName) || StrUtil.isEmpty(userPwd)) {
|
||||
return JsonMessage.getString(405, "请输入登录信息");
|
||||
}
|
||||
public String userLogin(
|
||||
@ValidatorConfig(value = {
|
||||
@ValidatorItem(value = ValidatorRule.NOT_EMPTY, msg = "请输入登录信息")
|
||||
}) String userName,
|
||||
@ValidatorConfig(value = {
|
||||
@ValidatorItem(value = ValidatorRule.NOT_EMPTY, msg = "请输入登录信息")
|
||||
}) String userPwd,
|
||||
String code) throws IOException {
|
||||
if (this.ipLock()) {
|
||||
return JsonMessage.getString(400, "尝试次数太多,请稍后再来");
|
||||
}
|
||||
|
@ -4,6 +4,9 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.jiangzeyin.common.DefaultSystemLog;
|
||||
import cn.jiangzeyin.common.JsonMessage;
|
||||
import cn.jiangzeyin.common.validator.ValidatorConfig;
|
||||
import cn.jiangzeyin.common.validator.ValidatorItem;
|
||||
import cn.jiangzeyin.common.validator.ValidatorRule;
|
||||
import cn.keepbx.jpom.BaseJpomApplication;
|
||||
import cn.keepbx.jpom.common.BaseServerController;
|
||||
import cn.keepbx.jpom.common.interceptor.LoginInterceptor;
|
||||
@ -48,10 +51,13 @@ public class UserInfoController extends BaseServerController {
|
||||
* @return json
|
||||
*/
|
||||
@RequestMapping(value = "updatePwd", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
public String updatePwd(String oldPwd, String newPwd) {
|
||||
if (StrUtil.isEmpty(oldPwd) || StrUtil.isEmpty(newPwd)) {
|
||||
return JsonMessage.getString(400, "密码不能为空");
|
||||
}
|
||||
public String updatePwd(
|
||||
@ValidatorConfig(value = {
|
||||
@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "密码不能为空")
|
||||
}) String oldPwd,
|
||||
@ValidatorConfig(value = {
|
||||
@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "密码不能为空")
|
||||
}) String newPwd) {
|
||||
if (oldPwd.equals(newPwd)) {
|
||||
return JsonMessage.getString(400, "新旧密码一致");
|
||||
}
|
||||
@ -84,14 +90,9 @@ public class UserInfoController extends BaseServerController {
|
||||
* @return json
|
||||
*/
|
||||
@RequestMapping(value = "updateName", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
public String updateName(String name) {
|
||||
if (StrUtil.isEmpty(name)) {
|
||||
return JsonMessage.getString(405, "请输入新的昵称");
|
||||
}
|
||||
int len = name.length();
|
||||
if (len > 10 || len < 2) {
|
||||
return JsonMessage.getString(405, "昵称长度只能是2-10");
|
||||
}
|
||||
public String updateName(@ValidatorConfig(value = {
|
||||
@ValidatorItem(value = ValidatorRule.NOT_BLANK, range = "2:10", msg = "昵称长度只能是2-10")
|
||||
}) String name) {
|
||||
UserModel userModel = getUser();
|
||||
userModel = userService.getItem(userModel.getId());
|
||||
userModel.setName(name);
|
||||
|
Loading…
Reference in New Issue
Block a user