-
Notifications
You must be signed in to change notification settings - Fork 1
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 #68 from ClothingStoreService/feature/signup-email…
…-verify Feature/signup email verify
- Loading branch information
Showing
40 changed files
with
620 additions
and
161 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
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
12 changes: 12 additions & 0 deletions
12
.../java/org/store/clothstar/common/error/exception/SignupCertifyNumAuthFailedException.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 org.store.clothstar.common.error.exception; | ||
|
||
import org.store.clothstar.common.error.ErrorCode; | ||
|
||
public class SignupCertifyNumAuthFailedException extends RuntimeException { | ||
private final ErrorCode errorCode; | ||
|
||
public SignupCertifyNumAuthFailedException(ErrorCode errorCode) { | ||
super(errorCode.getMessage()); | ||
this.errorCode = errorCode; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,7 +5,5 @@ | |
public interface ExceptionType { | ||
HttpStatus status(); | ||
|
||
int exceptionCode(); | ||
|
||
String message(); | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/main/java/org/store/clothstar/common/mail/MailContentBuilder.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,19 @@ | ||
package org.store.clothstar.common.mail; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.thymeleaf.TemplateEngine; | ||
import org.thymeleaf.context.Context; | ||
|
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MailContentBuilder { | ||
private final TemplateEngine templateEngine; | ||
|
||
public String build(String certifyNum) { | ||
Context context = new Context(); | ||
context.setVariable("certifyNum", certifyNum); | ||
return templateEngine.process("mailTemplate", context); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/store/clothstar/common/mail/MailSendDTO.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 org.store.clothstar.common.mail; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class MailSendDTO { | ||
private String address; | ||
private String subject; | ||
private String text; | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/store/clothstar/common/mail/MailService.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,34 @@ | ||
package org.store.clothstar.common.mail; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.mail.javamail.MimeMessageHelper; | ||
import org.springframework.mail.javamail.MimeMessagePreparator; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class MailService { | ||
private final JavaMailSender mailSender; | ||
|
||
@Value("${email.send}") | ||
private String fromAddress; | ||
|
||
public boolean sendMail(MailSendDTO mailSendDTO) { | ||
MimeMessagePreparator messagePreparator = mimeMessage -> { | ||
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8"); | ||
messageHelper.setFrom(fromAddress); | ||
messageHelper.setTo(mailSendDTO.getAddress()); | ||
messageHelper.setSubject(mailSendDTO.getSubject()); | ||
messageHelper.setText(mailSendDTO.getText(), true); | ||
}; | ||
|
||
log.info("전송 메일주소 : {} -> {}", fromAddress, mailSendDTO.getAddress()); | ||
mailSender.send(messagePreparator); | ||
|
||
return true; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/store/clothstar/common/redis/RedisConfig.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,21 @@ | ||
package org.store.clothstar.common.redis; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
|
||
@Configuration | ||
public class RedisConfig { | ||
@Value("${spring.data.redis.host}") | ||
private String host; | ||
|
||
@Value("${spring.data.redis.port}") | ||
private int port; | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
return new LettuceConnectionFactory(host, port); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/org/store/clothstar/common/redis/RedisUtil.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,59 @@ | ||
package org.store.clothstar.common.redis; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.data.redis.core.StringRedisTemplate; | ||
import org.springframework.data.redis.core.ValueOperations; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.Duration; | ||
import java.util.Random; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class RedisUtil { | ||
private final StringRedisTemplate template; | ||
|
||
@Value("${spring.data.redis.duration}") | ||
private int duration; | ||
|
||
public String getData(String key) { | ||
ValueOperations<String, String> valueOperations = template.opsForValue(); | ||
return valueOperations.get(key); | ||
} | ||
|
||
public boolean existData(String key) { | ||
return Boolean.TRUE.equals(template.hasKey(key)); | ||
} | ||
|
||
public void setDataExpire(String key, String value) { | ||
ValueOperations<String, String> valueOperations = template.opsForValue(); | ||
Duration expireDuration = Duration.ofSeconds(duration); | ||
valueOperations.set(key, value, expireDuration); | ||
} | ||
|
||
public void deleteData(String key) { | ||
template.delete(key); | ||
} | ||
|
||
public void createRedisData(String toEmail, String code) { | ||
if (existData(toEmail)) { | ||
deleteData(toEmail); | ||
} | ||
|
||
setDataExpire(toEmail, code); | ||
} | ||
|
||
public String createdCertifyNum() { | ||
int leftLimit = 48; // number '0' | ||
int rightLimit = 122; // alphabet 'z' | ||
int targetStringLength = 6; | ||
Random random = new Random(); | ||
|
||
return random.ints(leftLimit, rightLimit + 1) | ||
.filter(i -> (i <= 57 || i >= 65) && (i <= 90 || i >= 97)) | ||
.limit(targetStringLength) | ||
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) | ||
.toString(); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/org/store/clothstar/member/dto/request/CertifyNumRequest.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 org.store.clothstar.member.dto.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@ToString | ||
public class CertifyNumRequest { | ||
@NotNull(message = "이메일을 입력해 주세요") | ||
private String email; | ||
} |
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
Oops, something went wrong.