-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: member table 컬럼에 is_authorized 항목 추가 #109 * feat: 추가적인 domain 정의 #109 * feat: 메일, 학번, 전화번호 중복 확인 service 생성 #109 * feat: 회원가입 request dto 구현 #109 * feat: springframework security 의존성 추가 #109 * feat: 회원가입 구현 #109 * feat: 회원가입 테스트 코드 작성 #109 * feat: backend config 폴더 submodule로 가져오기 #109 * feat: submodule 경로 수정을 위한 삭제 #109 * feat: config 서브모듈 추가 #109 * feat: 인증코드 발송 api 와 test 코드 구현 #109 * feat: 변경된 이메일 인증 로직에 의한 table schema 수정 #109 * feat: 중복하는 이메일, 학번, 전화번호인지 확인할 수 있는 api 구현 #109 * refact requestFields의 속성들 snake 문법으로 수정 #109 * feat: 로그인 api 구현 #109 * feat: 임시 비밀번호 발급 api 구현 #109 * feat: ArgumentResolver 방식으로 jwtToken 발급 #109 * feat: 로그인과 임시 비밀번호 발급 test 코드 작성 #109 * feat: 비밀번호 수정 api 구현 #109 * feat: 비밀번호 수정 test 코드 작성 #109 * feat: 테스트 코드 문서화 작업 #109 * feat: config 파일 업데이트 #109 * feat: submodule true 설정 #109 * feat: submodule 관련 설정 추가 #109 * feat: 코드리뷰 반영 #109
- Loading branch information
Showing
50 changed files
with
2,843 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
backend/src/main/java/sw_css/auth/api/SignInController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package sw_css.auth.api; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import sw_css.auth.application.AuthSignInService; | ||
import sw_css.auth.application.dto.request.ResetPasswordRequest; | ||
import sw_css.auth.application.dto.request.SignInRequest; | ||
import sw_css.auth.application.dto.response.SignInResponse; | ||
|
||
@Validated | ||
@RequestMapping("/sign-in") | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class SignInController { | ||
|
||
private final AuthSignInService authSignInService; | ||
|
||
@PostMapping | ||
public ResponseEntity<SignInResponse> signIn(@RequestBody @Valid SignInRequest request) { | ||
return ResponseEntity.ok(authSignInService.signIn(request.email(), request.password())); | ||
} | ||
|
||
@PatchMapping("/reset-password") | ||
public ResponseEntity<Void> resetPassword( | ||
@RequestBody @Valid ResetPasswordRequest request) { | ||
authSignInService.resetPassword(request.email(), request.name()); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
backend/src/main/java/sw_css/auth/api/SignUpController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package sw_css.auth.api; | ||
|
||
|
||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotBlank; | ||
import java.net.URI; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import sw_css.auth.application.AuthEmailService; | ||
import sw_css.auth.application.AuthSignUpService; | ||
import sw_css.auth.application.dto.request.SendAuthCodeRequest; | ||
import sw_css.auth.application.dto.request.SignUpRequest; | ||
import sw_css.auth.application.dto.response.CheckDuplicateResponse; | ||
import sw_css.auth.application.dto.response.SendAuthCodeResponse; | ||
|
||
@Validated | ||
@RequestMapping("/sign-up") | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class SignUpController { | ||
|
||
private final AuthSignUpService authSignUpService; | ||
private final AuthEmailService authEmailService; | ||
|
||
@PostMapping | ||
public ResponseEntity<Void> signUp(@RequestBody @Valid SignUpRequest request) { | ||
long memberId = authSignUpService.signUp(request); | ||
return ResponseEntity.created(URI.create("/members/" + memberId)).build(); | ||
} | ||
|
||
@PostMapping("/send-auth-code") | ||
public ResponseEntity<SendAuthCodeResponse> sendAuthCode(@RequestBody @Valid SendAuthCodeRequest request) { | ||
return ResponseEntity.ok(authEmailService.emailAuth(request.email())); | ||
} | ||
|
||
@GetMapping("/exists/email") | ||
public ResponseEntity<CheckDuplicateResponse> checkDuplicateEmail( | ||
@RequestParam(value = "email") @NotBlank final String email) { | ||
return ResponseEntity.ok(authSignUpService.isDuplicateEmail(email)); | ||
} | ||
|
||
@GetMapping("/exists/student-id") | ||
public ResponseEntity<CheckDuplicateResponse> checkDuplicateStudentId( | ||
@RequestParam(value = "student_id") @NotBlank final String studentId) { | ||
return ResponseEntity.ok(authSignUpService.isDuplicateStudentId(studentId)); | ||
} | ||
|
||
@GetMapping("/exists/phone-number") | ||
public ResponseEntity<CheckDuplicateResponse> checkDuplicatePhoneNumber( | ||
@RequestParam(value = "phone_number") @NotBlank final String phoneNumber) { | ||
return ResponseEntity.ok(authSignUpService.isDuplicatePhoneNumber(phoneNumber)); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/sw_css/auth/application/AuthCheckDuplicateService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package sw_css.auth.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import sw_css.member.domain.repository.MemberRepository; | ||
import sw_css.member.domain.repository.StudentMemberRepository; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class AuthCheckDuplicateService { | ||
private final MemberRepository memberRepository; | ||
private final StudentMemberRepository studentMemberRepository; | ||
|
||
public boolean isDuplicateEmail(String email) { | ||
return memberRepository.existsByEmail(email); | ||
} | ||
|
||
public boolean isDuplicateStudentID(String studentIdStr) { | ||
Long studentId = Long.parseLong(studentIdStr); | ||
return studentMemberRepository.existsById(studentId); | ||
} | ||
|
||
public boolean isDuplicatePhoneNumber(String phoneNumber) { | ||
return memberRepository.existsByPhoneNumber(phoneNumber); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
backend/src/main/java/sw_css/auth/application/AuthEmailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package sw_css.auth.application; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import sw_css.auth.application.dto.response.SendAuthCodeResponse; | ||
import sw_css.auth.domain.EmailAuthRedis; | ||
import sw_css.auth.domain.repository.EmailAuthRedisRepository; | ||
import sw_css.utils.MailUtil; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AuthEmailService { | ||
public static final int EMAIL_EXPIRED_SECONDS = 600; // 10분 | ||
public static final int AUTH_CODE_LENGTH = 10; | ||
|
||
private static final Random RANDOM = new Random(); | ||
|
||
private final MailUtil mailUtil; | ||
private final EmailAuthRedisRepository emailAuthRedisRepository; | ||
|
||
public SendAuthCodeResponse emailAuth(String email) { | ||
String authCode = generateRandomAuthCode(); | ||
emailAuthRedisRepository.save(EmailAuthRedis.of(email, authCode)); | ||
sendAuthCode(email, authCode); | ||
return SendAuthCodeResponse.from(EMAIL_EXPIRED_SECONDS); | ||
} | ||
|
||
public void sendNewPassword(String email, String password) { | ||
List<String> toUserList = new ArrayList<>(List.of(email)); | ||
String subject = "[부산대학교] SW역량강화플랫폼 임시 비밀번호 발송 메일입니다."; | ||
String text = "SW역량강화플랫폼 임시 비밀번호는 " + password + " 입니다."; | ||
mailUtil.sendMail(toUserList, subject, text); | ||
} | ||
|
||
private static String generateRandomAuthCode() { | ||
char leftLimit = '0'; | ||
char rightLimit = 'z'; | ||
|
||
return RANDOM.ints(leftLimit, rightLimit + 1) | ||
.filter(i -> Character.isAlphabetic(i) || Character.isDigit(i)) | ||
.limit(AuthEmailService.AUTH_CODE_LENGTH) | ||
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) | ||
.toString(); | ||
} | ||
|
||
private void sendAuthCode(String email, String authCode) { | ||
List<String> toUserList = new ArrayList<>(List.of(email)); | ||
String subject = "[부산대학교] SW역량강화플랫폼 인증코드 발송 메일입니다."; | ||
String text = "SW역량강화플랫폼 인증코드는 " + authCode + " 입니다."; | ||
mailUtil.sendMail(toUserList, subject, text); | ||
} | ||
} |
Oops, something went wrong.