use of com.bc.pmpheep.back.util.DesRun in project pmph by BCSquad.
the class AddTestUser method addTestUser.
public void addTestUser() {
String pmphUserData = "[" + "{'username':'yewutest01','realname':'业务测试账号A','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'主任'}]}," + "{'username':'yewutest02','realname':'业务测试账号B','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'系统管理员'},{'roleName':'项目编辑'}]}," + "{'username':'yewutest03','realname':'业务测试账号C','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest04','realname':'业务测试账号D','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest05','realname':'业务测试账号E','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest06','realname':'业务测试账号F','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest07','realname':'业务测试账号J','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'主任'}]}," + "{'username':'yewutest08','realname':'业务测试账号H','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[]}," + "{'username':'yewutest09','realname':'业务测试账号I','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'数字编辑'}]}," + "{'username':'yewutest10','realname':'业务测试账号J','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'数字编辑'},{'roleName':'其他用户'}]}" + "]";
Gson gson = new Gson();
List<TestPmphUserBo> testPmphUsers = gson.fromJson(pmphUserData, new TypeToken<ArrayList<TestPmphUserBo>>() {
}.getType());
for (TestPmphUserBo user : testPmphUsers) {
PmphDepartment pmphDepartment = pmphDepartmentService.getPmphDepartmentByName(user.getDepartment());
PmphUser pmphUser = new PmphUser();
pmphUser.setUsername(user.getUsername());
pmphUser.setRealname(user.getRealname());
pmphUser.setPassword(user.getPassword());
pmphUser.setDepartmentId(pmphDepartment == null ? 0L : pmphDepartment.getId());
pmphUser.setAvatar(user.getAvatar());
pmphUser = pmphUserService.add(pmphUser);
for (PmphRole pmphRole : user.getRoles()) {
pmphRole = pmphRoleService.getByName(pmphRole.getRoleName());
PmphUserRole pmphUserRole = new PmphUserRole();
pmphUserRole.setUserId(pmphUser.getId());
pmphUserRole.setRoleId(pmphRole == null ? 0L : pmphRole.getId());
pmphUserRoleService.addPmphUserRole(pmphUserRole);
}
}
String orgData = "[" + "{'orgName':'北京测试学校','orgType':'本科','areaName':'北京市','username':'bjcsxxtest','password':'123456','realname':'北京学校管理员','avatar':'DEFAULT'," + "writerUsers:[" + "{'username':'bjzuojia01','password':'888888','nickname':'北京作家01','realname':'北京作家01'}," + "{'username':'bjzuojia02','password':'888888','nickname':'北京作家02','realname':'北京作家02'}," + "{'username':'bjzuojia03','password':'888888','nickname':'北京作家03','realname':'北京作家03'}," + "{'username':'bjzuojia04','password':'888888','nickname':'北京作家04','realname':'北京作家04'}," + "{'username':'bjzuojia05','password':'888888','nickname':'北京作家05','realname':'北京作家05'}," + "{'username':'bjzuojia06','password':'888888','nickname':'北京作家06','realname':'北京作家06'}," + "{'username':'bjzuojia07','password':'888888','nickname':'北京作家07','realname':'北京作家07'}," + "{'username':'bjzuojia08','password':'888888','nickname':'北京作家08','realname':'北京作家08'}," + "{'username':'bjzuojia09','password':'888888','nickname':'北京作家09','realname':'北京作家09'}," + "{'username':'bjzuojia10','password':'888888','nickname':'北京作家10','realname':'北京作家10'}," + "{'username':'bjzuojia11','password':'888888','nickname':'北京作家11','realname':'北京作家11'}" + "]" + "}," + "{'orgName':'天津测试学校','orgType':'本科','areaName':'天津市','username':'tjcsxxtest','password':'123456','realname':'天津学校管理员','avatar':'DEFAULT'," + "writerUsers:[" + "{'username':'tjzuojia01','password':'888888','nickname':'天津作家01','realname':'天津作家01'}," + "{'username':'tjzuojia02','password':'888888','nickname':'天津作家02','realname':'天津作家02'}," + "{'username':'tjzuojia03','password':'888888','nickname':'天津作家03','realname':'天津作家03'}," + "{'username':'tjzuojia04','password':'888888','nickname':'天津作家04','realname':'天津作家04'}," + "{'username':'tjzuojia05','password':'888888','nickname':'天津作家05','realname':'天津作家05'}," + "{'username':'tjzuojia06','password':'888888','nickname':'天津作家06','realname':'天津作家06'}," + "{'username':'tjzuojia07','password':'888888','nickname':'天津作家07','realname':'天津作家07'}," + "{'username':'tjzuojia08','password':'888888','nickname':'天津作家08','realname':'天津作家08'}," + "{'username':'tjzuojia09','password':'888888','nickname':'天津作家09','realname':'天津作家09'}," + "{'username':'tjzuojia10','password':'888888','nickname':'天津作家10','realname':'天津作家10'}," + "{'username':'tjzuojia11','password':'888888','nickname':'天津作家11','realname':'天津作家11'}" + "]" + "}" + "]";
List<TestOrgBo> orgBos = gson.fromJson(orgData, new TypeToken<ArrayList<TestOrgBo>>() {
}.getType());
for (TestOrgBo testOrgBo : orgBos) {
Org org = new Org();
org.setParentId(0L);
org.setOrgName(testOrgBo.getOrgName());
org.setOrgTypeId(orgTypeService.listOrgTypeByTypeName(testOrgBo.getOrgType()).get(0).getId());
org.setAreaId(areaService.getAreaIdByName(testOrgBo.getAreaName()));
org = orgService.addOrg(org);
OrgUser orgUser = new OrgUser();
orgUser.setUsername(testOrgBo.getUsername());
orgUser.setPassword(new DesRun("", testOrgBo.getPassword()).enpsw);
orgUser.setOrgId(org.getId());
orgUser.setRealname(testOrgBo.getRealname());
orgUser.setAvatar(testOrgBo.getAreaName());
orgUser = orgUserService.addOrgUser(orgUser);
for (WriterUser writerUser : testOrgBo.getWriterUsers()) {
writerUser.setOrgId(org.getId());
writerUserService.add(writerUser);
}
}
}
use of com.bc.pmpheep.back.util.DesRun in project pmph by BCSquad.
the class OrgUserServiceImpl method resetPassword.
@Override
public String resetPassword(Long id) throws CheckedServiceException {
if (ObjectUtil.isNull(id)) {
throw new CheckedServiceException(CheckedExceptionBusiness.ORG, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
String password = "123456";
OrgUser orgUser = orgUserDao.getOrgUserById(id);
DesRun desRun = new DesRun(orgUser.getUsername(), password);
orgUser.setPassword(desRun.enpsw);
orgUserDao.updateOrgUser(orgUser);
return password;
}
use of com.bc.pmpheep.back.util.DesRun in project pmph by BCSquad.
the class WriterUserServiceImpl method addWriterUserOfBack.
@Override
public String addWriterUserOfBack(WriterUser writerUser) throws CheckedServiceException {
WriterUser username = writerUserDao.getUsername(writerUser.getUsername());
if (username != null) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "用户代码已存在");
}
if (StringUtil.strLength(writerUser.getUsername()) > 20) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "用户名需要小于20字符");
}
if (StringUtil.strLength(writerUser.getRealname()) > 20) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "姓名需要小于20字符");
}
if (!StringUtil.isEmpty(writerUser.getHandphone())) {
if (!ValidatUtil.checkMobileNumber(writerUser.getHandphone())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "电话格式不正确");
}
}
if (!StringUtil.isEmpty(writerUser.getEmail())) {
if (!ValidatUtil.checkEmail(writerUser.getEmail())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "邮箱格式不正确");
}
}
if (StringUtil.isEmpty(writerUser.getUsername())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户名为空");
}
if (StringUtil.isEmpty(writerUser.getRealname())) {
writerUser.setRealname(writerUser.getUsername());
}
if (!StringUtil.isEmpty(writerUser.getNote())) {
if (StringUtil.strLength(writerUser.getNote()) > 100) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "备注需要小于100字符");
}
}
// 后台添加用户设置默认密码为123456
writerUser.setPassword(new DesRun("", Const.DEFAULT_PASSWORD).enpsw);
writerUser.setNickname(writerUser.getUsername());
// 后台添加新用户时,设置为默认头像
writerUser.setAvatar(RouteUtil.DEFAULT_USER_AVATAR);
writerUserDao.add(writerUser);
Long num = writerUser.getId();
String result = "FAIL";
if (num > 0) {
WriterProfile writerProfile = new WriterProfile();
writerProfile.setUserId(num);
writerProfileDao.addWriterProfile(writerProfile);
result = "SUCCESS";
}
return result;
}
use of com.bc.pmpheep.back.util.DesRun in project pmph by BCSquad.
the class PmphUserServiceImpl method updatePassword.
@Override
public Integer updatePassword(HttpServletRequest request, String oldPassword, String newPassword) {
// 获取当前用户
String sessionId = CookiesUtil.getSessionId(request);
PmphUser sessionPmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == sessionPmphUser) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "请求用户不存在");
}
Long id = sessionPmphUser.getId();
if (null == id) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户ID为空时禁止查询");
}
if (StringUtil.isEmpty(oldPassword)) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "原密码为空");
}
if (StringUtil.isEmpty(newPassword)) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "新密码为空");
}
oldPassword = oldPassword.trim();
newPassword = newPassword.trim();
if (newPassword.length() > 50) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "新密码长度不能超过50");
}
if (oldPassword.equals(newPassword)) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "新旧密码不能一致");
}
// 先修改SSO
// ---------------------------------
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", id);
// 加密密码
map.put("oldPassword", new DesRun("", oldPassword).enpsw);
map.put("newPassword", new DesRun("", newPassword).enpsw);
Integer res = pmphUserDao.updatePassword(map);
if (null == res || res == 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "原密码错误");
}
return 1;
}
use of com.bc.pmpheep.back.util.DesRun in project pmph by BCSquad.
the class PmphLoginController method login.
/**
* <pre>
* 功能描述:登陆
* 使用示范:
*
* @param user
* @param model
* @return
* </pre>
*
* //* @throws SingleSignOnException
*/
@ResponseBody
@OAuthRequired
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ResponseBean login(@RequestParam(value = "username", required = false) String username, @RequestParam(value = "password", required = false) String password, @RequestParam(value = "wechatUserId", required = false) String wechatUserId, @RequestParam(value = "token", required = false) String token, HttpServletRequest request) throws CheckedServiceException {
Map<String, Object> resultMap = new HashMap<String, Object>();
logger.info("username => " + username);
logger.info("password => " + password);
// HttpSingleSignOnService service = new HttpSingleSignOnService();
// String url = service.getSingleSignOnURL();
// try {
// 判断是否从企业微信App登陆
String userAgent = request.getHeader("user-agent").toLowerCase();
Boolean isTrue = userAgent == null || userAgent.indexOf("micromessenger") == -1 ? false : true;
if (isTrue) {
if (StringUtil.notEmpty(token)) {
String newToken = username + password + wechatUserId + "<pmpheep>";
if (!newToken.equals(new DesRun(token).depsw)) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户名密码错误!");
}
}
username = new DesRun(username).depsw;
password = new DesRun(password).depsw;
}
if (StringUtil.isEmpty(username) || StringUtil.isEmpty(password)) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "请输入用户名和密码!");
}
PmphUser pmphUser = pmphUserService.login(username, new DesRun("", password).enpsw);
// PmphUser pmphUser = pmphUserService.login(userName, null);
pmphUser.setLoginType(Const.LOGIN_TYPE_PMPH);
if (!RouteUtil.DEFAULT_USER_AVATAR.equals(pmphUser.getAvatar())) {
pmphUser.setAvatar(RouteUtil.userAvatar(pmphUser.getAvatar()));
}
// 根据用户Id查询对应角色(是否为管理员)
List<PmphRole> pmphRoles = pmphRoleService.getPmphRoleByUserId(pmphUser.getId());
if (pmphRoles.isEmpty()) {
// 添加默认权限
pmphRoleService.addUserRole(pmphUser.getId(), 2L);
pmphRoles = pmphRoleService.getPmphRoleByUserId(pmphUser.getId());
}
List<Long> roleIds = new ArrayList<Long>();
for (PmphRole pmphRole : pmphRoles) {
roleIds.add(pmphRole.getId());
if (ObjectUtil.notNull(pmphRole)) {
if (Const.LOGIN_USER_IS_ADMIN.equals(pmphRole.getRoleName()) || Const.LOGIN_USER_IS_ADMINS.equals(pmphRole.getRoleName()) || Const.LOGIN_SYS_USER_IS_ADMIN.equals(pmphRole.getRoleName())) {
pmphUser.setIsAdmin(true);
} else {
pmphUser.setIsAdmin(false);
}
}
if (Const.TRUE == pmphUser.getIsAdmin()) {
break;
}
}
// 根据用户Id查询对应权限Id
List<Long> pmphUserPermissionIds = pmphUserService.getPmphUserPermissionByUserId(pmphUser.getId());
// 判断是否从企业微信App登陆
if (isTrue) {
PmphUserWechat pmphUserWechat = pmphUserWechatService.getPmphUserWechatByWechatId(wechatUserId);
if (ObjectUtil.isNull(pmphUserWechat)) {
pmphUserWechatService.add(new PmphUserWechat(username, wechatUserId));
}
}
// String materialPermission =
// pmphUserService.getMaterialPermissionByUserId(pmphUser.getId()); 根据用户返回书籍
// 验证成功在Session中保存用户信息
request.getSession().setAttribute(Const.SESSION_PMPH_USER, pmphUser);
// 验证成功在Session中保存用户Token信息
request.getSession().setAttribute(Const.SEESION_PMPH_USER_TOKEN, new DesRun(password, username).enpsw);
// pmphUserSessionId
resultMap.put(Const.USER_SEESION_ID, request.getSession().getId());
resultMap.put(Const.SESSION_PMPH_USER, pmphUser);
resultMap.put(Const.SEESION_PMPH_USER_TOKEN, new DesRun(password, username).enpsw);
resultMap.put("pmphUserPermissionIds", pmphUserPermissionIds);
// resultMap.put("materialPermission", materialPermission);
return new ResponseBean(resultMap);
// } catch (CheckedServiceException cException) {
// return new ResponseBean(cException);
// }
}
Aggregations