org.jeecg.common.util.PasswordUtil Java Examples

The following examples show how to use org.jeecg.common.util.PasswordUtil. 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: SysUserController.java    From jeecg-cloud 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(CommonConstant.DEL_FLAG_0);
		sysUserService.addUserWithRole(user, selectedRoles);
           sysUserService.addUserWithDepart(user, selectedDeparts);
		result.success("添加成功!");
	} catch (Exception e) {
		log.error(e.getMessage(), e);
		result.error500("操作失败");
	}
	return result;
}
 
Example #2
Source File: SysUserServiceImpl.java    From jeecg-boot with Apache License 2.0 6 votes vote down vote up
@Override
@CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
public Result<?> resetPassword(String username, String oldpassword, String newpassword, String confirmpassword) {
    SysUser user = userMapper.getUserByName(username);
    String passwordEncode = PasswordUtil.encrypt(username, oldpassword, user.getSalt());
    if (!user.getPassword().equals(passwordEncode)) {
        return Result.error("旧密码输入错误!");
    }
    if (oConvertUtils.isEmpty(newpassword)) {
        return Result.error("新密码不允许为空!");
    }
    if (!newpassword.equals(confirmpassword)) {
        return Result.error("两次输入密码不一致!");
    }
    String password = PasswordUtil.encrypt(username, newpassword, user.getSalt());
    this.userMapper.update(new SysUser().setPassword(password), new LambdaQueryWrapper<SysUser>().eq(SysUser::getId, user.getId()));
    return Result.ok("密码重置成功!");
}
 
Example #3
Source File: SysUserServiceImpl.java    From jeecg-cloud with Apache License 2.0 6 votes vote down vote up
@Override
@CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
public Result<?> resetPassword(String username, String oldpassword, String newpassword, String confirmpassword) {
    SysUser user = userMapper.getUserByName(username);
    String passwordEncode = PasswordUtil.encrypt(username, oldpassword, user.getSalt());
    if (!user.getPassword().equals(passwordEncode)) {
        return Result.error("旧密码输入错误!");
    }
    if (oConvertUtils.isEmpty(newpassword)) {
        return Result.error("新密码不允许为空!");
    }
    if (!newpassword.equals(confirmpassword)) {
        return Result.error("两次输入密码不一致!");
    }
    String password = PasswordUtil.encrypt(username, newpassword, user.getSalt());
    this.userMapper.update(new SysUser().setPassword(password), new LambdaQueryWrapper<SysUser>().eq(SysUser::getId, user.getId()));
    return Result.ok("密码重置成功!");
}
 
Example #4
Source File: SysUserController.java    From jeecg-boot 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(CommonConstant.DEL_FLAG_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 jeecg-boot-with-activiti with MIT License 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 #6
Source File: SysUserServiceImpl.java    From teaching with Apache License 2.0 6 votes vote down vote up
@Override
@CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
public Result<?> resetPassword(String username, String oldpassword, String newpassword, String confirmpassword) {
    SysUser user = userMapper.getUserByName(username);
    String passwordEncode = PasswordUtil.encrypt(username, oldpassword, user.getSalt());
    if (!user.getPassword().equals(passwordEncode)) {
        return Result.error("旧密码输入错误!");
    }
    if (oConvertUtils.isEmpty(newpassword)) {
        return Result.error("新密码不允许为空!");
    }
    if (!newpassword.equals(confirmpassword)) {
        return Result.error("两次输入密码不一致!");
    }
    String password = PasswordUtil.encrypt(username, newpassword, user.getSalt());
    this.userMapper.update(new SysUser().setPassword(password), new LambdaQueryWrapper<SysUser>().eq(SysUser::getId, user.getId()));
    return Result.ok("密码重置成功!");
}
 
Example #7
Source File: SysUserServiceImpl.java    From jeecg-boot-with-activiti with MIT License 6 votes vote down vote up
@Override
@CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
public Result<?> resetPassword(String username, String oldpassword, String newpassword, String confirmpassword) {
    SysUser user = userMapper.getUserByName(username);
    String passwordEncode = PasswordUtil.encrypt(username, oldpassword, user.getSalt());
    if (!user.getPassword().equals(passwordEncode)) {
        return Result.error("旧密码输入错误!");
    }
    if (oConvertUtils.isEmpty(newpassword)) {
        return Result.error("新密码不允许为空!");
    }
    if (!newpassword.equals(confirmpassword)) {
        return Result.error("两次输入密码不一致!");
    }
    String password = PasswordUtil.encrypt(username, newpassword, user.getSalt());
    this.userMapper.update(new SysUser().setPassword(password), new LambdaQueryWrapper<SysUser>().eq(SysUser::getId, user.getId()));
    return Result.ok("密码重置成功!");
}
 
Example #8
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 #9
Source File: SysUserServiceImpl.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
@Override
@CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
public Result<?> changePassword(SysUser sysUser) {
    String salt = oConvertUtils.randomGen(8);
    sysUser.setSalt(salt);
    String password = sysUser.getPassword();
    String passwordEncode = PasswordUtil.encrypt(sysUser.getUsername(), password, salt);
    sysUser.setPassword(passwordEncode);
    this.userMapper.updateById(sysUser);
    return Result.ok("密码修改成功!");
}
 
Example #10
Source File: TestWebController.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
@PostMapping("/login")
public ResponseBean login(@RequestParam("username") String username,
                          @RequestParam("password") String password) {
	SysUser user = userService.getUserByName(username);
	if(user==null) {
		return new ResponseBean(200, "用户不存在!", JwtUtil.sign(username, user.getPassword()));
	}
	String passwordEncode = PasswordUtil.encrypt(username, password, user.getSalt());
    if (passwordEncode.equals(user.getPassword())) {
        return new ResponseBean(200, "Login success", JwtUtil.sign(username, user.getPassword()));
    } else {
        throw new UnauthorizedException();
    }
}
 
Example #11
Source File: TestWebController.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
@PostMapping("/login")
public ResponseBean login(@RequestParam("username") String username,
                          @RequestParam("password") String password) {
	SysUser user = userService.getUserByName(username);
	if(user==null) {
		return new ResponseBean(200, "用户不存在!", JwtUtil.sign(username, user.getPassword()));
	}
	String passwordEncode = PasswordUtil.encrypt(username, password, user.getSalt());
    if (passwordEncode.equals(user.getPassword())) {
        return new ResponseBean(200, "Login success", JwtUtil.sign(username, user.getPassword()));
    } else {
        throw new UnauthorizedException();
    }
}
 
Example #12
Source File: SysUserServiceImpl.java    From teaching with Apache License 2.0 5 votes vote down vote up
@Override
@CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
public Result<?> changePassword(SysUser sysUser) {
    String salt = oConvertUtils.randomGen(8);
    sysUser.setSalt(salt);
    String password = sysUser.getPassword();
    String passwordEncode = PasswordUtil.encrypt(sysUser.getUsername(), password, salt);
    sysUser.setPassword(passwordEncode);
    this.userMapper.updateById(sysUser);
    return Result.ok("密码修改成功!");
}
 
Example #13
Source File: TestWebController.java    From teaching with Apache License 2.0 5 votes vote down vote up
@PostMapping("/login")
public ResponseBean login(@RequestParam("username") String username,
                          @RequestParam("password") String password) {
	SysUser user = userService.getUserByName(username);
	if(user==null) {
		return new ResponseBean(200, "用户不存在!", JwtUtil.sign(username, user.getPassword()));
	}
	String passwordEncode = PasswordUtil.encrypt(username, password, user.getSalt());
    if (passwordEncode.equals(user.getPassword())) {
        return new ResponseBean(200, "Login success", JwtUtil.sign(username, user.getPassword()));
    } else {
        throw new UnauthorizedException();
    }
}
 
Example #14
Source File: SysUserServiceImpl.java    From jeecg-boot-with-activiti with MIT License 5 votes vote down vote up
@Override
@CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
public Result<?> changePassword(SysUser sysUser) {
    String salt = oConvertUtils.randomGen(8);
    sysUser.setSalt(salt);
    String password = sysUser.getPassword();
    String passwordEncode = PasswordUtil.encrypt(sysUser.getUsername(), password, salt);
    sysUser.setPassword(passwordEncode);
    this.userMapper.updateById(sysUser);
    return Result.ok("密码修改成功!");
}
 
Example #15
Source File: SysUserController.java    From jeecg-boot-with-activiti with MIT License 5 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>();
       SysUser sysUser=new SysUser();
       Object object= redisUtil.get(phone);
       if(null==object) {
       	result.setMessage("更改密码失败");
           result.setSuccess(false);
       }
       if(!smscode.equals(object)) {
       	result.setMessage("更改密码失败");
           result.setSuccess(false);
       }
       sysUser = this.sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername,username));
       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;
       }
   }
 
