Search in sources :

Example 1 with UserDto

use of co.yixiang.modules.system.service.dto.UserDto in project yshopmall by guchengwuyue.

the class SysUserServiceImpl method download.

@Override
public void download(List<UserDto> all, HttpServletResponse response) throws IOException {
    List<Map<String, Object>> list = new ArrayList<>();
    for (UserDto user : all) {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("邮箱", user.getEmail());
        map.put("状态:1启用、0禁用", user.getEnabled());
        map.put("密码", user.getPassword());
        map.put("用户名", user.getUsername());
        map.put("部门名称", user.getDeptId());
        map.put("手机号码", user.getPhone());
        map.put("创建日期", user.getCreateTime());
        map.put("最后修改密码的日期", user.getLastPasswordResetTime());
        map.put("昵称", user.getNickName());
        map.put("性别", user.getSex());
        list.add(map);
    }
    FileUtil.downloadExcel(list, response);
}
Also used : UserDto(co.yixiang.modules.system.service.dto.UserDto)

Example 2 with UserDto

use of co.yixiang.modules.system.service.dto.UserDto in project yshopmall by guchengwuyue.

the class SysUserController method updateEmail.

@ForbidSubmit
@Log("修改邮箱")
@ApiOperation("修改邮箱")
@PostMapping(value = "/updateEmail/{code}")
public ResponseEntity<Object> updateEmail(@PathVariable String code, @RequestBody User user) {
    // 密码解密
    RSA rsa = new RSA(privateKey, null);
    String password = new String(rsa.decrypt(user.getPassword(), KeyType.PrivateKey));
    UserDto userDto = userService.findByName(SecurityUtils.getUsername());
    if (!passwordEncoder.matches(password, userDto.getPassword())) {
        throw new BadRequestException("密码错误");
    }
    VerificationCode verificationCode = new VerificationCode(code, YshopConstant.RESET_MAIL, "email", user.getEmail());
    verificationCodeService.validated(verificationCode);
    userService.updateEmail(userDto.getUsername(), user.getEmail());
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : RSA(cn.hutool.crypto.asymmetric.RSA) ResponseEntity(org.springframework.http.ResponseEntity) VerificationCode(co.yixiang.modules.tools.domain.VerificationCode) UserDto(co.yixiang.modules.system.service.dto.UserDto) BadRequestException(co.yixiang.exception.BadRequestException) ForbidSubmit(co.yixiang.modules.aop.ForbidSubmit) Log(co.yixiang.modules.logging.aop.log.Log) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with UserDto

use of co.yixiang.modules.system.service.dto.UserDto in project yshopmall by guchengwuyue.

the class SysUserController method updatePass.

@ForbidSubmit
@ApiOperation("修改密码")
@PostMapping(value = "/updatePass")
public ResponseEntity<Object> updatePass(@RequestBody UserPassVo passVo) {
    // 密码解密
    RSA rsa = new RSA(privateKey, null);
    String oldPass = new String(rsa.decrypt(passVo.getOldPass(), KeyType.PrivateKey));
    String newPass = new String(rsa.decrypt(passVo.getNewPass(), KeyType.PrivateKey));
    UserDto user = userService.findByName(SecurityUtils.getUsername());
    if (!passwordEncoder.matches(oldPass, user.getPassword())) {
        throw new BadRequestException("修改失败,旧密码错误");
    }
    if (passwordEncoder.matches(newPass, user.getPassword())) {
        throw new BadRequestException("新密码不能与旧密码相同");
    }
    userService.updatePass(user.getUsername(), passwordEncoder.encode(newPass));
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : RSA(cn.hutool.crypto.asymmetric.RSA) ResponseEntity(org.springframework.http.ResponseEntity) UserDto(co.yixiang.modules.system.service.dto.UserDto) BadRequestException(co.yixiang.exception.BadRequestException) ForbidSubmit(co.yixiang.modules.aop.ForbidSubmit) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with UserDto

use of co.yixiang.modules.system.service.dto.UserDto in project yshopmall by guchengwuyue.

the class MenuController method buildMenus.

@ApiOperation("获取前端所需菜单")
@GetMapping(value = "/build")
public ResponseEntity<Object> buildMenus() {
    UserDto user = userService.findByName(SecurityUtils.getUsername());
    List<MenuDto> menuDtoList = menuService.findByRoles(roleService.findByUsersId(user.getId()));
    List<MenuDto> menuDtos = (List<MenuDto>) menuService.buildTree(menuDtoList).get("content");
    return new ResponseEntity<>(menuService.buildMenus(menuDtos), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) UserDto(co.yixiang.modules.system.service.dto.UserDto) List(java.util.List) MenuDto(co.yixiang.modules.system.service.dto.MenuDto) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with UserDto

use of co.yixiang.modules.system.service.dto.UserDto in project yshopmall by guchengwuyue.

the class SysUserController method center.

@ForbidSubmit
@Log("修改用户:个人中心")
@ApiOperation("修改用户:个人中心")
@PutMapping(value = "center")
public ResponseEntity<Object> center(@Validated(User.Update.class) @RequestBody User resources) {
    UserDto userDto = userService.findByName(SecurityUtils.getUsername());
    if (!resources.getId().equals(userDto.getId())) {
        throw new BadRequestException("不能修改他人资料");
    }
    userService.saveOrUpdate(resources);
    return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) UserDto(co.yixiang.modules.system.service.dto.UserDto) BadRequestException(co.yixiang.exception.BadRequestException) ForbidSubmit(co.yixiang.modules.aop.ForbidSubmit) Log(co.yixiang.modules.logging.aop.log.Log) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

UserDto (co.yixiang.modules.system.service.dto.UserDto)9 BadRequestException (co.yixiang.exception.BadRequestException)6 ApiOperation (io.swagger.annotations.ApiOperation)5 ResponseEntity (org.springframework.http.ResponseEntity)5 ForbidSubmit (co.yixiang.modules.aop.ForbidSubmit)4 Log (co.yixiang.modules.logging.aop.log.Log)3 RoleSmallDto (co.yixiang.modules.system.service.dto.RoleSmallDto)3 RSA (cn.hutool.crypto.asymmetric.RSA)2 Dept (co.yixiang.modules.system.domain.Dept)1 MenuDto (co.yixiang.modules.system.service.dto.MenuDto)1 VerificationCode (co.yixiang.modules.tools.domain.VerificationCode)1 HashSet (java.util.HashSet)1 List (java.util.List)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1