Skip to content

Commit

Permalink
refactor: 회원가입 시 문자 인증 TTL은 클라이언트에서 하는 것으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
dgjinsu committed Nov 21, 2024
1 parent 8e3b08a commit d07c518
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public ResponseEntity<Response> validationPhone(@RequestBody ValidationPhoneRequ
return ResponseEntity.ok(new Response("사용 가능한 휴대폰 입니다."));
}

@Operation(summary = "회원 가입: 휴대폰 인증")
@Operation(summary = "회원 가입: 휴대폰 인증 (인증 코드 발송)")
@PostMapping("/api/join/sms-verification")
public ResponseEntity<Response> verificationSms(@RequestBody VerificationSmsRequest request) {
VerificationSmsResponse verificationSmsResponse = joinService.verificationSms(request);
public ResponseEntity<Response> sendVerificationCode(@RequestBody VerificationSmsRequest request) {
VerificationSmsResponse verificationSmsResponse = joinService.sendVerificationSms(request);
return ResponseEntity.ok(new Response(verificationSmsResponse, "6자리 인증 코드 반환"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public class JoinCompanyRequest {
@Schema(description = "휴대폰 번호", example = "01012345678")
@NotBlank
private String phone;
@Schema(description = "본인 확인 인증 번호", example = "123456")
@NotBlank
private String authCode;
@Schema(description = "회원 타입 [ROLE_WORKER or ROLE_COMPANY]", example = "ROLE_COMPANY")
@NotNull
private Role role; // 회원 타입
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public class JoinWorkerRequest {
@Schema(description = "휴대폰 번호", example = "01012345678")
@NotBlank
private String phone;
@Schema(description = "본인 확인 인증 번호", example = "123456")
@NotBlank
private String authCode;
@Schema(description = "이메일", example = "[email protected]")
@Email
private String email; // 이메일
Expand Down
22 changes: 1 addition & 21 deletions src/main/java/jikgong/domain/member/service/JoinService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import jikgong.domain.common.Address;
import jikgong.domain.location.entity.Location;
Expand All @@ -25,7 +24,6 @@
import jikgong.global.utils.RandomCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -41,16 +39,11 @@ public class JoinService {
private final WorkExperienceRepository workExperienceRepository;
private final PasswordEncoder encoder;
private final SmsService smsService;
private final RedisTemplate<String, String> redisTemplate;

private static final String REDIS_PREFIX_SIGNUP_VERIFICATION = "signup_verification:";

/**
* 노동자 회원가입 위치 정보 저장
*/
public Long joinWorkerMember(JoinWorkerRequest request) {
// 인증 코드 유효 시간 검사
validationAuthCode(request);
// loginId 중복 체크
validationLoginId(request.getLoginId());
// 휴대폰 중복 체크
Expand Down Expand Up @@ -105,15 +98,6 @@ public Long joinWorkerMember(JoinWorkerRequest request) {
return savedMember.getId();
}

// 인증 코드 유효 시간 검사
private void validationAuthCode(JoinWorkerRequest request) {
String redisKey = REDIS_PREFIX_SIGNUP_VERIFICATION + request.getPhone();
String savedAuthCode = redisTemplate.opsForValue().get(redisKey);
if (savedAuthCode == null || !savedAuthCode.equals(request.getAuthCode())) {
throw new JikgongException(ErrorCode.MEMBER_INVALID_AUTH_CODE); // 인증 코드 불일치
}
}

/**
* 기업 회원가입
*/
Expand Down Expand Up @@ -174,7 +158,7 @@ public void validationLoginId(String login) {
/**
* 휴대폰 인증
*/
public VerificationSmsResponse verificationSms(VerificationSmsRequest request) {
public VerificationSmsResponse sendVerificationSms(VerificationSmsRequest request) {
// 6자리 랜덤 코드 생성
String authCode = RandomCode.createAuthCode();
String content = "[직공]\n본인확인 인증번호: [" + authCode + "]";
Expand All @@ -184,10 +168,6 @@ public VerificationSmsResponse verificationSms(VerificationSmsRequest request) {
throw new JikgongException(ErrorCode.SMS_SEND_FAIL);
}

// Redis에 인증 코드와 회원 정보를 저장 (TTL 5분)
String redisKey = REDIS_PREFIX_SIGNUP_VERIFICATION + request.getPhone();
redisTemplate.opsForValue().set(redisKey, authCode, 5, TimeUnit.MINUTES);

return new VerificationSmsResponse(authCode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void verificationBeforeFindLoginId(LoginIdFindRequest request) {
* 문자로 인증된 코드로 아이디 찾기
*/
public LoginIdFindResponse findLoginId(AuthCodeForFindRequest request) {
// // 인증 코드가 일치하는지 체크
// 인증 코드가 일치하는지 체크
validationAuthCode(request);

Member member = memberRepository.findByPhone(request.getPhone())
Expand Down

0 comments on commit d07c518

Please sign in to comment.