Example #16
Source File: TestWebController.java    From jeecg-boot-with-activiti with MIT License 5 votes vote down vote up
@PostMapping("/login")
public ResponseBean login(@RequestParam("username") String username,
                          @RequestParam("password") String password) {
	SysUser user = userService.getUserByName(username);
	if(user==null) {
		return new ResponseBean(200, "用户不存在!", JwtUtil.sign(username, user.getPassword()));
	}
	String passwordEncode = PasswordUtil.encrypt(username, password, user.getSalt());
    if (passwordEncode.equals(user.getPassword())) {
        return new ResponseBean(200, "Login success", JwtUtil.sign(username, user.getPassword()));
    } else {
        throw new UnauthorizedException();
    }
}
 
Example #17
Source File: SysUserServiceImpl.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
@Override
@CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
public Result<?> changePassword(SysUser sysUser) {
    String salt = oConvertUtils.randomGen(8);
    sysUser.setSalt(salt);
    String password = sysUser.getPassword();
    String passwordEncode = PasswordUtil.encrypt(sysUser.getUsername(), password, salt);
    sysUser.setPassword(passwordEncode);
    this.userMapper.updateById(sysUser);
    return Result.ok("密码修改成功!");
}
 
Example #18
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 #19
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;
       }
   }
 
Example #20
Source File: SysUserController.java    From jeecg-boot-with-activiti with MIT License 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");
	String password = jsonObject.getString("password");
	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;
	}
	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 #21
Source File: SysUserController.java    From jeecg-boot 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(CommonConstant.USER_UNFREEZE);
		user.setDelFlag(CommonConstant.DEL_FLAG_0);
		user.setActivitiSync(CommonConstant.ACT_SYNC_0);
		sysUserService.addUserWithRole(user,"ee8626f80f7c2619917b6236f3a7f02b");//默认临时角色 test
		result.success("注册成功");
	} catch (Exception e) {
		result.error500("注册失败");
	}
	return result;
}
 
Example #22
Source File: SysUserController.java    From jeecg-boot 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;
       }
   }
 
Example #23
Source File: SysUserController.java    From jeecg-cloud 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;
       }
   }
 
Example #24
Source File: SysUserController.java    From jeecg-cloud 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(CommonConstant.USER_UNFREEZE);
		user.setDelFlag(CommonConstant.DEL_FLAG_0);
		user.setActivitiSync(CommonConstant.ACT_SYNC_0);
		sysUserService.addUserWithRole(user,"ee8626f80f7c2619917b6236f3a7f02b");//默认临时角色 test
		result.success("注册成功");
	} catch (Exception e) {
		result.error500("注册失败");
	}
	return result;
}