-
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 pull request #7 from kusitms-28th-Meetup-E/feat/auth
Feat/auth
- Loading branch information
Showing
25 changed files
with
318 additions
and
236 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 was deleted.
Oops, something went wrong.
Binary file not shown.
13 changes: 13 additions & 0 deletions
13
src/main/java/gwangjang/server/domain/auth/application/dto/request/CheckEmailRequest.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,13 @@ | ||
package gwangjang.server.domain.auth.application.dto.request; | ||
|
||
import lombok.*; | ||
|
||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@Getter | ||
@Setter | ||
public class CheckEmailRequest { | ||
String email; | ||
String code; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/gwangjang/server/domain/auth/application/dto/request/LocalSignInRequest.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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
package gwangjang.server.domain.auth.application.dto.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class LocalSignInRequest { | ||
private String id; | ||
private String pw; | ||
|
||
} |
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
6 changes: 2 additions & 4 deletions
6
src/main/java/gwangjang/server/domain/auth/application/dto/request/SignInRequest.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
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
6 changes: 2 additions & 4 deletions
6
src/main/java/gwangjang/server/domain/auth/application/dto/request/TestRequest.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
14 changes: 14 additions & 0 deletions
14
src/main/java/gwangjang/server/domain/auth/application/dto/response/CheckEmailResponse.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,14 @@ | ||
package gwangjang.server.domain.auth.application.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
public class CheckEmailResponse { | ||
private Boolean isChecked; | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/gwangjang/server/domain/auth/application/service/CheckEmailUserCase.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,77 @@ | ||
package gwangjang.server.domain.auth.application.service; | ||
|
||
import gwangjang.server.domain.auth.application.dto.request.CheckEmailRequest; | ||
import gwangjang.server.domain.auth.application.dto.response.CheckEmailResponse; | ||
import gwangjang.server.domain.auth.application.dto.response.CheckNicknameResponse; | ||
import gwangjang.server.domain.auth.exception.EmailAuthException; | ||
import gwangjang.server.domain.member.domain.service.MemberCheckService; | ||
import gwangjang.server.global.security.jwt.redis.RedisUtil; | ||
import gwangjang.server.global.utils.EmailUtil; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.mail.SimpleMailMessage; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.security.NoSuchAlgorithmException; | ||
import java.security.SecureRandom; | ||
import java.util.Random; | ||
|
||
@Slf4j | ||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class CheckEmailUserCase { | ||
|
||
private final MemberCheckService memberCheckService; | ||
|
||
private final EmailUtil emailUtil; | ||
private final RedisUtil redisUtil; | ||
|
||
private static final String AUTH_CODE_PREFIX = "AuthCode "; | ||
|
||
|
||
public CheckEmailResponse requestEmail(String email){ | ||
boolean isDuplicated=memberCheckService.checkEmail(email); | ||
|
||
if (!isDuplicated) { | ||
log.info("createCode Before"); | ||
String code = createCode(); | ||
log.info("sendEmail Before"); | ||
emailUtil.sendEmail(email,"광장 이메일 인증","인증번호 : "+code); | ||
redisUtil.save(code,email); | ||
log.info("code"+code); | ||
} | ||
return new CheckEmailResponse(isDuplicated); | ||
} | ||
|
||
|
||
public CheckEmailResponse checkEmailAuth(CheckEmailRequest checkEmailRequest) { | ||
|
||
return verifiedCode(checkEmailRequest.getEmail(), checkEmailRequest.getCode()); | ||
} | ||
|
||
private String createCode() { | ||
int lenth = 6; | ||
try { | ||
Random random = SecureRandom.getInstanceStrong(); | ||
StringBuilder builder = new StringBuilder(); | ||
for (int i = 0; i < lenth; i++) { | ||
builder.append(random.nextInt(10)); | ||
} | ||
return builder.toString(); | ||
} catch (NoSuchAlgorithmException e) { | ||
log.debug("MemberService.createCode() exception occur"); | ||
throw new EmailAuthException(); | ||
} | ||
} | ||
|
||
public CheckEmailResponse verifiedCode(String email, String authCode) { | ||
String redisAuthCode = redisUtil.getEmailValues (email).get().toString(); | ||
log.info(String.valueOf(redisUtil.checkExistsValue(redisAuthCode))+"checkExistsValue"); | ||
log.info(String.valueOf(redisAuthCode.equals(authCode))+"redisauthCodeEquals"); | ||
boolean authResult = redisUtil.checkExistsValue(redisAuthCode) && redisAuthCode.equals(authCode); | ||
return new CheckEmailResponse(authResult); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/java/gwangjang/server/domain/auth/exception/EmailAuthException.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,12 @@ | ||
package gwangjang.server.domain.auth.exception; | ||
|
||
import gwangjang.server.global.response.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class EmailAuthException extends AuthException { | ||
public EmailAuthException() { | ||
super(ErrorCode.EMAIL_AUTH_ERROR, | ||
HttpStatus.UNAUTHORIZED); | ||
} | ||
} | ||
|
Oops, something went wrong.