-
Notifications
You must be signed in to change notification settings - Fork 3
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 #54 from AECOFARM/email
✨ [FEAT] SignUp시 Email인증 기능 추가
- Loading branch information
Showing
17 changed files
with
289 additions
and
49 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
8 changes: 8 additions & 0 deletions
8
src/main/java/dgu/aecofarm/domain/email/service/EmailService.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,8 @@ | ||
package dgu.aecofarm.domain.email.service; | ||
|
||
import dgu.aecofarm.entity.EmailMessage; | ||
|
||
public interface EmailService { | ||
void sendAuthCode(String email, String authCode); | ||
} | ||
|
32 changes: 32 additions & 0 deletions
32
src/main/java/dgu/aecofarm/domain/email/service/EmailServiceImpl.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,32 @@ | ||
package dgu.aecofarm.domain.email.service; | ||
|
||
import jakarta.mail.internet.MimeMessage; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.mail.javamail.MimeMessageHelper; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class EmailServiceImpl implements EmailService { | ||
|
||
private final JavaMailSender javaMailSender; | ||
|
||
@Override | ||
public void sendAuthCode(String email, String authCode) { | ||
try { | ||
MimeMessage mimeMessage = javaMailSender.createMimeMessage(); | ||
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, false, "UTF-8"); | ||
mimeMessageHelper.setTo(email); | ||
mimeMessageHelper.setSubject("[AECOfarm] Email Verification Code"); | ||
mimeMessageHelper.setText("Your verification code is: " + authCode, false); // HTML이 아니라면 false로 설정 | ||
javaMailSender.send(mimeMessage); | ||
log.info("Auth code sent to email: " + email); | ||
} catch (jakarta.mail.MessagingException e) { | ||
log.error("Failed to send auth code to email: " + email, e); | ||
throw new RuntimeException("Failed to send auth code", e); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/dgu/aecofarm/domain/email/service/UserService.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,41 @@ | ||
package dgu.aecofarm.domain.email.service; | ||
|
||
import dgu.aecofarm.entity.Member; | ||
import dgu.aecofarm.repository.MemberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Optional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserService { | ||
private final MemberRepository memberRepository; | ||
|
||
// 임시 비밀번호를 설정하는 메서드 | ||
public void setTempPassword(String email, String tempPassword) { | ||
Optional<Member> optionalMember = memberRepository.findMemberByEmail(email); | ||
if (!optionalMember.isPresent()) { | ||
throw new IllegalArgumentException("유효한 이메일이 아닙니다."); | ||
} | ||
Member member = optionalMember.get(); | ||
member.updatePassword(tempPassword); | ||
memberRepository.save(member); | ||
} | ||
|
||
// 사용자 정보 조회 메서드 | ||
public Optional<Member> getMemberByEmail(String email) { | ||
return memberRepository.findMemberByEmail(email); | ||
} | ||
|
||
// 사용자 비밀번호 재설정 메서드 | ||
public void resetPassword(String email, String newPassword) { | ||
Optional<Member> optionalMember = memberRepository.findMemberByEmail(email); | ||
if (!optionalMember.isPresent()) { | ||
throw new IllegalArgumentException("유효한 이메일이 아닙니다."); | ||
} | ||
Member member = optionalMember.get(); | ||
member.updatePassword(newPassword); | ||
memberRepository.save(member); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dgu.aecofarm.dto.email; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class EmailPostDto { | ||
private String email; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/dgu/aecofarm/dto/email/EmailResponseDto.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,10 @@ | ||
package dgu.aecofarm.dto.email; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class EmailResponseDto { | ||
private String code; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/dgu/aecofarm/dto/member/SignupCompleteDTO.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 dgu.aecofarm.dto.member; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class SignupCompleteDTO { | ||
private SignupRequestDTO signupRequestDTO; | ||
private String authCode; | ||
private String expectedCode; | ||
} |
Oops, something went wrong.