Skip to content
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

Develop #25

Merged
merged 88 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
17c2e5a
add model - User.java file
nguyenkhanhquy Nov 11, 2023
1950adf
add model - Role.java file
nguyenkhanhquy Nov 11, 2023
011969a
add models
Bisoo12300 Nov 11, 2023
32fbad0
add models
NguyenDink Nov 11, 2023
4819e9d
add model - Cart.java file
nguyenkhanhquy Nov 11, 2023
a8e48f4
add entity
nguyenkhanhquy Nov 11, 2023
fa10ad6
update entities
nguyenkhanhquy Nov 16, 2023
42dfb80
edit entities
nguyenkhanhquy Nov 16, 2023
ae813fb
edit entities, add entityDB
nguyenkhanhquy Nov 16, 2023
8d6a640
add register
NguyenDink Nov 16, 2023
8e4a01e
add folders
nguyenkhanhquy Nov 17, 2023
28f2352
change package data -> dao
nguyenkhanhquy Nov 17, 2023
2b38c9a
add view
nguyenkhanhquy Nov 17, 2023
8356802
Merge pull request #1 from nguyenkhanhquy/feature/Login
nguyenkhanhquy Nov 17, 2023
dae4b92
fix view register
nguyenkhanhquy Nov 17, 2023
2775a5c
add dao
NguyenDink Nov 17, 2023
a7a820d
add dao
nguyenkhanhquy Nov 17, 2023
df07deb
add dao - LineItemDB.java file
Bisoo12300 Nov 17, 2023
d227dcc
fix input radio - registerView.jsp file
nguyenkhanhquy Nov 17, 2023
c4d0985
Merge pull request #2 from nguyenkhanhquy/develop
nguyenkhanhquy Nov 17, 2023
bde0ca1
edit model - User.java file
nguyenkhanhquy Nov 17, 2023
85b4ff8
edit registerView.jsp file
nguyenkhanhquy Nov 18, 2023
0fdf3e2
Merge pull request #3 from nguyenkhanhquy/feature/Register
nguyenkhanhquy Nov 18, 2023
a1982d9
Merge pull request #4 from nguyenkhanhquy/develop
nguyenkhanhquy Nov 18, 2023
95b14ec
add feature - login
nguyenkhanhquy Nov 18, 2023
01717da
update entities
nguyenkhanhquy Nov 18, 2023
0969d6d
update home page
nguyenkhanhquy Nov 18, 2023
02c78cf
add PasswordEncryptorUtil
nguyenkhanhquy Nov 18, 2023
2d60bbf
Merge pull request #5 from nguyenkhanhquy/feature/Login
nguyenkhanhquy Nov 18, 2023
b2c41c5
add show category
NguyenDink Nov 18, 2023
43c93a1
add show product
nguyenkhanhquy Nov 18, 2023
fff0545
Merge pull request #6 from nguyenkhanhquy/feature/ShowProduct
nguyenkhanhquy Nov 18, 2023
3256d22
add filter - EncodingFilter.java file
nguyenkhanhquy Nov 18, 2023
d79326d
add filter - CookieFilter.java file
nguyenkhanhquy Nov 18, 2023
ba8c6b6
add feature update password
nguyenkhanhquy Nov 18, 2023
ea6b815
add feature update user info
nguyenkhanhquy Nov 19, 2023
44d3747
add includes folder - layout web
nguyenkhanhquy Nov 19, 2023
8b9c6c3
Merge pull request #7 from nguyenkhanhquy/feature/AccountSettings
nguyenkhanhquy Nov 19, 2023
140f285
fix updatePasswordView.jsp file
nguyenkhanhquy Nov 19, 2023
8d9550a
fix successView.jsp file
nguyenkhanhquy Nov 19, 2023
3dd8b29
add LoadMoreController.java file
NguyenDink Nov 19, 2023
d75720d
update LoadMoreController.java file
nguyenkhanhquy Nov 19, 2023
5de344b
add logo vs product image
Bisoo12300 Nov 19, 2023
9246378
logo again
Bisoo12300 Nov 19, 2023
9f7cabe
add logo
Bisoo12300 Nov 19, 2023
f7e4715
fix EncodingFilter.java file
nguyenkhanhquy Nov 20, 2023
3e56855
update image data
nguyenkhanhquy Nov 20, 2023
63339fa
edit register.css file
nguyenkhanhquy Nov 20, 2023
6d01308
remove dependency
nguyenkhanhquy Nov 20, 2023
92fe8cc
Merge pull request #9 from nguyenkhanhquy/feature/LoadProduct
nguyenkhanhquy Nov 20, 2023
04a0a7f
add CategoryController.java file
NguyenDink Nov 20, 2023
9b9a2fb
edit controllers
nguyenkhanhquy Nov 21, 2023
cda7bcf
add "all categories" option
nguyenkhanhquy Nov 21, 2023
c5278fc
add show role name
nguyenkhanhquy Nov 21, 2023
bb4ee9e
update model - Product.java file
nguyenkhanhquy Nov 21, 2023
43c0404
Merge pull request #10 from nguyenkhanhquy/feature/Category
nguyenkhanhquy Nov 21, 2023
4e08f60
add send email
nguyenkhanhquy Nov 21, 2023
fb3d844
Merge pull request #11 from nguyenkhanhquy/feature/SendMail
nguyenkhanhquy Nov 21, 2023
567dfb5
fix LoadMore Category
NguyenDink Nov 21, 2023
cf0b31e
a
Bisoo12300 Nov 23, 2023
b755db5
fix search product
NguyenDink Nov 23, 2023
52d44e5
Merge pull request #12 from nguyenkhanhquy/feature/Category
nguyenkhanhquy Nov 23, 2023
c4c1cec
edit dao - ProductDB.java file
NguyenDink Nov 23, 2023
ca2051f
Merge pull request #13 from nguyenkhanhquy/feature/SearchProduct
nguyenkhanhquy Nov 23, 2023
0f2e714
add feature - manager product
nguyenkhanhquy Nov 23, 2023
ea4d8bd
add feature - add product
nguyenkhanhquy Nov 24, 2023
4eb27b4
add feature - pagination
nguyenkhanhquy Nov 25, 2023
3e14ee4
add feature - show detail product
NguyenDink Nov 25, 2023
ea6aff0
add feature - CRUD product
nguyenkhanhquy Nov 25, 2023
f575f1d
Merge branch 'develop' into feature/LoadMore
nguyenkhanhquy Nov 25, 2023
33fc90b
Merge pull request #15 from nguyenkhanhquy/feature/LoadMore
nguyenkhanhquy Nov 25, 2023
79780b2
add view - cartView.jsp file
nguyenkhanhquy Nov 25, 2023
2ace529
code optimization
nguyenkhanhquy Nov 26, 2023
d269391
feature bug fix - update user info
nguyenkhanhquy Nov 26, 2023
a554729
add feature - CRUD user
nguyenkhanhquy Nov 26, 2023
4f52225
Merge pull request #17 from nguyenkhanhquy/feature/UserManagement
nguyenkhanhquy Nov 26, 2023
a117f3f
add CRUD of Category in Admin
Bisoo12300 Nov 26, 2023
3063469
fix bug - CRUD category
nguyenkhanhquy Nov 27, 2023
02e3566
Merge pull request #18 from nguyenkhanhquy/feature/CategoryManagement
nguyenkhanhquy Nov 27, 2023
b9b9b56
add controller - CartController.java file
nguyenkhanhquy Nov 28, 2023
1fcc92c
update feature cart
nguyenkhanhquy Nov 30, 2023
ef39298
add feature - view order
nguyenkhanhquy Dec 1, 2023
3561dc8
add feature - view detail order
nguyenkhanhquy Dec 2, 2023
4e7fd46
update feature - view detail order
nguyenkhanhquy Dec 2, 2023
0703410
add error page
nguyenkhanhquy Dec 5, 2023
c814154
edit LoadMoreController
NguyenDink Dec 5, 2023
89bc7d3
fix feature - load more
nguyenkhanhquy Dec 6, 2023
8dfe073
add feature - OTP
nguyenkhanhquy Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add feature - OTP
  • Loading branch information
