Skip to content

Commit

Permalink
Merge pull request #7 from kusitms-28th-Meetup-E/feat/auth
Browse files Browse the repository at this point in the history
Feat/auth
  • Loading branch information
seungueonn authored Nov 6, 2023
2 parents 7d64cd7 + 163cba6 commit e495a52
Show file tree
Hide file tree
Showing 25 changed files with 318 additions and 236 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ out/
.vscode/


application.yml
application.yml
build/resources/main/application.yml
build/tmp/compileJava/previous-compilation-data.bin
src/main/resources/application.yml

3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:3.1.4'

implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'jakarta.mail:jakarta.mail-api:2.1.2'
implementation 'org.springframework.boot:spring-boot-starter-mail'



}
Expand Down
81 changes: 0 additions & 81 deletions build/resources/main/application.yml

This file was deleted.

Binary file removed build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
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;
}
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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.*;

@Data
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class LocalSignUpRequest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package gwangjang.server.domain.auth.application.dto.request;

import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;


@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class SignInRequest {
@NotBlank(message="token 을 입력해주세요.")
private String token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;


@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class SignUpRequest {


Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package gwangjang.server.domain.auth.application.dto.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class TestRequest {
private String socialId;

Expand Down
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;
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ public SignInResponse localSignUp(LocalSignUpRequest localSignUpRequest) {
return SignInResponse.from(tokenResponse, member.getRegistrationStatus());
}


}
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);
}
}

Loading

0 comments on commit e495a52

Please sign in to comment.