禁止注册和添加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,38 +223,43 @@ 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{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER, if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginame())) {
BusinessConstants.LOG_OPERATION_TYPE_ADD, throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
//检查用户名和登录名 } else {
checkUserNameAndLoginName(ue); logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER,
//新增用户信息 BusinessConstants.LOG_OPERATION_TYPE_ADD,
ue= this.addUser(ue); ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
if(ue==null){ //检查用户名和登录名
logger.error("异常码[{}],异常提示[{}],参数,[{}]", checkUserNameAndLoginName(ue);
ExceptionConstants.USER_ADD_FAILED_CODE,ExceptionConstants.USER_ADD_FAILED_MSG); //新增用户信息
throw new BusinessRunTimeException(ExceptionConstants.USER_ADD_FAILED_CODE, ue= this.addUser(ue);
ExceptionConstants.USER_ADD_FAILED_MSG); if(ue==null){
} logger.error("异常码[{}],异常提示[{}],参数,[{}]",
if(ue.getOrgaId()==null){ ExceptionConstants.USER_ADD_FAILED_CODE,ExceptionConstants.USER_ADD_FAILED_MSG);
//如果没有选择机构,就不建机构和用户的关联关系 throw new BusinessRunTimeException(ExceptionConstants.USER_ADD_FAILED_CODE,
return; ExceptionConstants.USER_ADD_FAILED_MSG);
} }
//新增用户和机构关联关系 if(ue.getOrgaId()==null){
OrgaUserRel oul=new OrgaUserRel(); //如果没有选择机构,就不建机构和用户的关联关系
//机构id return;
oul.setOrgaId(ue.getOrgaId()); }
//用户id //新增用户和机构关联关系
oul.setUserId(ue.getId()); OrgaUserRel oul=new OrgaUserRel();
//用户在机构中的排序 //机构id
oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq()); oul.setOrgaId(ue.getOrgaId());
//用户id
oul.setUserId(ue.getId());
//用户在机构中的排序
oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq());
oul=orgaUserRelService.addOrgaUserRel(oul); oul=orgaUserRelService.addOrgaUserRel(oul);
if(oul==null){ if(oul==null){
logger.error("异常码[{}],异常提示[{}],参数,[{}]", logger.error("异常码[{}],异常提示[{}],参数,[{}]",
ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE,ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG); ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE,ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG);
throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE, throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE,
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)
@@ -288,30 +293,35 @@ public class UserService {
* description: * description:
* 多次创建事务,事物之间无法协同,应该在入口处创建一个事务以做协调 * 多次创建事务,事物之间无法协同,应该在入口处创建一个事务以做协调
*/ */
ue.setPassword(Tools.md5Encryp(ue.getPassword())); if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginame())) {
ue.setIsystem(BusinessConstants.USER_NOT_SYSTEM); throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
if(ue.getIsmanager()==null){ ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER); } else {
ue.setPassword(Tools.md5Encryp(ue.getPassword()));
ue.setIsystem(BusinessConstants.USER_NOT_SYSTEM);
if (ue.getIsmanager() == null) {
ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER);
}
ue.setStatus(BusinessConstants.USER_STATUS_NORMAL);
int i = userMapperEx.addUser(ue);
//更新租户id
User user = new User();
user.setId(ue.getId());
user.setTenantId(ue.getId());
userService.updateUserTenant(user);
//新增用户与角色的关系
JSONObject ubObj = new JSONObject();
ubObj.put("type", "UserRole");
ubObj.put("keyid", ue.getId());
JSONArray ubArr = new JSONArray();
ubArr.add(manageRoleId);
ubObj.put("value", ubArr.toString());
userBusinessService.insertUserBusiness(ubObj.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
if (i > 0) {
return ue;
}
return null;
} }
ue.setStatus(BusinessConstants.USER_STATUS_NORMAL);
int i=userMapperEx.addUser(ue);
//更新租户id
User user = new User();
user.setId(ue.getId());
user.setTenantId(ue.getId());
userService.updateUserTenant(user);
//新增用户与角色的关系
JSONObject ubObj = new JSONObject();
ubObj.put("type", "UserRole");
ubObj.put("keyid", ue.getId());
JSONArray ubArr = new JSONArray();
ubArr.add(manageRoleId);
ubObj.put("value", ubArr.toString());
userBusinessService.insertUserBusiness(ubObj.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
if(i>0){
return ue;
}
return null;
} }
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
@@ -323,47 +333,51 @@ 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{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER, if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginame())) {
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ue.getId()).toString(), throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
//检查用户名和登录名 } else {
checkUserNameAndLoginName(ue); logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER,
//更新用户信息 new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ue.getId()).toString(),
ue=this.updateUser(ue); ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
if(ue==null){ //检查用户名和登录名
logger.error("异常码[{}],异常提示[{}],参数,[{}]", checkUserNameAndLoginName(ue);
ExceptionConstants.USER_EDIT_FAILED_CODE,ExceptionConstants.USER_EDIT_FAILED_MSG); //更新用户信息
throw new BusinessRunTimeException(ExceptionConstants.USER_EDIT_FAILED_CODE, ue = this.updateUser(ue);
ExceptionConstants.USER_EDIT_FAILED_MSG); if (ue == null) {
logger.error("异常码[{}],异常提示[{}],参数,[{}]",
ExceptionConstants.USER_EDIT_FAILED_CODE, ExceptionConstants.USER_EDIT_FAILED_MSG);
throw new BusinessRunTimeException(ExceptionConstants.USER_EDIT_FAILED_CODE,
ExceptionConstants.USER_EDIT_FAILED_MSG);
}
if (ue.getOrgaId() == null) {
//如果没有选择机构,就不建机构和用户的关联关系
return;
}
//更新用户和机构关联关系
OrgaUserRel oul = new OrgaUserRel();
//机构和用户关联关系id
oul.setId(ue.getOrgaUserRelId());
//机构id
oul.setOrgaId(ue.getOrgaId());
//用户id
oul.setUserId(ue.getId());
//用户在机构中的排序
oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq());
if (oul.getId() != null) {
//已存在机构和用户的关联关系,更新
oul = orgaUserRelService.updateOrgaUserRel(oul);
} else {
//不存在机构和用户的关联关系,新建
oul = orgaUserRelService.addOrgaUserRel(oul);
}
if (oul == null) {
logger.error("异常码[{}],异常提示[{}],参数,[{}]",
ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE, ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG);
throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE,
ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG);
}
} }
if(ue.getOrgaId()==null){
//如果没有选择机构,就不建机构和用户的关联关系
return;
}
//更新用户和机构关联关系
OrgaUserRel oul=new OrgaUserRel();
//机构和用户关联关系id
oul.setId(ue.getOrgaUserRelId());
//机构id
oul.setOrgaId(ue.getOrgaId());
//用户id
oul.setUserId(ue.getId());
//用户在机构中的排序
oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq());
if(oul.getId()!=null){
//已存在机构和用户的关联关系,更新
oul=orgaUserRelService.updateOrgaUserRel(oul);
}else{
//不存在机构和用户的关联关系,新建
oul=orgaUserRelService.addOrgaUserRel(oul);
}
if(oul==null){
logger.error("异常码[{}],异常提示[{}],参数,[{}]",
ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE,ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG);
throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE,
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){