Java Code Examples for org.jeecg.modules.system.entity.SysUser#setPassword()

The following examples show how to use org.jeecg.modules.system.entity.SysUser#setPassword() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SysUserDepartServiceImpl.java    From jeecg-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * 根据部门id查询用户信息
 */
@Override
public List<SysUser> queryUserByDepId(String depId) {
	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	queryUDep.eq(SysUserDepart::getDepId, depId);
	List<String> userIdList = new ArrayList<>();
	List<SysUserDepart> uDepList = this.list(queryUDep);
	if(uDepList != null && uDepList.size() > 0) {
		for(SysUserDepart uDep : uDepList) {
			userIdList.add(uDep.getUserId());
		}
		List<SysUser> userList = (List<SysUser>) sysUserService.listByIds(userIdList);
		//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		for (SysUser sysUser : userList) {
			sysUser.setSalt("");
			sysUser.setPassword("");
		}
		//update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		return userList;
	}
	return new ArrayList<SysUser>();
}
 
Example 2
Source File: SysUserDepartServiceImpl.java    From jeecg-boot-with-activiti with MIT License 6 votes vote down vote up
/**
 * 根据部门id查询用户信息
 */
@Override
public List<SysUser> queryUserByDepId(String depId) {
	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	queryUDep.eq(SysUserDepart::getDepId, depId);
	List<String> userIdList = new ArrayList<>();
	List<SysUserDepart> uDepList = this.list(queryUDep);
	if(uDepList != null && uDepList.size() > 0) {
		for(SysUserDepart uDep : uDepList) {
			userIdList.add(uDep.getUserId());
		}
		List<SysUser> userList = (List<SysUser>) sysUserService.listByIds(userIdList);
		//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		for (SysUser sysUser : userList) {
			sysUser.setSalt("");
			sysUser.setPassword("");
		}
		//update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		return userList;
	}
	return new ArrayList<SysUser>();
}
 
Example 3
Source File: TeachingUserController.java    From teaching with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
public Result<SysUser> edit(@RequestBody JSONObject jsonObject) {
    Result<SysUser> result = new Result<SysUser>();
    try {
        SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
        sysBaseAPI.addLog("修改用户资料,id: " +jsonObject.getString("id") , CommonConstant.LOG_TYPE_2, 2);
        if(sysUser==null) {
            result.error500("未找到对应实体");
        }else {
            SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
            user.setUpdateTime(new Date());
            //String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), sysUser.getSalt());
            user.setPassword(sysUser.getPassword());
            sysUserService.updateById(user);
            result.success("修改成功!");
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        result.error500("操作失败");
    }
    return result;
}
 
Example 4
Source File: SysUserController.java    From teaching with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/add", method = RequestMethod.POST)
   @RequiresPermissions("user:add")
public Result<SysUser> add(@RequestBody JSONObject jsonObject) {
	Result<SysUser> result = new Result<SysUser>();
	String selectedRoles = jsonObject.getString("selectedroles");
	String selectedDeparts = jsonObject.getString("selecteddeparts");
	try {
		SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
		user.setCreateTime(new Date());//设置创建时间
		String salt = oConvertUtils.randomGen(8);
		user.setSalt(salt);
		String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
		user.setPassword(passwordEncode);
		user.setStatus(1);
		user.setDelFlag("0");
		sysUserService.addUserWithRole(user, selectedRoles);
           sysUserService.addUserWithDepart(user, selectedDeparts);
		result.success("添加成功!");
	} catch (Exception e) {
		log.error(e.getMessage(), e);
		result.error500("操作失败");
	}
	return result;
}
 
Example 5
Source File: SysUserController.java    From teaching with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
   //@RequiresPermissions("user:edit")
public Result<SysUser> edit(@RequestBody JSONObject jsonObject) {
	Result<SysUser> result = new Result<SysUser>();
	try {
		SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
		sysBaseAPI.addLog("编辑用户,id: " +jsonObject.getString("id") ,CommonConstant.LOG_TYPE_2, 2);
		if(sysUser==null) {
			result.error500("未找到对应实体");
		}else {
			SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
			user.setUpdateTime(new Date());
			//String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), sysUser.getSalt());
			user.setPassword(sysUser.getPassword());
			String roles = jsonObject.getString("selectedroles");
               String departs = jsonObject.getString("selecteddeparts");
			sysUserService.editUserWithRole(user, roles);
               sysUserService.editUserWithDepart(user, departs);
			result.success("修改成功!");
		}
	} catch (Exception e) {
		log.error(e.getMessage(), e);
		result.error500("操作失败");
	}
	return result;
}
 
Example 6
Source File: SysUserDepartServiceImpl.java    From teaching with Apache License 2.0 6 votes vote down vote up
/**
 * 根据部门id查询用户信息
 */
@Override
public List<SysUser> queryUserByDepId(String depId) {
	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	queryUDep.eq(SysUserDepart::getDepId, depId);
	List<String> userIdList = new ArrayList<>();
	List<SysUserDepart> uDepList = this.list(queryUDep);
	if(uDepList != null && uDepList.size() > 0) {
		for(SysUserDepart uDep : uDepList) {
			userIdList.add(uDep.getUserId());
		}
		List<SysUser> userList = (List<SysUser>) sysUserService.listByIds(userIdList);
		//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		for (SysUser sysUser : userList) {
			sysUser.setSalt("");
			sysUser.setPassword("");
		}
		//update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		return userList;
	}
	return new ArrayList<SysUser>();
}
 
