-
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.
๐[Fix] ๋ก๊ทธ์ธํ์ง ์์ ์ฌ์ฉ์๊ฐ ๋น๋ฐ๋ฒํธ ์ฌ์ค์ ์ ํ ๊ฒฝ์ฐ ์์ ๋น๋ฐ๋ฒํธ๋ฅผ ๋ณธ์ธ ๋ฉ์ผ๋ก ๋ฐ์ก
- Loading branch information
Showing
6 changed files
with
245 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,26 @@ | |
import com.gamegoo.apiPayload.exception.handler.MemberHandler; | ||
import com.gamegoo.domain.member.Member; | ||
import com.gamegoo.repository.member.MemberRepository; | ||
import com.gamegoo.util.CodeGeneratorUtil; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.mail.javamail.MimeMessageHelper; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.mail.MessagingException; | ||
import javax.mail.internet.MimeMessage; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class PasswordService { | ||
|
||
private final MemberRepository memberRepository; | ||
private final BCryptPasswordEncoder bCryptPasswordEncoder; | ||
private final JavaMailSender javaMailSender; | ||
|
||
|
||
/** | ||
* ๋น๋ฐ๋ฒํธ๊ฐ ๋ง๋์ง ํ์ธ | ||
|
@@ -29,7 +39,7 @@ public boolean checkPasswordById(Long userId, String password) { | |
} | ||
|
||
/** | ||
* ๋น๋ฐ๋ฒํธ ์์ | ||
* ๋น๋ฐ๋ฒํธ ์์ (๋ก๊ทธ์ธO) | ||
* | ||
* @param userId | ||
* @param newPassword | ||
|
@@ -49,28 +59,204 @@ public void updatePassword(Long userId, String oldPassword, String newPassword) | |
throw new MemberHandler(ErrorStatus.PASSWORD_INVALID); | ||
} | ||
|
||
|
||
} | ||
|
||
/** | ||
* ๋น๋ฐ๋ฒํธ ์์ | ||
* ๋น๋ฐ๋ฒํธ ์์ (๋ก๊ทธ์ธX) | ||
* | ||
* @param email | ||
* @param newPassword | ||
*/ | ||
public void updatePasswordWithEmail(String email, String oldPassword, String newPassword) { | ||
// jwt ํ ํฐ์ผ๋ก ๋ฉค๋ฒ ์ฐพ๊ธฐ | ||
public void updatePasswordWithEmail(String email) { | ||
// email์ผ๋ก ๋ฉค๋ฒ ์ฐพ๊ธฐ | ||
Member member = memberRepository.findByEmail(email) | ||
.orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); | ||
|
||
// ๋๋ค ์์ ๋น๋ฐ๋ฒํธ ์์ฑ | ||
String tempPassword = CodeGeneratorUtil.generatePasswordRandomCode(); | ||
|
||
// ์ด๋ฉ์ผ ์ ์ก | ||
sendEmailInternal(email,tempPassword); | ||
|
||
if (bCryptPasswordEncoder.matches(oldPassword,member.getPassword())) { | ||
// ๋น๋ฐ๋ฒํธ ์ฌ์ค์ | ||
member.updatePassword(bCryptPasswordEncoder.encode(newPassword)); | ||
member.updatePassword(bCryptPasswordEncoder.encode(tempPassword)); | ||
memberRepository.save(member); | ||
}else{ | ||
throw new MemberHandler(ErrorStatus.PASSWORD_INVALID); | ||
} | ||
|
||
/** | ||
* Gmail ๋ฐ์ก | ||
* | ||
* @param email | ||
* @param tempPassword | ||
*/ | ||
public void sendEmailInternal(String email, String tempPassword) { | ||
try { | ||
log.info("Starting email send process for email: {}, certificationNumber: {}", email, | ||
tempPassword); | ||
|
||
MimeMessage message = javaMailSender.createMimeMessage(); | ||
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(message, true); | ||
|
||
String htmlContent = getTempPasswordMessage(tempPassword); | ||
|
||
mimeMessageHelper.setTo(email); | ||
mimeMessageHelper.setSubject("GameGoo ์์ ๋น๋ฐ๋ฒํธ ๋ฐ๊ธ"); | ||
mimeMessageHelper.setText(htmlContent, true); | ||
log.debug("Prepared email message for email: {}", email); | ||
|
||
javaMailSender.send(message); | ||
log.info("Email sent successfully to email: {}", email); | ||
|
||
|
||
} catch (MessagingException e) { | ||
log.error("Failed to send email to email: {}, certificationNumber: {}, error: {}", | ||
email, tempPassword, e.getMessage()); | ||
|
||
throw new MemberHandler(ErrorStatus.EMAIL_SEND_ERROR); | ||
} | ||
} | ||
|
||
/** | ||
* ๋ฉ์ผ ๋ด์ฉ ํธ์ง | ||
* | ||
* @param tempPassword | ||
* @return | ||
*/ | ||
private String getTempPasswordMessage(String tempPassword) { | ||
String certificationMessage = "" | ||
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" | ||
+ | ||
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + | ||
" <head>\n" + | ||
" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" + | ||
" <title>Gamegoo ์์ ๋น๋ฐ๋ฒํธ ๋ฐ๊ธ</title>\n" + | ||
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n" + | ||
" </head>\n" + | ||
" <body>\n" + | ||
" <table\n" + | ||
" style=\"\n" + | ||
" width: 628px;\n" + | ||
" box-sizing: border-box;\n" + | ||
" border-collapse: collapse;\n" + | ||
" background-color: #ffffff;\n" + | ||
" border: 1px solid #c0c0c0;\n" + | ||
" text-align: left;\n" + | ||
" margin: 0 auto;\n" + | ||
" \"\n" + | ||
" >\n" + | ||
" <tbody>\n" + | ||
" <tr>\n" + | ||
" <td>\n" + | ||
" <table\n" + | ||
" cellpadding=\"0\"\n" + | ||
" cellspacing=\"0\"\n" + | ||
" style=\"width: 628px; height: 521px; padding: 53px 62px 42px 62px\"\n" + | ||
" >\n" + | ||
" <tbody>\n" + | ||
" <tr>\n" + | ||
" <td style=\"padding-bottom: 11.61px\">\n" + | ||
" <img\n" + | ||
" src=\"https://ifh.cc/g/BY3XG2.png\"\n" + | ||
" style=\"display: block\"\n" + | ||
" width=\"137\"\n" + | ||
" height=\"24\"\n" + | ||
" alt=\"Gamegoo\"\n" + | ||
" />\n" + | ||
" </td>\n" + | ||
" </tr>\n" + | ||
" <tr>\n" + | ||
" <td style=\"padding-top: 20px\">\n" + | ||
" <span\n" + | ||
" style=\"\n" + | ||
" color: #2d2d2d;\n" + | ||
" font-family: Pretendard;\n" + | ||
" font-size: 25px;\n" + | ||
" font-style: normal;\n" + | ||
" font-weight: 400;\n" + | ||
" line-height: 150%;\n" + | ||
" \"\n" + | ||
" >\n" + | ||
" ์์ ๋น๋ฐ๋ฒํธ๋ฅผ ํ์ธํด์ฃผ์ธ์\n" + | ||
" </span>\n" + | ||
" </td>\n" + | ||
" </tr>\n" + | ||
" <tr>\n" + | ||
" <td style=\"padding-top: 38px\">\n" + | ||
" <span\n" + | ||
" style=\"\n" + | ||
" color: #5a42ee;\n" + | ||
" color: #2d2d2d;\n" + | ||
" font-size: 32px;\n" + | ||
" font-style: normal;\n" + | ||
" font-weight: 700;\n" + | ||
" line-height: 150%;\n" + | ||
" margin-bottom: 30px;\n" + | ||
" \"\n" + | ||
" >\n" + | ||
tempPassword + | ||
" </span>\n" + | ||
" </td>\n" + | ||
" </tr>\n" + | ||
" <tr>\n" + | ||
" <td style=\"padding-top: 30px\">\n" + | ||
" <span\n" + | ||
" style=\"\n" + | ||
" color: #2d2d2d;\n" + | ||
" font-family: Pretendard;\n" + | ||
" font-size: 18px;\n" + | ||
" font-style: normal;\n" + | ||
" font-weight: 400;\n" + | ||
" line-height: 150%;\n" + | ||
" \"\n" + | ||
" >\n" + | ||
" ์์ ๋น๋ฐ๋ฒํธ๊ฐ ๋ฐ๊ธ๋์์ต๋๋ค. \n" + | ||
" ๊ฐ์ฌํฉ๋๋ค.\n" + | ||
" </span>\n" + | ||
" </td>\n" + | ||
" </tr>\n" + | ||
" </tbody>\n" + | ||
" </table>\n" + | ||
" <table\n" + | ||
" cellpadding=\"0\"\n" + | ||
" cellspacing=\"0\"\n" + | ||
" style=\"\n" + | ||
" width: 628px;\n" + | ||
" height: 292px;\n" + | ||
" padding: 37px 0px 153px 62px;\n" + | ||
" background: #f7f7f9;\n" + | ||
" \"\n" + | ||
" >\n" + | ||
" <tbody>\n" + | ||
" <tr>\n" + | ||
" <td>\n" + | ||
" <span\n" + | ||
" style=\"\n" + | ||
" color: #606060;\n" + | ||
" font-family: Pretendard;\n" + | ||
" font-size: 11px;\n" + | ||
" font-style: normal;\n" + | ||
" font-weight: 500;\n" + | ||
" line-height: 150%;\n" + | ||
" \"\n" + | ||
" >\n" + | ||
" ๋ณธ ๋ฉ์ผ์ ๋ฐ์ ์ ์ฉ์ผ๋ก ํ์ ๋์ง ์์ต๋๋ค.<br />\n" + | ||
" ๊ถ๊ธํ์ ์ ์ ๊ฒ๊ตฌ ์ด๋ฉ์ผ์ด๋ ์นด์นด์ค ์ฑ๋์ ํตํด\n" + | ||
" ๋ฌธ์ํ์๊ธฐ ๋ฐ๋๋๋ค.<br /><br />\n" + | ||
" email: [email protected]<br />\n" + | ||
" kakao: https://pf.kakao.com/_Rrxiqn<br />\n" + | ||
" copyright 2024. GameGoo All Rights Reserved.<br />\n" + | ||
" </span>\n" + | ||
" </td>\n" + | ||
" </tr>\n" + | ||
" </tbody>\n" + | ||
" </table>\n" + | ||
" </td>\n" + | ||
" </tr>\n" + | ||
" </tbody>\n" + | ||
" </table>\n" + | ||
" </body>\n" + | ||
"</html>\n"; | ||
|
||
return certificationMessage; | ||
} | ||
|
||
} |
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