Skip to content
Snippets Groups Projects
Commit d80f1f39 authored by Gwan Ju's avatar Gwan Ju
Browse files

refactor: Update field names in User entity and related DTOs

parent bbd906e3
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ public class SecurityUtil { ...@@ -14,7 +14,7 @@ public class SecurityUtil {
} }
UserInfoDto userInfoDto = new UserInfoDto(); UserInfoDto userInfoDto = new UserInfoDto();
userInfoDto.setUserId(authentication.getName()); userInfoDto.setLoginId(authentication.getName());
userInfoDto.setMemberRole(authentication.getAuthorities().stream().toList().get(0).toString().replaceAll("ROLE_", "")); userInfoDto.setMemberRole(authentication.getAuthorities().stream().toList().get(0).toString().replaceAll("ROLE_", ""));
return userInfoDto; return userInfoDto;
......
...@@ -25,6 +25,10 @@ public class AuthController { ...@@ -25,6 +25,10 @@ public class AuthController {
return authService.login(userLoginDto); return authService.login(userLoginDto);
} }
@PostMapping("/logout")
public TokenInfo logout(){
return null;
}
@PostMapping("/register") @PostMapping("/register")
public void register(@RequestBody UserJoinDto userJoinDto) { public void register(@RequestBody UserJoinDto userJoinDto) {
authService.join(userJoinDto); authService.join(userJoinDto);
......
...@@ -8,7 +8,7 @@ import lombok.*; ...@@ -8,7 +8,7 @@ import lombok.*;
@ToString @ToString
@Builder @Builder
public class UserInfoDto { public class UserInfoDto {
private String userId; private String loginId;
private String memberRole; private String memberRole;
} }
\ No newline at end of file
...@@ -4,7 +4,7 @@ import lombok.Data; ...@@ -4,7 +4,7 @@ import lombok.Data;
@Data @Data
public class UserJoinDto { public class UserJoinDto {
private String userId; private String loginId;
private String password; private String password;
private String userName; private String userName;
} }
\ No newline at end of file
...@@ -4,6 +4,6 @@ import lombok.Data; ...@@ -4,6 +4,6 @@ import lombok.Data;
@Data @Data
public class UserLoginDto { public class UserLoginDto {
String userId; String loginId;
String password; String password;
} }
...@@ -26,7 +26,7 @@ public class User implements UserDetails { ...@@ -26,7 +26,7 @@ public class User implements UserDetails {
private Long id; private Long id;
@Column(nullable = false) @Column(nullable = false)
private String userId; private String loginId;
@Column(nullable = false) @Column(nullable = false)
private String password; private String password;
......
...@@ -6,5 +6,5 @@ import umc.spring.post.data.entity.User; ...@@ -6,5 +6,5 @@ import umc.spring.post.data.entity.User;
import java.util.Optional; import java.util.Optional;
public interface UserRepository extends JpaRepository<User, Long> { public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByUserId(String userId); Optional<User> findByLoginId(String loginId);
} }
...@@ -44,15 +44,15 @@ public class AuthServiceImpl implements AuthService, UserDetailsService { ...@@ -44,15 +44,15 @@ public class AuthServiceImpl implements AuthService, UserDetailsService {
@Override @Override
public TokenInfo login(UserLoginDto userLoginDto) { public TokenInfo login(UserLoginDto userLoginDto) {
User user = userRepository.findByUserId(userLoginDto.getUserId()).orElseThrow(() -> new UsernameNotFoundException("아이디 혹은 비밀번호를 확인하세요.")); User user = userRepository.findByLoginId(userLoginDto.getLoginId()).orElseThrow(() -> new UsernameNotFoundException("아이디 혹은 비밀번호를 확인하세요."));
boolean matches = passwordEncoder.matches(userLoginDto.getPassword(), user.getPassword()); boolean matches = passwordEncoder.matches(userLoginDto.getPassword(), user.getPassword());
if (!matches) throw new BadCredentialsException("아이디 혹은 비밀번호를 확인하세요."); if (!matches) throw new BadCredentialsException("아이디 혹은 비밀번호를 확인하세요.");
Authentication authentication = new UsernamePasswordAuthenticationToken(user.getUserId(), user.getPassword(), user.getAuthorities()); Authentication authentication = new UsernamePasswordAuthenticationToken(user.getLoginId(), user.getPassword(), user.getAuthorities());
TokenInfo tokenInfo = jwtTokenProvider.generateToken(authentication); TokenInfo tokenInfo = jwtTokenProvider.generateToken(authentication);
tokenInfo.setEmail(user.getUserId()); tokenInfo.setEmail(user.getLoginId());
tokenInfo.setMemberRole(user.getRole().toString()); tokenInfo.setMemberRole(user.getRole().toString());
return tokenInfo; return tokenInfo;
...@@ -61,7 +61,7 @@ public class AuthServiceImpl implements AuthService, UserDetailsService { ...@@ -61,7 +61,7 @@ public class AuthServiceImpl implements AuthService, UserDetailsService {
@Override @Override
public void join(UserJoinDto userJoinDto) { public void join(UserJoinDto userJoinDto) {
User user = new User(); User user = new User();
user.setUserId(userJoinDto.getUserId()); user.setLoginId(userJoinDto.getLoginId());
user.setPassword(passwordEncoder.encode(userJoinDto.getPassword())); user.setPassword(passwordEncoder.encode(userJoinDto.getPassword()));
user.setUserName(userJoinDto.getUserName()); user.setUserName(userJoinDto.getUserName());
userRepository.save(user); userRepository.save(user);
...@@ -75,7 +75,7 @@ public class AuthServiceImpl implements AuthService, UserDetailsService { ...@@ -75,7 +75,7 @@ public class AuthServiceImpl implements AuthService, UserDetailsService {
@Override @Override
public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException { public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
return userRepository.findByUserId(userId) return userRepository.findByLoginId(userId)
.map(this::createUserDetails) .map(this::createUserDetails)
.orElseThrow(() -> new UsernameNotFoundException("해당하는 유저를 찾을 수 없습니다.")); .orElseThrow(() -> new UsernameNotFoundException("해당하는 유저를 찾을 수 없습니다."));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment