Skip to content

Commit

Permalink
新增重置用户密码功能
Browse files Browse the repository at this point in the history
  • Loading branch information
elunez committed Jul 6, 2023
1 parent c20bd42 commit e0777d8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,13 @@ public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificat
@Query(value = "SELECT count(1) FROM sys_user u, sys_users_roles r WHERE " +
"u.user_id = r.user_id AND r.role_id in ?1", nativeQuery = true)
int countByRoles(Set<Long> ids);

/**
* 重置密码
* @param ids 、
* @param pwd 、
*/
@Modifying
@Query(value = "update sys_user set password = ?2 where user_id in ?1",nativeQuery = true)
void resetPwd(Set<Long> ids, String pwd);
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ public ResponseEntity<Object> updateUserPass(@RequestBody UserPassVo passVo) thr
return new ResponseEntity<>(HttpStatus.OK);
}

@ApiOperation("重置密码")
@PutMapping(value = "/resetPwd")
public ResponseEntity<Object> resetPwd(@RequestBody Set<Long> ids) {
String pwd = passwordEncoder.encode("123456");
userService.resetPwd(ids, pwd);
return new ResponseEntity<>(HttpStatus.OK);
}

@ApiOperation("修改头像")
@PostMapping(value = "/updateAvatar")
public ResponseEntity<Object> updateUserAvatar(@RequestParam MultipartFile avatar){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,11 @@ public interface UserService {
* @param resources /
*/
void updateCenter(User resources);

/**
* 重置密码
* @param ids 用户id
* @param pwd 密码
*/
void resetPwd(Set<Long> ids, String pwd);
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ public void updatePass(String username, String pass) {
flushCache(username);
}

@Override
@Transactional(rollbackFor = Exception.class)
public void resetPwd(Set<Long> ids, String pwd) {
userRepository.resetPwd(ids, pwd);
}

@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> updateAvatar(MultipartFile multipartFile) {
Expand Down

0 comments on commit e0777d8

Please sign in to comment.