nguyenkhanhquy committed Dec 6, 2023
commit 8dfe073cf8dae5098fe01b1e5eb9dd6c370f313a
41 changes: 6 additions & 35 deletions src/main/java/com/jacobin/controllers/RegisterController.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
package com.jacobin.controllers;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import javax.mail.MessagingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.jacobin.dao.CartDB;
import com.jacobin.dao.RoleDB;
import com.jacobin.dao.UserDB;
import com.jacobin.models.Cart;
import com.jacobin.models.Role;
import com.jacobin.models.User;
import com.jacobin.utils.PasswordEncryptorUtil;

import com.jacobin.utils.MailUtilGmail;

@WebServlet(urlPatterns = { "/register" })
public class RegisterController extends HttpServlet {

Expand Down Expand Up @@ -75,41 +70,17 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
} else if (!user.getPassword().equals(passwordAgain)) {
message = "Mật khẩu không khớp.<br>" + "Vui lòng nhập lại.";
} else {
message = "Đăng ký thành công!";
url = "/WEB-INF/views/customer/successView.jsp";
password = PasswordEncryptorUtil.toSHA1(password);
user.setPassword(password);
UserDB.insert(user);

Cart cart = new Cart();
cart.setUser(user);
CartDB.insert(cart);

// Gửi email đến email của user
String to = email;
String from = "shop.javamail@gmail.com";
String subject = "Chào mừng đến với Jacobin Store";
String body = "Chào " + firstName + ",\n\n"
+ "Chúng tôi rất vui mừng thông báo rằng bạn đã đăng ký thành công tài khoản mới tại Jacobin Store!\n\n"
+ "Chào mừng bạn đến với cửa hàng của chúng tôi và cảm ơn bạn đã chọn chúng tôi để trải nghiệm mua sắm trực tuyến.\n\n"
+ "Hãy khám phá thế giới mua sắm tuyệt vời tại Jacobin Store ngay bây giờ.\n\n"
+ "Chúc bạn có những trải nghiệm mua sắm thú vị và hài lòng!\n\n"
+ "Trân trọng, Jacobin Store.";
boolean isBodyHTML = false;

try {
MailUtilGmail.sendMail(to, from, subject, body, isBodyHTML);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpSession session = req.getSession();
session.setAttribute("user", user);
message = "";
url = "/WEB-INF/views/customer/verifyOTPView.jsp";
}

req.setAttribute("user", user);
req.setAttribute("message", message);
getServletContext().getRequestDispatcher(url).forward(req, resp);
req.getRequestDispatcher(url).forward(req, resp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.jacobin.controllers.customer;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Random;

import javax.mail.MessagingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.jacobin.dao.UserDB;
import com.jacobin.models.User;
import com.jacobin.utils.MailUtilGmail;
import com.jacobin.utils.PasswordEncryptorUtil;

@WebServlet(urlPatterns = {"/forgot-password"})
public class ForgotPasswordController extends HttpServlet {

private static final long serialVersionUID = 1L;

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

String url = "/WEB-INF/views/customer/forgotPasswordView.jsp";

HttpSession session = req.getSession();
String email = null;
String message = null;
String action = req.getParameter("action");
if (action == null) {
action = "";
} else {
email = req.getParameter("email");
if (action.equals("send")) {
User user = UserDB.selectUserByEmail(email);
if (user == null) {
message = "Email không tồn tại trên hệ thống!";
}
else {
message = "Đã gửi mã OTP tới email của bạn!";

Random random = new Random();
int otp = random.nextInt(900000) + 100000;
String otpString = String.valueOf(otp);
session.setAttribute("otpSend", otpString);

// Gửi email đến email của user
String to = user.getEmail();
String from = "shop.javamail@gmail.com";
String subject = "Xác minh email";
String body = "Chào " + user.getFirstName() + ",\n\n"
+ "Mã OTP của bạn là: " + otpString;
boolean isBodyHTML = false;

try {
MailUtilGmail.sendMail(to, from, subject, body, isBodyHTML);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else if (action.equals("confirm")) {
String otp = req.getParameter("otp");

String otpSend = (String) session.getAttribute("otpSend");

if (otp.equals(otpSend)) {
url = "/WEB-INF/views/customer/newPasswordView.jsp";
}
else {
message = "Mã OTP bạn nhập không đúng!";
}
} else if (action.equals("newpass")){
url = "/WEB-INF/views/customer/newPasswordView.jsp";

String newPassword = req.getParameter("newPassword");
String newPasswordAgain = req.getParameter("newPasswordAgain");

email = req.getParameter("email");
User user = UserDB.selectUserByEmail(email);

if (!newPassword.equals(newPasswordAgain)) {
message = "Mật khẩu nhập lại không khớp!";
} else {
message = "Đổi mật khẩu thành công!";
url = "/WEB-INF/views/customer/successView.jsp";
newPassword = PasswordEncryptorUtil.toSHA1(newPassword);
user.setPassword(newPassword);
UserDB.update(user);

session.removeAttribute("otpSend");
}
} else {
message = "";
}
}
req.setAttribute("email", email);
req.setAttribute("message", message);
req.getRequestDispatcher(url).forward(req, resp);
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

doGet(req, resp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package com.jacobin.controllers.customer;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Random;

import javax.mail.MessagingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.jacobin.dao.CartDB;
import com.jacobin.dao.UserDB;
import com.jacobin.models.Cart;
import com.jacobin.models.User;
import com.jacobin.utils.MailUtilGmail;

@WebServlet(urlPatterns = { "/verify-otp" })
public class VerifyOTPController extends HttpServlet {

private static final long serialVersionUID = 1L;

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

resp.sendRedirect("home");
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

String url = "/WEB-INF/views/customer/verifyOTPView.jsp";

String action = req.getParameter("action");
if (action == null) {
action = "";
}

HttpSession session = req.getSession();
User user = (User) session.getAttribute("user");

String message;
if (action.equals("send")) {
message = "Đã gửi mã OTP tới email của bạn!";

Random random = new Random();
int otp = random.nextInt(900000) + 100000;
String otpString = String.valueOf(otp);
session.setAttribute("otpSend", otpString);

// Gửi email đến email của user
String to = user.getEmail();
String from = "shop.javamail@gmail.com";
String subject = "Xác minh email";
String body = "Chào " + user.getFirstName() + ",\n\n"
+ "Mã OTP của bạn là: " + otpString;
boolean isBodyHTML = false;

try {
MailUtilGmail.sendMail(to, from, subject, body, isBodyHTML);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (action.equals("confirm")) {
String otp = req.getParameter("otp");

String otpSend = (String) session.getAttribute("otpSend");
if (otp.equals(otpSend)) {
message = "Đăng ký thành công!";
url = "/WEB-INF/views/customer/successView.jsp";
UserDB.insert(user);

Cart cart = new Cart();
cart.setUser(user);
CartDB.insert(cart);

// Gửi email đến email của user
String to = user.getEmail();
String from = "shop.javamail@gmail.com";
String subject = "Chào mừng đến với Jacobin Store";
String body = "Chào " + user.getFirstName() + ",\n\n"
+ "Chúng tôi rất vui mừng thông báo rằng bạn đã đăng ký thành công tài khoản mới tại Jacobin Store!\n\n"
+ "Chào mừng bạn đến với cửa hàng của chúng tôi và cảm ơn bạn đã chọn chúng tôi để trải nghiệm mua sắm trực tuyến.\n\n"
+ "Hãy khám phá thế giới mua sắm tuyệt vời tại Jacobin Store ngay bây giờ.\n\n"
+ "Chúc bạn có những trải nghiệm mua sắm thú vị và hài lòng!\n\n"
+ "Trân trọng, Jacobin Store.";
boolean isBodyHTML = false;

try {
MailUtilGmail.sendMail(to, from, subject, body, isBodyHTML);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

session.removeAttribute("user");
session.removeAttribute("otpSend");
}
else {
message = "Mã OTP bạn nhập không đúng!";
}
} else {
message = "";
}

req.setAttribute("message", message);
req.getRequestDispatcher(url).forward(req, resp);
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/jacobin/dao/UserDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ public static User selectUserByUserName(String userName) {
em.close();
}
}

public static User selectUserByEmail(String email) {
EntityManager em = DBUtil.getEmFactory().createEntityManager();
String qString = "SELECT u FROM User u " +
"WHERE u.email = :email";
TypedQuery<User> q = em.createQuery(qString, User.class);
q.setParameter("email", email);
try {
User user = q.getSingleResult();
return user;
} catch (NoResultException e) {
return null;
} finally {
em.close();
}
}

public static boolean checkEmailExists(String email) {
EntityManager em = DBUtil.getEmFactory().createEntityManager();
Expand Down
6 changes: 3 additions & 3 deletions src/main/webapp/WEB-INF/views/cartView.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@
<div class="p-4">
<div class="form-floating mb-4">
<input type="text" class="form-control" id="ten" placeholder="Tên" name="firstName" value="${loginedUser.firstName}" required readonly>
<label for="ten">Tên<span class="red">*</span></label>
<label for="ten">Tên <span class="red">*</span></label>
</div>

<div class="form-floating mb-4">
<input type="tel" class="form-control" id="dienThoai" placeholder="Số điện thoại" name="phone" value="${loginedUser.phone}" required readonly>
<label for="dienThoai">Số điện thoại<span class="red">*</span></label>
<label for="dienThoai">Số điện thoại <span class="red">*</span></label>
</div>

<div class="form-floating mb-4">
<input type="text" class="form-control" id="diaChiKhachHang" placeholder="Địa chỉ" name="address" value="${loginedUser.address}" required>
<label for="diaChiKhachHang">Địa chỉ<span class="red">*</span></label>
<label for="diaChiKhachHang">Địa chỉ <span class="red">*</span></label>
</div>

<select name="paymentMethod" class="form-select mb-4" required>
Expand Down
Loading