-
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.
Merge branch 'main' into Feature/#152-해커톤_페이지_구현
- Loading branch information
Showing
88 changed files
with
3,503 additions
and
459 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/.idea/ | ||
.iml | ||
.iml | ||
|
||
**/node_modules |
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,4 @@ | ||
[submodule "config"] | ||
path = backend/src/main/resources/config | ||
url = https://github.com/SW-CSS/config.git | ||
branch = main |
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); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
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,66 @@ | ||
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.auth.exception.AuthException; | ||
import sw_css.auth.exception.AuthExceptionType; | ||
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; | ||
private final AuthCheckDuplicateService authCheckDuplicateService; | ||
|
||
public SendAuthCodeResponse emailAuth(String email) { | ||
checkIsDuplicateEmail(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); | ||
} | ||
|
||
private void checkIsDuplicateEmail(String email) { | ||
if (authCheckDuplicateService.isDuplicateEmail(email)) { | ||
throw new AuthException(AuthExceptionType.MEMBER_EMAIL_DUPLICATE); | ||
} | ||
} | ||
} |
Oops, something went wrong.