| | |
| | | import com.ycl.config.PlatformConfig; |
| | | import com.ycl.system.AjaxResult; |
| | | import com.ycl.system.entity.SysUser; |
| | | import com.ycl.system.mapper.SysUserMapper; |
| | | import com.ycl.system.model.LoginUser; |
| | | import com.ycl.system.service.ISysUserService; |
| | | import com.ycl.system.service.TokenService; |
| | |
| | | import com.ycl.utils.file.MimeTypeUtils; |
| | | import enumeration.BusinessType; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import utils.StringUtils; |
| | |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | @Autowired |
| | | private SysUserMapper userMapper; |
| | | |
| | | /** |
| | | * 个人信息 |
| | | */ |
| | | @GetMapping |
| | | public AjaxResult profile() |
| | | { |
| | | public AjaxResult profile() { |
| | | LoginUser loginUser = getLoginUser(); |
| | | SysUser user = loginUser.getUser(); |
| | | AjaxResult ajax = AjaxResult.success(user); |
| | |
| | | */ |
| | | @Log(title = "个人信息", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult updateProfile(@RequestBody SysUser user) |
| | | { |
| | | public AjaxResult updateProfile(@RequestBody SysUser user) { |
| | | LoginUser loginUser = getLoginUser(); |
| | | SysUser currentUser = loginUser.getUser(); |
| | | currentUser.setNickName(user.getNickName()); |
| | | currentUser.setEmail(user.getEmail()); |
| | | currentUser.setPhonenumber(user.getPhonenumber()); |
| | | currentUser.setSex(user.getSex()); |
| | | if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(currentUser)) |
| | | { |
| | | if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(currentUser)) { |
| | | return error("修改用户'" + loginUser.getUsername() + "'失败,手机号码已存在"); |
| | | } |
| | | if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(currentUser)) |
| | | { |
| | | if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(currentUser)) { |
| | | return error("修改用户'" + loginUser.getUsername() + "'失败,邮箱账号已存在"); |
| | | } |
| | | if (userService.updateUserProfile(currentUser) > 0) |
| | | { |
| | | if (userService.updateUserProfile(currentUser) > 0) { |
| | | // 更新缓存用户信息 |
| | | tokenService.setLoginUser(loginUser); |
| | | return success(); |
| | |
| | | */ |
| | | @Log(title = "个人信息", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/updatePwd") |
| | | public AjaxResult updatePwd(String oldPassword, String newPassword) |
| | | { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult updatePwd(String oldPassword, String newPassword, Short firstLogin) { |
| | | LoginUser loginUser = getLoginUser(); |
| | | String userName = loginUser.getUsername(); |
| | | String password = loginUser.getPassword(); |
| | | if (!SecurityUtils.matchesPassword(oldPassword, password)) |
| | | { |
| | | if (firstLogin != 0 && !SecurityUtils.matchesPassword(oldPassword, password)) { |
| | | return error("修改密码失败,旧密码错误"); |
| | | } |
| | | if (SecurityUtils.matchesPassword(newPassword, password)) |
| | | { |
| | | if (SecurityUtils.matchesPassword(newPassword, password)) { |
| | | return error("新密码不能与旧密码相同"); |
| | | } |
| | | newPassword = SecurityUtils.encryptPassword(newPassword); |
| | | if (userService.resetUserPwd(userName, newPassword) > 0) |
| | | { |
| | | if (userService.resetUserPwd(userName, newPassword) > 0) { |
| | | // 更新缓存用户密码 |
| | | loginUser.getUser().setPassword(newPassword); |
| | | tokenService.setLoginUser(loginUser); |
| | | return success(); |
| | | } |
| | | //将状态改为已修改过密码 |
| | | if (firstLogin == 0) { |
| | | SysUser user = new SysUser(); |
| | | user.setUserId(loginUser.getUserId()); |
| | | user.setFirstLogin((short) 1); |
| | | userMapper.updateUser(user); |
| | | } |
| | | return error("修改密码异常,请联系管理员"); |
| | | } |
| | |
| | | */ |
| | | @Log(title = "用户头像", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/avatar") |
| | | public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws Exception |
| | | { |
| | | if (!file.isEmpty()) |
| | | { |
| | | public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws Exception { |
| | | if (!file.isEmpty()) { |
| | | LoginUser loginUser = getLoginUser(); |
| | | String avatar = FileUploadUtils.upload(PlatformConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION); |
| | | if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) |
| | | { |
| | | if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("imgUrl", avatar); |
| | | // 更新缓存用户头像 |