This repository has been archived by the owner on Dec 31, 2023. It is now read-only.
-
-
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.
- Loading branch information
1 parent
0cf45f0
commit 0a64834
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/main/java/io/hardingadonis/miu/controller/web/VerifyServlet.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,69 @@ | ||
package io.hardingadonis.miu.controller.web; | ||
|
||
import io.hardingadonis.miu.model.*; | ||
import io.hardingadonis.miu.model.detail.*; | ||
import io.hardingadonis.miu.services.*; | ||
import java.io.*; | ||
import javax.servlet.*; | ||
import javax.servlet.annotation.*; | ||
import javax.servlet.http.*; | ||
|
||
@WebServlet(name = "VerifyServlet", urlPatterns = {"/verify"}) | ||
public class VerifyServlet extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
|
||
HttpSession session = request.getSession(); | ||
|
||
User user = (User) session.getAttribute("user"); | ||
|
||
if ((user == null) || (user.getStatus() == UserStatus.ACTIVATE)) { | ||
response.sendRedirect("home"); | ||
return; | ||
} | ||
|
||
String email = request.getParameter("email"); | ||
|
||
String msg = null; | ||
|
||
if ((email == null) || (email.isEmpty())) { | ||
String hashedStr = Hash.SHA256(email + System.currentTimeMillis()); | ||
|
||
session.setAttribute("hashed_str", hashedStr); | ||
|
||
Singleton.email.sendVerifyEmail(user, hashedStr, request); | ||
|
||
msg = "Bạn đã nhận được một email xác thực tài khoản. Vui lòng kiểm tra email!"; | ||
} else { | ||
if (user.getEmail().equals(email)) { | ||
String hashedStrParameter = request.getParameter("code"); | ||
String hashedStrSession = (String) session.getAttribute("hashed_str"); | ||
|
||
if ((hashedStrParameter != null) && (hashedStrSession != null) && (hashedStrParameter.equals(hashedStrSession))) { | ||
user.setStatus(UserStatus.ACTIVATE); | ||
|
||
session.setAttribute("hashed_str", null); | ||
|
||
request.setAttribute("success", true); | ||
|
||
Singleton.userDAO.update(user); | ||
Singleton.email.sendWelcomeEmail(user); | ||
|
||
msg = "Xác thực thành công!"; | ||
} else { | ||
msg = "Xác thực thất bại!"; | ||
} | ||
} else { | ||
msg = "Xác thực thất bại!"; | ||
} | ||
} | ||
|
||
request.setAttribute("msg", msg); | ||
|
||
request.getRequestDispatcher("/view/web/verify.jsp").forward(request, response); | ||
} | ||
} |
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,50 @@ | ||
<%@ page contentType="text/html" pageEncoding="UTF-8" %> | ||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> | ||
|
||
<!DOCTYPE html> | ||
|
||
<html> | ||
|
||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
|
||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" /> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" /> | ||
<link rel="stylesheet" href="<%=request.getContextPath()%>/assets/css/web/common/common.css" /> | ||
|
||
<link rel="icon" type="image/x-icon" href="<%=request.getContextPath()%>/assets/images/favicon/favicon.png"> | ||
|
||
<title>Miu Shop | Xác thực</title> | ||
</head> | ||
|
||
<body> | ||
<%@include file="common/_header.jsp" %> | ||
|
||
<section class="container"> | ||
<div class="py-5 my-5"> | ||
<div class="container my-5"> | ||
<h6 class="display-6 mb-4 d-flex justify-content-center"> | ||
Xác thực tài khoản | ||
</h6> | ||
<br> | ||
<div class="text-center"> | ||
${msg} | ||
</div> | ||
<br> | ||
<c:if test="${success == true}"> | ||
<div class="d-flex justify-content-center"> | ||
<a href="home" class="btn btn-outline-dark">Bắt đầu mua sắm</a> | ||
</div> | ||
</c:if> | ||
<br> | ||
</div> | ||
</div> | ||
</section> | ||
|
||
<%@include file="common/_footer.jsp" %> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> | ||
<script src="<%=request.getContextPath()%>/assets/js/web/common/commonHandler.js"></script> | ||
</body> | ||
|
||
</html> |