Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #76 from hardingadonis/vuong_verify_user
Browse files Browse the repository at this point in the history
Vương: Verify users when they register
  • Loading branch information
GoldStarPro authored Dec 7, 2023
2 parents 238f8d1 + 5397528 commit 8cd6d85
Show file tree
Hide file tree
Showing 20 changed files with 339 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.hardingadonis.miu.controller.web;

import io.hardingadonis.miu.model.*;
import io.hardingadonis.miu.model.detail.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.*;
Expand All @@ -13,6 +15,15 @@ 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.DEACTIVATE)) {
response.sendRedirect("verify");
return;
}

request.getRequestDispatcher("/view/web/about.jsp").forward(request, response);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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.*;
Expand All @@ -22,7 +23,12 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
response.sendRedirect("login");
return;
}


if (user.getStatus() == UserStatus.DEACTIVATE) {
response.sendRedirect("verify");
return;
}

if (user.getAddress().size() >= 5) {
response.sendRedirect("delivery-address");
return;
Expand All @@ -47,10 +53,10 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String phone = request.getParameter("phone");

String newAddress = phone + ", " + receiver + ", " + specific + ", " + ward + ", " + district + ", " + city;

user.getAddress().add(newAddress);
Singleton.userDAO.update(user);

response.sendRedirect("delivery-address");
}
}
11 changes: 11 additions & 0 deletions src/main/java/io/hardingadonis/miu/controller/web/CartServlet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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.*;
Expand All @@ -15,6 +17,15 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
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.DEACTIVATE)) {
response.sendRedirect("verify");
return;
}

String cartDataStr = getCartCookie(request);

request.setAttribute("cart_data_str", cartDataStr);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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.*;
Expand All @@ -9,7 +10,7 @@

@WebServlet(name = "ChangePasswordServlet", urlPatterns = {"/change-password"})
public class ChangePasswordServlet extends HttpServlet {

private static final String CHANGE_PASSWORD_SUCCESS_PARAM = "changePasswordSuccess";

@Override
Expand All @@ -25,6 +26,11 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
return;
}

if (user.getStatus() == UserStatus.DEACTIVATE) {
response.sendRedirect("verify");
return;
}

request.getRequestDispatcher("/view/web/change-password.jsp").forward(request, response);
}

Expand All @@ -46,10 +52,10 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
} else {
user.setHashedPassword(hashedNewPassword);
Singleton.userDAO.update(user);

request.getSession(false).invalidate();
response.sendRedirect("login?" + CHANGE_PASSWORD_SUCCESS_PARAM + "=true");

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
return;
}

if (user.getStatus() == UserStatus.DEACTIVATE) {
response.sendRedirect("verify");
return;
}

long totalPrice = getTotalPrice(getCartCookie(request));

request.setAttribute("total_price", totalPrice);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.hardingadonis.miu.controller.web;

import io.hardingadonis.miu.model.User;
import io.hardingadonis.miu.model.detail.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.*;
Expand All @@ -16,8 +18,16 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)

HttpSession session = request.getSession();

if ((session.getAttribute("user") == null) || (session.getAttribute("order") == null) || (session.getAttribute("cart_cookie") == null)) {
User user = (User) session.getAttribute("user");

if ((user != null) && (user.getStatus() == UserStatus.DEACTIVATE)) {
response.sendRedirect("verify");
return;
}

if ((user == null) || (session.getAttribute("order") == null) || (session.getAttribute("cart_cookie") == null)) {
response.sendRedirect("home");
return;
}

request.getRequestDispatcher("/view/web/checkout-status.jsp").forward(request, response);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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.*;
Expand All @@ -22,6 +23,11 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
response.sendRedirect("login");
return;
}

if (user.getStatus() == UserStatus.DEACTIVATE) {
response.sendRedirect("verify");
return;
}

request.getRequestDispatcher("/view/web/delivery-address.jsp").forward(request, response);
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/hardingadonis/miu/controller/web/HomeServlet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.hardingadonis.miu.controller.web;

import io.hardingadonis.miu.model.*;
import io.hardingadonis.miu.model.detail.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.*;
Expand All @@ -13,6 +15,15 @@ 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.DEACTIVATE)) {
response.sendRedirect("verify");
return;
}

request.getRequestDispatcher("/view/web/home.jsp").forward(request, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,35 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

String email = request.getParameter("email");
String password = request.getParameter("password");

HttpSession session = request.getSession();

User user = Singleton.userDAO.get(email);

if (user != null && user.getHashedPassword().equals(Hash.SHA256(password)) && user.getStatus() == UserStatus.ACTIVATE) {
HttpSession session = request.getSession();
if (user != null && user.getHashedPassword().equals(Hash.SHA256(password))) {
session.setAttribute("user", user);
response.sendRedirect("home");

return;
if (user.getStatus() == UserStatus.ACTIVATE) {
response.sendRedirect("home");
return;
} else {
response.sendRedirect("verify");
return;
}
}

String errorMsg = "Sai mật khẩu!";
if (user != null && user.getStatus() == UserStatus.DEACTIVATE) {
errorMsg = "Tài khoản đã bị khóa!";
}
if (user == null) {
errorMsg = "Tài khoản không tồn tại!";
email = null;
}

request.setAttribute("email", email);
request.setAttribute("errorMsg", errorMsg);

this.doGet(request, response);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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.*;
Expand All @@ -15,6 +16,15 @@ 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.DEACTIVATE)) {
response.sendRedirect("verify");
return;
}

String IDStr = request.getParameter("id");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
return;
}

if (user.getStatus() == UserStatus.DEACTIVATE) {
response.sendRedirect("verify");
return;
}

request.setAttribute("gender", user.getGender().toString());

request.getRequestDispatcher("/view/web/profile.jsp").forward(request, response);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 java.util.*;
Expand All @@ -18,15 +19,22 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
response.setContentType("text/html; charset=UTF-8");

HttpSession session = request.getSession();

User user = (User) session.getAttribute("user");

int orderID = Integer.parseInt(request.getParameter("id"));

User user = (User) session.getAttribute("user");
Order order = Singleton.orderDAO.get(orderID);

if (user == null) {
response.sendRedirect("login");
return;
}

if (user.getStatus() == UserStatus.DEACTIVATE) {
response.sendRedirect("verify");
return;
}

if (order.getUserID() != user.getID()) {
response.sendRedirect("purchase-history?tab=all");
Expand Down
Loading

0 comments on commit 8cd6d85

Please sign in to comment.