Skip to content

Commit

Permalink
Feat: 회원가입, 로그인 API 수정 #1
Browse files Browse the repository at this point in the history
Feat: 회원가입, 로그인 API 수정 #1
  • Loading branch information
tokyj515 authored Jul 31, 2023
2 parents 895e38e + 184a72a commit 51d81c0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.neoul.dto.UserRes;
import com.example.neoul.entity.user.User;
import com.example.neoul.global.entity.ApiResponse;
import com.example.neoul.global.exception.BadRequestException;
import com.example.neoul.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
Expand All @@ -22,7 +23,7 @@ public class UserController {
private final UserService userService;


@ApiOperation(value = "현재 로그인 유저(이거 지금 실행x)", notes = "현재 로그인 유저")
@ApiOperation(value = "현재 로그인 유저", notes = "현재 로그인 유저")
@GetMapping("/now")
public ApiResponse<User> now(){
return new ApiResponse<>(userService.findNowLoginUser());
Expand All @@ -33,8 +34,12 @@ public ApiResponse<User> now(){
@PostMapping("/signup")
public ApiResponse<UserRes.UserDetailDto> signup(@RequestBody UserReq.SignupUserDto signupUserDto) {
//이메일 형식 체크
if(userService.validationEmail(signupUserDto.getUsername()))
throw new BadRequestException("이메일 형식으로 입력해주세요");

//비밀번호 형식 체크
if(signupUserDto.getPassword().length() < 6)
throw new BadRequestException("비밀번호를 6자리 이상 입력해주세요");


return new ApiResponse<>(userService.signup(signupUserDto));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/example/neoul/dto/UserReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static class SignupUserDto {
private String username;
private String password;
private String name;
private String phone;
private String imageUrl;
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/example/neoul/global/jwt/TokenProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ public Authentication getAuthentication(String token) {
// .map(SimpleGrantedAuthority::new)
// .collect(Collectors.toList());

Long userIdx = claims.get("userId",Long.class);
Long userId = claims.get("userId",Long.class);

User user = userRepository.findUserByUserId(userIdx).get();

User user = userRepository.findUserByUserId(userId).get();
String userName = user.getUsername();

UserDetails userDetails = customUserDetailsService.loadUserByUsername(userName);
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/example/neoul/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


@RequiredArgsConstructor
Expand Down Expand Up @@ -92,8 +94,8 @@ public UserRes.UserDetailDto signup(UserReq.SignupUserDto signupUserDto) {
.username(signupUserDto.getUsername())
.password(passwordEncoder.encode(signupUserDto.getPassword()))
.name(signupUserDto.getName())
.phone(signupUserDto.getPhone())
.imageUrl(signupUserDto.getImageUrl())

.authorities(Collections.singletonList(authority))
.build();

Expand All @@ -102,6 +104,16 @@ public UserRes.UserDetailDto signup(UserReq.SignupUserDto signupUserDto) {
return UserRes.UserDetailDto.toDto(user);
}

//전화번호 양식 체크
public boolean validationEmail(String email){
Pattern pattern = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$");
Matcher matcher = pattern.matcher(email);
if (matcher.matches()) {
return true;
} else {
return false;
}
}


// public User signupADMIN(UserReq.SignupUserDto signupUserDto) {
Expand Down

0 comments on commit 51d81c0

Please sign in to comment.