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 {
}
UserInfoDto userInfoDto = new UserInfoDto();
userInfoDto.setUserId(authentication.getName());
userInfoDto.setLoginId(authentication.getName());
userInfoDto.setMemberRole(authentication.getAuthorities().stream().toList().get(0).toString().replaceAll("ROLE_", ""));
return userInfoDto;
......
......@@ -25,6 +25,10 @@ public class AuthController {
return authService.login(userLoginDto);
}
@PostMapping("/logout")
public TokenInfo logout(){
return null;
}
@PostMapping("/register")
public void register(@RequestBody UserJoinDto userJoinDto) {
authService.join(userJoinDto);
......
......@@ -8,7 +8,7 @@ import lombok.*;
@ToString
@Builder
public class UserInfoDto {
private String userId;
private String loginId;
private String memberRole;
}
\ No newline at end of file
......@@ -4,7 +4,7 @@ import lombok.Data;
@Data
public class UserJoinDto {
private String userId;
private String loginId;
private String password;
private String userName;
}
\ No newline at end of file
......@@ -4,6 +4,6 @@ import lombok.Data;
@Data
public class UserLoginDto {
String userId;
String loginId;
String password;
}
......@@ -26,7 +26,7 @@ public class User implements UserDetails {
private Long id;
@Column(nullable = false)
private String userId;
private String loginId;
@Column(nullable = false)
private String password;
......
......@@ -6,5 +6,5 @@ import umc.spring.post.data.entity.User;
import java.util.Optional;
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 {
@Override
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());
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.setEmail(user.getUserId());
tokenInfo.setEmail(user.getLoginId());
tokenInfo.setMemberRole(user.getRole().toString());
return tokenInfo;
......@@ -61,7 +61,7 @@ public class AuthServiceImpl implements AuthService, UserDetailsService {
@Override
public void join(UserJoinDto userJoinDto) {
User user = new User();
user.setUserId(userJoinDto.getUserId());
user.setLoginId(userJoinDto.getLoginId());
user.setPassword(passwordEncoder.encode(userJoinDto.getPassword()));
user.setUserName(userJoinDto.getUserName());
userRepository.save(user);
......@@ -75,7 +75,7 @@ public class AuthServiceImpl implements AuthService, UserDetailsService {
@Override
public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
return userRepository.findByUserId(userId)
return userRepository.findByLoginId(userId)
.map(this::createUserDetails)
.orElseThrow(() -> new UsernameNotFoundException("해당하는 유저를 찾을 수 없습니다."));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment