Skip to content

Commit

Permalink
add logout after changing password
Browse files Browse the repository at this point in the history
  • Loading branch information
zrll12 committed Dec 20, 2023
1 parent 2e5638d commit 6676900
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/cc/vastsea/toyou/service/impl/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import static cc.vastsea.toyou.constant.UserConstant.*;
import static cc.vastsea.toyou.constant.UserConstant.USER_LOGIN_STATE;
import static cc.vastsea.toyou.constant.UserConstant.USER_TOKEN_HEADER;

@Service
@Slf4j
Expand Down Expand Up @@ -287,6 +290,13 @@ public void changePassword(User user, String oldPassword, String newPassword) {
throw new BusinessException(StatusCode.BAD_REQUEST, "密码格式错误");
}
user.setPassword(PasswordUtil.encodePassword(newPassword));
//log user out
Map<UUID, Long> tokenMap = userLoginToken.asMap();
for (Map.Entry<UUID, Long> entry : tokenMap.entrySet()) {
if (Objects.equals(entry.getValue(), user.getUid())) {
userLoginToken.invalidate(entry.getKey());
}
}
userMapper.updateById(user);
}

Expand Down

0 comments on commit 6676900

Please sign in to comment.