Example 7
Source File: SysUserDepartServiceImpl.java    From jeecg-boot with Apache License 2.0 6 votes vote down vote up
/**
 * 根据部门id查询用户信息
 */
@Override
public List<SysUser> queryUserByDepId(String depId) {
	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	queryUDep.eq(SysUserDepart::getDepId, depId);
	List<String> userIdList = new ArrayList<>();
	List<SysUserDepart> uDepList = this.list(queryUDep);
	if(uDepList != null && uDepList.size() > 0) {
		for(SysUserDepart uDep : uDepList) {
			userIdList.add(uDep.getUserId());
		}
		List<SysUser> userList = (List<SysUser>) sysUserService.listByIds(userIdList);
		//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		for (SysUser sysUser : userList) {
			sysUser.setSalt("");
			sysUser.setPassword("");
		}
		//update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		return userList;
	}
	return new ArrayList<SysUser>();
}
 
Example 8
Source File: SysUserDepartServiceImpl.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 根据部门code,查询当前部门和下级部门的 用户信息
 */
@Override
public List<SysUser> queryUserByDepCode(String depCode,String realname) {
	LambdaQueryWrapper<SysDepart> queryByDepCode = new LambdaQueryWrapper<SysDepart>();
	queryByDepCode.likeRight(SysDepart::getOrgCode,depCode);
	List<SysDepart> sysDepartList = sysDepartService.list(queryByDepCode);
	List<String> depIds = sysDepartList.stream().map(SysDepart::getId).collect(Collectors.toList());

	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	queryUDep.in(SysUserDepart::getDepId, depIds);
	List<String> userIdList = new ArrayList<>();
	List<SysUserDepart> uDepList = this.list(queryUDep);
	if(uDepList != null && uDepList.size() > 0) {
		for(SysUserDepart uDep : uDepList) {
			userIdList.add(uDep.getUserId());
		}
		LambdaQueryWrapper<SysUser> queryUser = new LambdaQueryWrapper<SysUser>();
		queryUser.in(SysUser::getId,userIdList);
		if(oConvertUtils.isNotEmpty(realname)){
			queryUser.like(SysUser::getRealname,realname.trim());
		}
		List<SysUser> userList = (List<SysUser>) sysUserService.list(queryUser);
		//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		for (SysUser sysUser : userList) {
			sysUser.setSalt("");
			sysUser.setPassword("");
		}
		//update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		return userList;
	}
	return new ArrayList<SysUser>();
}
 
Example 9
Source File: SysUserDepartServiceImpl.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 根据部门code,查询当前部门和下级部门的 用户信息
 */
@Override
public List<SysUser> queryUserByDepCode(String depCode) {
	LambdaQueryWrapper<SysDepart> queryByDepCode = new LambdaQueryWrapper<SysDepart>();
	queryByDepCode.likeRight(SysDepart::getOrgCode,depCode);
	List<SysDepart> sysDepartList = sysDepartService.list(queryByDepCode);
	List<String> depIds = sysDepartList.stream().map(SysDepart::getId).collect(Collectors.toList());

	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	queryUDep.in(SysUserDepart::getDepId, depIds);
	List<String> userIdList = new ArrayList<>();
	List<SysUserDepart> uDepList = this.list(queryUDep);
	if(uDepList != null && uDepList.size() > 0) {
		for(SysUserDepart uDep : uDepList) {
			userIdList.add(uDep.getUserId());
		}
		List<SysUser> userList = (List<SysUser>) sysUserService.listByIds(userIdList);
		//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		for (SysUser sysUser : userList) {
			sysUser.setSalt("");
			sysUser.setPassword("");
		}
		//update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		return userList;
	}
	return new ArrayList<SysUser>();
}
 
Example 10
Source File: SysUserDepartServiceImpl.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 根据部门code,查询当前部门和下级部门的 用户信息
 */
