禁止注册和添加admin用户

This commit is contained in:
季圣华
2019-04-13 20:21:36 +08:00
parent 40fc728e58
commit 491e44b0b2
4 changed files with 117 additions and 95 deletions

View File

@@ -75,7 +75,7 @@
if (res && res.code === 200) { if (res && res.code === 200) {
alert("注册成功!"); alert("注册成功!");
} else { } else {
alert("注册失败!"); alert(res.msg);
} }
}, },
//此处添加错误处理 //此处添加错误处理

View File

@@ -208,6 +208,11 @@ public class BusinessConstants {
public static final String DELETE_TYPE_NORMAL = "1"; public static final String DELETE_TYPE_NORMAL = "1";
public static final String DELETE_TYPE_FORCE = "2"; public static final String DELETE_TYPE_FORCE = "2";
/**
* 默认管理员账号
*/
public static final String DEFAULT_MANAGER = "admin";

View File

@@ -56,6 +56,9 @@ public class ExceptionConstants {
//用户录入数量超出限制 //用户录入数量超出限制
public static final int USER_OVER_LIMIT_FAILED_CODE = 500004; public static final int USER_OVER_LIMIT_FAILED_CODE = 500004;
public static final String USER_OVER_LIMIT_FAILED_MSG = "用户录入数量超出限制,请联系管理员续费"; public static final String USER_OVER_LIMIT_FAILED_MSG = "用户录入数量超出限制,请联系管理员续费";
//此用户名限制使用
public static final int USER_NAME_LIMIT_USE_CODE = 500004;
public static final String USER_NAME_LIMIT_USE_MSG = "此用户名限制使用";
/** /**
* 角色信息 * 角色信息

View File

@@ -223,6 +223,10 @@ public class UserService {
} }
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void addUserAndOrgUserRel(UserEx ue) throws Exception{ public void addUserAndOrgUserRel(UserEx ue) throws Exception{
if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginame())) {
throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
} else {
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER, logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER,
BusinessConstants.LOG_OPERATION_TYPE_ADD, BusinessConstants.LOG_OPERATION_TYPE_ADD,
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
@@ -257,6 +261,7 @@ public class UserService {
ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG); ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG);
} }
} }
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public UserEx addUser(UserEx ue) throws Exception{ public UserEx addUser(UserEx ue) throws Exception{
/** /**
@@ -288,13 +293,17 @@ public class UserService {
* description: * description:
* 多次创建事务,事物之间无法协同,应该在入口处创建一个事务以做协调 * 多次创建事务,事物之间无法协同,应该在入口处创建一个事务以做协调
*/ */
if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginame())) {
throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
} else {
ue.setPassword(Tools.md5Encryp(ue.getPassword())); ue.setPassword(Tools.md5Encryp(ue.getPassword()));
ue.setIsystem(BusinessConstants.USER_NOT_SYSTEM); ue.setIsystem(BusinessConstants.USER_NOT_SYSTEM);
if(ue.getIsmanager()==null){ if (ue.getIsmanager() == null) {
ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER); ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER);
} }
ue.setStatus(BusinessConstants.USER_STATUS_NORMAL); ue.setStatus(BusinessConstants.USER_STATUS_NORMAL);
int i=userMapperEx.addUser(ue); int i = userMapperEx.addUser(ue);
//更新租户id //更新租户id
User user = new User(); User user = new User();
user.setId(ue.getId()); user.setId(ue.getId());
@@ -308,11 +317,12 @@ public class UserService {
ubArr.add(manageRoleId); ubArr.add(manageRoleId);
ubObj.put("value", ubArr.toString()); ubObj.put("value", ubArr.toString());
userBusinessService.insertUserBusiness(ubObj.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); userBusinessService.insertUserBusiness(ubObj.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
if(i>0){ if (i > 0) {
return ue; return ue;
} }
return null; return null;
} }
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateUserTenant(User user) throws Exception{ public void updateUserTenant(User user) throws Exception{
@@ -323,25 +333,29 @@ public class UserService {
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateUserAndOrgUserRel(UserEx ue) throws Exception{ public void updateUserAndOrgUserRel(UserEx ue) throws Exception{
if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginame())) {
throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
} else {
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER, logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ue.getId()).toString(), new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ue.getId()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
//检查用户名和登录名 //检查用户名和登录名
checkUserNameAndLoginName(ue); checkUserNameAndLoginName(ue);
//更新用户信息 //更新用户信息
ue=this.updateUser(ue); ue = this.updateUser(ue);
if(ue==null){ if (ue == null) {
logger.error("异常码[{}],异常提示[{}],参数,[{}]", logger.error("异常码[{}],异常提示[{}],参数,[{}]",
ExceptionConstants.USER_EDIT_FAILED_CODE,ExceptionConstants.USER_EDIT_FAILED_MSG); ExceptionConstants.USER_EDIT_FAILED_CODE, ExceptionConstants.USER_EDIT_FAILED_MSG);
throw new BusinessRunTimeException(ExceptionConstants.USER_EDIT_FAILED_CODE, throw new BusinessRunTimeException(ExceptionConstants.USER_EDIT_FAILED_CODE,
ExceptionConstants.USER_EDIT_FAILED_MSG); ExceptionConstants.USER_EDIT_FAILED_MSG);
} }
if(ue.getOrgaId()==null){ if (ue.getOrgaId() == null) {
//如果没有选择机构,就不建机构和用户的关联关系 //如果没有选择机构,就不建机构和用户的关联关系
return; return;
} }
//更新用户和机构关联关系 //更新用户和机构关联关系
OrgaUserRel oul=new OrgaUserRel(); OrgaUserRel oul = new OrgaUserRel();
//机构和用户关联关系id //机构和用户关联关系id
oul.setId(ue.getOrgaUserRelId()); oul.setId(ue.getOrgaUserRelId());
//机构id //机构id
@@ -350,20 +364,20 @@ public class UserService {
oul.setUserId(ue.getId()); oul.setUserId(ue.getId());
//用户在机构中的排序 //用户在机构中的排序
oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq()); oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq());
if(oul.getId()!=null){ if (oul.getId() != null) {
//已存在机构和用户的关联关系,更新 //已存在机构和用户的关联关系,更新
oul=orgaUserRelService.updateOrgaUserRel(oul); oul = orgaUserRelService.updateOrgaUserRel(oul);
}else{ } else {
//不存在机构和用户的关联关系,新建 //不存在机构和用户的关联关系,新建
oul=orgaUserRelService.addOrgaUserRel(oul); oul = orgaUserRelService.addOrgaUserRel(oul);
} }
if(oul==null){ if (oul == null) {
logger.error("异常码[{}],异常提示[{}],参数,[{}]", logger.error("异常码[{}],异常提示[{}],参数,[{}]",
ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE,ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG); ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE, ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG);
throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE, throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE,
ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG); ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG);
} }
}
} }
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public UserEx updateUser(UserEx ue){ public UserEx updateUser(UserEx ue){