티스토리 뷰

웹 개발/SpringBoot

[Spirng Boot] Password Reset

스톤승현 2022. 11. 9. 14:31

- MemberController

@RequestMapping(value = "recoverPasswordEmail",
method = RequestMethod.GET,
produces = MediaType.TEXT_HTML_VALUE)
@ResponseBody
public ModelAndView getRecoverPasswordEmail(EmailAuthEntity emailAuth) {
    Enum<?> result = this.memberService.recoverPasswordAuth(emailAuth);
    ModelAndView modelAndView = new ModelAndView("member/recoverPasswordEmail");
    modelAndView.addObject("result", result.name());

    return modelAndView;
}

- MemberService

public Enum<? extends IResult> recoverPasswordAuth(EmailAuthEntity emailAuth) {
    EmailAuthEntity existingEmailAuth = this.memberMapper.selectEmailAuthByEmailCodeSalt(
            emailAuth.getEmail(),
            emailAuth.getCode(),
            emailAuth.getSalt());

    if (existingEmailAuth== null) {
        return CommonResult.FAILURE;
    }
    if (new Date().compareTo(existingEmailAuth.getExpiresOn()) > 0) {
        return CommonResult.FAILURE;

    }
    existingEmailAuth.setExpired(true);
    if(this.memberMapper.updateEmailAuth(existingEmailAuth) == 0) {
        return CommonResult.FAILURE;
    }
    return CommonResult.SUCCESS;
}

- recoverPasswordEmail.html

<!doctype html>
<html lang="ko"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>스터디 - 이메일 인증</title>
    <!--/*@thymesVar id="equals" type="java.lang.String"*/-->
    <script th:if="${result != null && result.equals('SUCCESS')}">
        alert('이메일 인증이 완료되었습니다.\n\n비밀번호 재설정 페이지로 돌아가 계속해 주세요.');
        window.close();
    </script>
    <script th:if="${result == null && !result.equals('SUCCESS')}">
        alert('이메일 인증에 실패하였습니다.\n\n인증 링크가 만료되었거나 일시적인 문제일 수 있습니다.');
        window.close();
    </script>
</head>
<body>

</body>
</html>

인증하기 클릭하였을 때
위에 화면이 나오면 정상!

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2026/04   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
글 보관함