@Override
public List<SysUser> queryUserByDepCode(String depCode,String realname) {
	LambdaQueryWrapper<SysDepart> queryByDepCode = new LambdaQueryWrapper<SysDepart>();
	queryByDepCode.likeRight(SysDepart::getOrgCode,depCode);
	List<SysDepart> sysDepartList = sysDepartService.list(queryByDepCode);
	List<String> depIds = sysDepartList.stream().map(SysDepart::getId).collect(Collectors.toList());

	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	queryUDep.in(SysUserDepart::getDepId, depIds);
	List<String> userIdList = new ArrayList<>();
	List<SysUserDepart> uDepList = this.list(queryUDep);
	if(uDepList != null && uDepList.size() > 0) {
		for(SysUserDepart uDep : uDepList) {
			userIdList.add(uDep.getUserId());
		}
		LambdaQueryWrapper<SysUser> queryUser = new LambdaQueryWrapper<SysUser>();
		queryUser.in(SysUser::getId,userIdList);
		if(oConvertUtils.isNotEmpty(realname)){
			queryUser.like(SysUser::getRealname,realname.trim());
		}
		List<SysUser> userList = (List<SysUser>) sysUserService.list(queryUser);
		//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		for (SysUser sysUser : userList) {
			sysUser.setSalt("");
			sysUser.setPassword("");
		}
		//update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		return userList;
	}
	return new ArrayList<SysUser>();
}
 
Example 11
Source File: SysUserController.java    From teaching with Apache License 2.0 4 votes vote down vote up
/**
 * 用户注册接口
 * 
 * @param jsonObject
 * @param user
 * @return
 */
@PostMapping("/register")
public Result<JSONObject> userRegister(@RequestBody JSONObject jsonObject, SysUser user) {
	Result<JSONObject> result = new Result<JSONObject>();
	String phone = jsonObject.getString("phone");
	String smscode = jsonObject.getString("smscode");
	Object code = redisUtil.get(phone);
	String username = jsonObject.getString("username");
	//未设置用户名,则用手机号作为用户名
	if(oConvertUtils.isEmpty(username)){
           username = phone;
       }
       //未设置密码,则随机生成一个密码
	String password = jsonObject.getString("password");
	if(oConvertUtils.isEmpty(password)){
           password = RandomUtil.randomString(8);
       }
	String email = jsonObject.getString("email");
	SysUser sysUser1 = sysUserService.getUserByName(username);
	if (sysUser1 != null) {
		result.setMessage("用户名已注册");
		result.setSuccess(false);
		return result;
	}
	SysUser sysUser2 = sysUserService.getUserByPhone(phone);
	if (sysUser2 != null) {
		result.setMessage("该手机号已注册");
		result.setSuccess(false);
		return result;
	}

	if(oConvertUtils.isNotEmpty(email)){
           SysUser sysUser3 = sysUserService.getUserByEmail(email);
           if (sysUser3 != null) {
               result.setMessage("邮箱已被注册");
               result.setSuccess(false);
               return result;
           }
       }

	if (!smscode.equals(code)) {
		result.setMessage("手机验证码错误");
		result.setSuccess(false);
		return result;
	}

	try {
		user.setCreateTime(new Date());// 设置创建时间
		String salt = oConvertUtils.randomGen(8);
		String passwordEncode = PasswordUtil.encrypt(username, password, salt);
		user.setSalt(salt);
		user.setUsername(username);
		user.setRealname(username);
		user.setPassword(passwordEncode);
		user.setEmail(email);
		user.setPhone(phone);
		user.setStatus(1);
		user.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
		user.setActivitiSync(CommonConstant.ACT_SYNC_1);
		sysUserService.addUserWithRole(user,"ee8626f80f7c2619917b6236f3a7f02b");//默认临时角色 test
		result.success("注册成功");
	} catch (Exception e) {
		result.error500("注册失败");
	}
	return result;
}
 
Example 12
Source File: SysUserController.java    From teaching with Apache License 2.0 4 votes vote down vote up
/**
 * 用户更改密码
 */
@GetMapping("/passwordChange")
public Result<SysUser> passwordChange(@RequestParam(name="username")String username,
									  @RequestParam(name="password")String password,
		                              @RequestParam(name="smscode")String smscode,
		                              @RequestParam(name="phone") String phone) {
       Result<SysUser> result = new Result<SysUser>();
       if(oConvertUtils.isEmpty(username) || oConvertUtils.isEmpty(password) || oConvertUtils.isEmpty(smscode)  || oConvertUtils.isEmpty(phone) ) {
           result.setMessage("重置密码失败!");
           result.setSuccess(false);
           return result;
       }

       SysUser sysUser=new SysUser();
       Object object= redisUtil.get(phone);
       if(null==object) {
       	result.setMessage("短信验证码失效!");
           result.setSuccess(false);
           return result;
       }
       if(!smscode.equals(object)) {
       	result.setMessage("短信验证码不匹配!");
           result.setSuccess(false);
           return result;
       }
       sysUser = this.sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername,username).eq(SysUser::getPhone,phone));
       if (sysUser == null) {
           result.setMessage("未找到用户!");
           result.setSuccess(false);
           return result;
       } else {
           String salt = oConvertUtils.randomGen(8);
           sysUser.setSalt(salt);
           String passwordEncode = PasswordUtil.encrypt(sysUser.getUsername(), password, salt);
           sysUser.setPassword(passwordEncode);
           this.sysUserService.updateById(sysUser);
           result.setSuccess(true);
           result.setMessage("密码重置完成!");
           return result;
       }
   }