-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/4-find-user-id #13
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,5 +1,5 @@ | ||
package com.sptp.backend.email.service; | ||
|
||
public interface EmailService { | ||
String sendMessage(String to)throws Exception; | ||
void sendMessage(String to)throws Exception; | ||
} |
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,6 +1,8 @@ | ||
package com.sptp.backend.email.service; | ||
|
||
import com.sptp.backend.email.service.EmailService; | ||
import com.sptp.backend.member.repository.Member; | ||
import com.sptp.backend.member.repository.MemberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.mail.MailException; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
|
@@ -16,12 +18,11 @@ | |
public class EmailServiceImpl implements EmailService { | ||
|
||
private final JavaMailSender emailSender; | ||
private final MemberRepository memberRepository; | ||
|
||
public static final String ePw = createKey(); | ||
|
||
private MimeMessage createMessage(String to)throws Exception{ | ||
private MimeMessage createMessage(String to, String UserId)throws Exception{ | ||
System.out.println("보λ΄λ λμ : "+ to); | ||
System.out.println("μΈμ¦ λ²νΈ : "+ePw); | ||
System.out.println("μμ΄λ : "+ UserId); | ||
MimeMessage message = emailSender.createMimeMessage(); | ||
|
||
message.addRecipients(Message.RecipientType.TO, to);//보λ΄λ λμ | ||
|
@@ -31,56 +32,27 @@ private MimeMessage createMessage(String to)throws Exception{ | |
msgg+= "<div style='margin:20px;'>"; | ||
msgg+= "<h1> μλ νμΈμ Attiesμ λλ€. </h1>"; | ||
msgg+= "<br>"; | ||
msgg+= "<p>μλ μ½λλ₯Ό 볡μ¬ν΄ μ λ ₯ν΄μ£ΌμΈμ<p>"; | ||
msgg+= "<br>"; | ||
msgg+= "<p>κ°μ¬ν©λλ€.<p>"; | ||
msgg+= "<br>"; | ||
msgg+= "<div align='center' style='border:1px solid black; font-family:verdana';>"; | ||
msgg+= "<h3 style='color:blue;'>νμκ°μ μΈμ¦ μ½λμ λλ€.</h3>"; | ||
msgg+= "<h3 style='color:blue;'>μλλ νμλμ μμ΄λμ λλ€.</h3>"; | ||
msgg+= "<div style='font-size:130%'>"; | ||
msgg+= "CODE : <strong>"; | ||
msgg+= ePw+"</strong><div><br/> "; | ||
msgg+= "νμID : <strong>"; | ||
msgg+= UserId+"</strong><div><br/> "; | ||
msgg+= "</div>"; | ||
message.setText(msgg, "utf-8", "html");//λ΄μ© | ||
message.setFrom(new InternetAddress("[email protected]","limjunho"));//보λ΄λ μ¬λ | ||
|
||
return message; | ||
} | ||
|
||
public static String createKey() { | ||
StringBuffer key = new StringBuffer(); | ||
Random rnd = new Random(); | ||
|
||
for (int i = 0; i < 8; i++) { // μΈμ¦μ½λ 8μ리 | ||
int index = rnd.nextInt(3); // 0~2 κΉμ§ λλ€ | ||
|
||
switch (index) { | ||
case 0: | ||
key.append((char) ((int) (rnd.nextInt(26)) + 97)); | ||
// a~z (ex. 1+97=98 => (char)98 = 'b') | ||
break; | ||
case 1: | ||
key.append((char) ((int) (rnd.nextInt(26)) + 65)); | ||
// A~Z | ||
break; | ||
case 2: | ||
key.append((rnd.nextInt(10))); | ||
// 0~9 | ||
break; | ||
} | ||
} | ||
return key.toString(); | ||
} | ||
@Override | ||
public String sendMessage(String to)throws Exception { | ||
// TODO Auto-generated method stub | ||
MimeMessage message = createMessage(to); | ||
try{//μμΈμ²λ¦¬ | ||
public void sendMessage(String to)throws Exception { | ||
String UserId = memberRepository.findByEmail(to).get().getUserId(); | ||
MimeMessage message = createMessage(to, UserId); | ||
try{ | ||
emailSender.send(message); | ||
}catch(MailException es){ | ||
es.printStackTrace(); | ||
throw new IllegalArgumentException(); | ||
} | ||
return ePw; | ||
} | ||
} |
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/com/sptp/backend/member/web/dto/request/MemberFindIdRequestDto.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 com.sptp.backend.member.web.dto.request; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class MemberFindIdRequestDto { | ||
|
||
private String username; | ||
private String email; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setFrom λ©μλ λΆλΆμμ μ‘μ μλͺ Attiesλ‘ μ€μ νλ©΄ μ’μ κ² κ°μ΅λλ€!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ΅ μμ νκ² μ΅λλ€!