diff --git a/flower_shop.sql b/flower_shop.sql index f04a319..af2c336 100644 --- a/flower_shop.sql +++ b/flower_shop.sql @@ -2,10 +2,10 @@ -- version 5.2.1 -- https://www.phpmyadmin.net/ -- --- Host: 127.0.0.1 --- Generation Time: Nov 28, 2023 at 10:41 AM --- Server version: 10.4.28-MariaDB --- PHP Version: 8.2.4 +-- Máy chủ: 127.0.0.1 +-- Thời gian đã tạo: Th10 30, 2023 lúc 10:16 AM +-- Phiên bản máy phục vụ: 10.4.28-MariaDB +-- Phiên bản PHP: 8.2.4 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; START TRANSACTION; @@ -18,7 +18,7 @@ SET time_zone = "+00:00"; /*!40101 SET NAMES utf8mb4 */; -- --- Database: `flower_shop` +-- Cơ sở dữ liệu: `flower_shop` -- CREATE DATABASE IF NOT EXISTS `flower_shop` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; USE `flower_shop`; @@ -26,7 +26,7 @@ USE `flower_shop`; -- -------------------------------------------------------- -- --- Table structure for table `admin` +-- Cấu trúc bảng cho bảng `admin` -- CREATE TABLE `admin` ( @@ -37,7 +37,7 @@ CREATE TABLE `admin` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- --- Dumping data for table `admin` +-- Đang đổ dữ liệu cho bảng `admin` -- INSERT INTO `admin` (`id`, `username`, `password`, `role`) VALUES @@ -49,7 +49,7 @@ INSERT INTO `admin` (`id`, `username`, `password`, `role`) VALUES -- -------------------------------------------------------- -- --- Table structure for table `cart` +-- Cấu trúc bảng cho bảng `cart` -- CREATE TABLE `cart` ( @@ -59,7 +59,7 @@ CREATE TABLE `cart` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- --- Dumping data for table `cart` +-- Đang đổ dữ liệu cho bảng `cart` -- INSERT INTO `cart` (`user_id`, `product_id`, `amount`) VALUES @@ -97,7 +97,7 @@ INSERT INTO `cart` (`user_id`, `product_id`, `amount`) VALUES -- -------------------------------------------------------- -- --- Table structure for table `categories` +-- Cấu trúc bảng cho bảng `categories` -- CREATE TABLE `categories` ( @@ -106,7 +106,7 @@ CREATE TABLE `categories` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- --- Dumping data for table `categories` +-- Đang đổ dữ liệu cho bảng `categories` -- INSERT INTO `categories` (`id`, `name`) VALUES @@ -119,7 +119,7 @@ INSERT INTO `categories` (`id`, `name`) VALUES -- -------------------------------------------------------- -- --- Table structure for table `data_order` +-- Cấu trúc bảng cho bảng `data_order` -- CREATE TABLE `data_order` ( @@ -129,7 +129,7 @@ CREATE TABLE `data_order` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- --- Dumping data for table `data_order` +-- Đang đổ dữ liệu cho bảng `data_order` -- INSERT INTO `data_order` (`order_id`, `product_id`, `amount`) VALUES @@ -165,12 +165,13 @@ INSERT INTO `data_order` (`order_id`, `product_id`, `amount`) VALUES (30, 15, 1), (32, 44, 1), (33, 14, 1), -(34, 20, 2); +(34, 20, 2), +(35, 22, 2); -- -------------------------------------------------------- -- --- Table structure for table `order` +-- Cấu trúc bảng cho bảng `order` -- CREATE TABLE `order` ( @@ -183,7 +184,7 @@ CREATE TABLE `order` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- --- Dumping data for table `order` +-- Đang đổ dữ liệu cho bảng `order` -- INSERT INTO `order` (`id`, `user_id`, `total_price`, `payment`, `status`, `create_at`) VALUES @@ -219,12 +220,13 @@ INSERT INTO `order` (`id`, `user_id`, `total_price`, `payment`, `status`, `creat (30, 1, 280000, 'COD', 'canceled', '2023-11-16 08:00:00'), (32, 1, 550000, 'MoMo', 'shipping', '2023-11-17 15:39:31'), (33, 1, 600000, 'COD', 'done', '2023-11-18 15:51:43'), -(34, 1, 370000, 'MoMo', 'shipping', '2023-11-22 15:53:02'); +(34, 1, 370000, 'MoMo', 'shipping', '2023-11-22 15:53:02'), +(35, 1, 460000, 'COD', 'done', '2023-11-27 09:34:21'); -- -------------------------------------------------------- -- --- Table structure for table `product` +-- Cấu trúc bảng cho bảng `product` -- CREATE TABLE `product` ( @@ -238,7 +240,7 @@ CREATE TABLE `product` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- --- Dumping data for table `product` +-- Đang đổ dữ liệu cho bảng `product` -- INSERT INTO `product` (`id`, `category_id`, `name`, `banners`, `thumb`, `price`, `detail`) VALUES @@ -288,7 +290,7 @@ INSERT INTO `product` (`id`, `category_id`, `name`, `banners`, `thumb`, `price`, -- -------------------------------------------------------- -- --- Table structure for table `user` +-- Cấu trúc bảng cho bảng `user` -- CREATE TABLE `user` ( @@ -306,7 +308,7 @@ CREATE TABLE `user` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- --- Dumping data for table `user` +-- Đang đổ dữ liệu cho bảng `user` -- INSERT INTO `user` (`id`, `full_name`, `year_of_birth`, `gender`, `email`, `password`, `address`, `phone_number`, `status`, `create_at`, `delete_at`) VALUES @@ -340,52 +342,52 @@ INSERT INTO `user` (`id`, `full_name`, `year_of_birth`, `gender`, `email`, `pass (28, 'Vũ Văn Dũng', 2000, 'male', 'Dungvv@gmail.com', '5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5', '57A Nguyễn Huệ, tp.Quy Nhơn, Bình Định', '02567308668', 'activate', '2023-11-07 11:20:01', NULL), (29, 'Phạm Đức Nghĩa', 2003, 'male', 'Nghiapd@gmail.com', '5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5', '114B 31 tháng 3, tp.Quy Nhơn, Bình Định', '02567308668', 'activate', '2023-10-05 11:21:26', NULL), (30, 'Lê Uyển Nhi', 2001, 'female', 'Nhilu@gmail.com', '5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5', 'Lô 01 Ngọc Hồi, huyện Tây Sơn, Bình Định', '02567308668', 'activate', '2023-10-01 11:21:26', NULL), -(43, 'Le Quoc C', 2000, 'male', 'abcd@gmail.com', '5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5', '5/20/17 Hoàng Hoa Thám, TP.Quy Nhơn', '0363475716', 'activate', '2023-11-23 20:47:39', NULL); +(49, 'Nguyễn Văn A', 2000, 'male', 'fafa', 'a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3', '5/20/17 Hoàng Hoa Thám, TP.Quy Nhơn', '0363475716', 'activate', '2023-11-28 20:15:47', NULL); -- --- Indexes for dumped tables +-- Chỉ mục cho các bảng đã đổ -- -- --- Indexes for table `admin` +-- Chỉ mục cho bảng `admin` -- ALTER TABLE `admin` ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `username` (`username`); -- --- Indexes for table `cart` +-- Chỉ mục cho bảng `cart` -- ALTER TABLE `cart` ADD PRIMARY KEY (`user_id`,`product_id`); -- --- Indexes for table `categories` +-- Chỉ mục cho bảng `categories` -- ALTER TABLE `categories` ADD PRIMARY KEY (`id`); -- --- Indexes for table `data_order` +-- Chỉ mục cho bảng `data_order` -- ALTER TABLE `data_order` ADD PRIMARY KEY (`order_id`,`product_id`); -- --- Indexes for table `order` +-- Chỉ mục cho bảng `order` -- ALTER TABLE `order` ADD PRIMARY KEY (`id`), ADD KEY `user_id` (`user_id`); -- --- Indexes for table `product` +-- Chỉ mục cho bảng `product` -- ALTER TABLE `product` ADD PRIMARY KEY (`id`); -- --- Indexes for table `user` +-- Chỉ mục cho bảng `user` -- ALTER TABLE `user` ADD PRIMARY KEY (`id`), @@ -393,51 +395,51 @@ ALTER TABLE `user` ADD UNIQUE KEY `email_2` (`email`); -- --- AUTO_INCREMENT for dumped tables +-- AUTO_INCREMENT cho các bảng đã đổ -- -- --- AUTO_INCREMENT for table `admin` +-- AUTO_INCREMENT cho bảng `admin` -- ALTER TABLE `admin` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6; -- --- AUTO_INCREMENT for table `categories` +-- AUTO_INCREMENT cho bảng `categories` -- ALTER TABLE `categories` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; -- --- AUTO_INCREMENT for table `order` +-- AUTO_INCREMENT cho bảng `order` -- ALTER TABLE `order` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=35; + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=36; -- --- AUTO_INCREMENT for table `product` +-- AUTO_INCREMENT cho bảng `product` -- ALTER TABLE `product` MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=45; -- --- AUTO_INCREMENT for table `user` +-- AUTO_INCREMENT cho bảng `user` -- ALTER TABLE `user` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=44; + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=50; -- --- Constraints for dumped tables +-- Các ràng buộc cho các bảng đã đổ -- -- --- Constraints for table `data_order` +-- Các ràng buộc cho bảng `data_order` -- ALTER TABLE `data_order` ADD CONSTRAINT `data_order_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `order` (`id`); -- --- Constraints for table `order` +-- Các ràng buộc cho bảng `order` -- ALTER TABLE `order` ADD CONSTRAINT `order_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); @@ -445,4 +447,4 @@ COMMIT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; \ No newline at end of file +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/src/main/java/com/bakaqc/flower/controller/AdminAccountController.java b/src/main/java/com/bakaqc/flower/controller/AdminAccountController.java index 9ed4f03..05496af 100644 --- a/src/main/java/com/bakaqc/flower/controller/AdminAccountController.java +++ b/src/main/java/com/bakaqc/flower/controller/AdminAccountController.java @@ -1,46 +1,45 @@ -/* - * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license - * Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template - */ - package com.bakaqc.flower.controller; import com.bakaqc.flower.dao.UserDAO; import com.bakaqc.flower.model.User; import java.io.IOException; -import java.io.PrintWriter; import java.util.List; +import java.util.stream.Collectors; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - public class AdminAccountController extends HttpServlet { - - - @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + throws ServletException, IOException { + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); String error = request.getParameter("error"); - if(error != null){ + String status = request.getParameter("status"); + if (error != null) { request.setAttribute("error", error); } UserDAO userDAO = new UserDAO(); List users = userDAO.selectAll(); + if (status != null && !status.equals("0")) { + request.setAttribute("status", status); + String statusCode = status.equals("1") ? "activate" : "deactivate"; + users = users.stream().filter((t) -> t.getStatus().toString().equals(statusCode)).collect(Collectors.toList()); + } request.setAttribute("users", users); request.getSession().setAttribute("isActive", 1); request.getRequestDispatcher("/view/AccountAdmin.jsp").forward(request, response); - } + } - @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - + throws ServletException, IOException { + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); + } - -} \ No newline at end of file +} diff --git a/src/main/java/com/bakaqc/flower/controller/AdminController.java b/src/main/java/com/bakaqc/flower/controller/AdminController.java index 49fa16a..71dd51f 100644 --- a/src/main/java/com/bakaqc/flower/controller/AdminController.java +++ b/src/main/java/com/bakaqc/flower/controller/AdminController.java @@ -35,6 +35,8 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); } } diff --git a/src/main/java/com/bakaqc/flower/controller/AdminDeleteController.java b/src/main/java/com/bakaqc/flower/controller/AdminDeleteController.java new file mode 100644 index 0000000..dad1115 --- /dev/null +++ b/src/main/java/com/bakaqc/flower/controller/AdminDeleteController.java @@ -0,0 +1,44 @@ +package com.bakaqc.flower.controller; + +import com.bakaqc.flower.dao.AdminDAO; +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class AdminDeleteController extends HttpServlet { + + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + String id = request.getParameter("id"); + AdminDAO adminDAO = new AdminDAO(); + adminDAO.delete(id); + } + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); + } + + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/src/main/java/com/bakaqc/flower/controller/AdminListController.java b/src/main/java/com/bakaqc/flower/controller/AdminListController.java new file mode 100644 index 0000000..f93d5b4 --- /dev/null +++ b/src/main/java/com/bakaqc/flower/controller/AdminListController.java @@ -0,0 +1,48 @@ +package com.bakaqc.flower.controller; + +import com.bakaqc.flower.dao.AdminDAO; +import com.bakaqc.flower.model.Admin; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class AdminListController extends HttpServlet { + + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + AdminDAO adminDAO = new AdminDAO(); + List list = adminDAO.selectAll(); + request.setAttribute("list", list); + request.getSession().setAttribute("isActive", 3); + request.getRequestDispatcher("/view/manageAdmin.jsp").forward(request, response); + } + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); + } + + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/src/main/java/com/bakaqc/flower/controller/AdminLoginController.java b/src/main/java/com/bakaqc/flower/controller/AdminLoginController.java index c3c3e80..1526f92 100644 --- a/src/main/java/com/bakaqc/flower/controller/AdminLoginController.java +++ b/src/main/java/com/bakaqc/flower/controller/AdminLoginController.java @@ -30,12 +30,10 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) String password = request.getParameter("password"); Admin ad = AdminDAO.getInstance().selectByUserName(username); - if (ad != null && ad.getPassword().equals(Hash.hashCode(password))) { HttpSession session = request.getSession(); session.setAttribute("user", ad); response.sendRedirect("admin"); - return; } diff --git a/src/main/java/com/bakaqc/flower/controller/AdminProductController.java b/src/main/java/com/bakaqc/flower/controller/AdminProductController.java index 335e5ad..11a1b2e 100644 --- a/src/main/java/com/bakaqc/flower/controller/AdminProductController.java +++ b/src/main/java/com/bakaqc/flower/controller/AdminProductController.java @@ -1,5 +1,3 @@ - - package com.bakaqc.flower.controller; import com.bakaqc.flower.dao.CategoriesDAO; @@ -14,16 +12,13 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - public class AdminProductController extends HttpServlet { - - - - @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + throws ServletException, IOException { + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); CategoriesDAO categoriesDAO = new CategoriesDAO(); List categorieses = categoriesDAO.selectAll(); ProductDAO productDAO = new ProductDAO(); @@ -32,15 +27,14 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) request.setAttribute("products", products); request.getSession().setAttribute("isActive", 2); request.getRequestDispatcher("/view/ProductAdmin.jsp").forward(request, response); - } + } - @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - - } + throws ServletException, IOException { + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); - + } -} \ No newline at end of file +} diff --git a/src/main/java/com/bakaqc/flower/controller/CreateAccountAdminController.java b/src/main/java/com/bakaqc/flower/controller/CreateAccountAdminController.java new file mode 100644 index 0000000..7cf9912 --- /dev/null +++ b/src/main/java/com/bakaqc/flower/controller/CreateAccountAdminController.java @@ -0,0 +1,54 @@ +package com.bakaqc.flower.controller; + +import com.bakaqc.flower.dao.AdminDAO; +import com.bakaqc.flower.model.Admin; +import com.bakaqc.flower.model.option.AdminRole; +import com.bakaqc.flower.service.Hash; +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class CreateAccountAdminController extends HttpServlet { + + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + String username = request.getParameter("username"); + String password = request.getParameter("password"); + Admin admin = new Admin(); + admin.setUserName(username); + admin.setPassword(Hash.hashCode(password)); + admin.setRole(AdminRole.create("Admin")); + AdminDAO adminDAO = new AdminDAO(); + adminDAO.insert(admin); + String url = request.getHeader("referer"); + response.sendRedirect(url); + } + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); + } + + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/src/main/java/com/bakaqc/flower/controller/CreateAccountController.java b/src/main/java/com/bakaqc/flower/controller/CreateAccountController.java index cbebb09..ca3d167 100644 --- a/src/main/java/com/bakaqc/flower/controller/CreateAccountController.java +++ b/src/main/java/com/bakaqc/flower/controller/CreateAccountController.java @@ -6,19 +6,19 @@ import com.bakaqc.flower.model.option.UserStatus; import java.io.IOException; import java.io.PrintWriter; +import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - public class CreateAccountController extends HttpServlet { - protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); - try ( PrintWriter out = response.getWriter()) { + try (PrintWriter out = response.getWriter()) { String fullname = request.getParameter("fullname"); String year = request.getParameter("year"); String email = request.getParameter("email"); @@ -26,40 +26,43 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re String status = request.getParameter("status"); String address = request.getParameter("address"); String password = request.getParameter("password"); + String phone = request.getParameter("phone"); String url = request.getHeader("referer"); if (UserDAO.getInstance().selectByEmail(email) != null) { request.setAttribute("error", "Email existed!"); - request.getRequestDispatcher(url).forward(request, response); + List users = UserDAO.getInstance().selectAll(); + request.setAttribute("users", users); + request.getRequestDispatcher("/view/AccountAdmin.jsp").forward(request, response); } else { User user = new User(); user.setPassword(password); user.setAddress(address); user.setEmail(email); user.setFullName(fullname); + user.setPhone_number(phone); user.setStatus(UserStatus.create(status)); user.setGender(UserGender.create(gender)); user.setYearOfBirth(Integer.parseInt(year)); - UserDAO.getInstance().insert(user); + UserDAO.getInstance().insert(user); response.sendRedirect(url); } } } - @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); } - @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); } - - - -} \ No newline at end of file +} diff --git a/src/main/java/com/bakaqc/flower/controller/CreateProductController.java b/src/main/java/com/bakaqc/flower/controller/CreateProductController.java index 63abe6c..02dc426 100644 --- a/src/main/java/com/bakaqc/flower/controller/CreateProductController.java +++ b/src/main/java/com/bakaqc/flower/controller/CreateProductController.java @@ -14,17 +14,16 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.Part; - @MultipartConfig(fileSizeThreshold = 1024 * 1024, maxFileSize = 1024 * 1024 * 10, maxRequestSize = 1024 * 1024 * 11) public class CreateProductController extends HttpServlet { - protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); - try ( PrintWriter out = response.getWriter()) { + try (PrintWriter out = response.getWriter()) { ProductDAO productDAO = new ProductDAO(); Product product = new Product(); String name = request.getParameter("name"); @@ -37,33 +36,33 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re product.setCategoryID(Integer.parseInt(categoryID)); product.setPrice(Integer.parseInt(price)); product.setDetail(detail); + product.setBanners(image); productDAO.insert(product); String url = request.getHeader("referer"); response.sendRedirect(url); } } - @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); } - @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); } - - - public String uploadFile(HttpServletRequest request) throws IOException, ServletException { String fileName = ""; int length = getServletContext().getRealPath("/").length(); - String uploadPath = new StringBuilder(getServletContext().getRealPath("/")).delete(length - 10, length - 4).toString() + File.separator + "img"; + String uploadPath = new StringBuilder(getServletContext().getRealPath("/")) + File.separator + "img"; File uploadDir = new File(uploadPath); if (!uploadDir.exists()) { uploadDir.mkdir(); @@ -91,4 +90,4 @@ private String getFileName(Part part) { return DEFAULT_FILENAME; } -} \ No newline at end of file +} diff --git a/src/main/java/com/bakaqc/flower/controller/DeleteAccountController.java b/src/main/java/com/bakaqc/flower/controller/DeleteAccountController.java index f77e34c..af07975 100644 --- a/src/main/java/com/bakaqc/flower/controller/DeleteAccountController.java +++ b/src/main/java/com/bakaqc/flower/controller/DeleteAccountController.java @@ -1,10 +1,7 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.bakaqc.flower.controller; + +import com.bakaqc.flower.dao.UserDAO; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; @@ -12,72 +9,33 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -/** - * - * @author vungo - */ public class DeleteAccountController extends HttpServlet { - /** - * Processes requests for both HTTP GET and POST - * methods. - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs - */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { - /* TODO output your page here. You may use following sample code. */ - out.println(""); - out.println(""); - out.println(""); - out.println("Servlet DeleteAccountController"); - out.println(""); - out.println(""); - out.println("

Servlet DeleteAccountController at " + request.getContextPath() + "

"); - out.println(""); - out.println(""); + String id = request.getParameter("id"); + UserDAO.getInstance().delete(id); } } - // - /** - * Handles the HTTP GET method. - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs - */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); } - /** - * Handles the HTTP POST method. - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs - */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); } - /** - * Returns a short description of the servlet. - * - * @return a String containing servlet description - */ @Override public String getServletInfo() { return "Short description"; diff --git a/src/main/java/com/bakaqc/flower/controller/DeleteProductController.java b/src/main/java/com/bakaqc/flower/controller/DeleteProductController.java index ad8a5fe..59c2aa5 100644 --- a/src/main/java/com/bakaqc/flower/controller/DeleteProductController.java +++ b/src/main/java/com/bakaqc/flower/controller/DeleteProductController.java @@ -8,34 +8,31 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - public class DeleteProductController extends HttpServlet { - protected void processRequest(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String id = request.getParameter("id"); - ProductDAO productDAO = new ProductDAO(); - productDAO.delete(id); + ProductDAO.getInstance().delete(id); } - } + } - @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + throws ServletException, IOException { processRequest(request, response); - } + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); + } - @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + throws ServletException, IOException { processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); } - - -} \ No newline at end of file +} diff --git a/src/main/java/com/bakaqc/flower/controller/UpdateAccountController.java b/src/main/java/com/bakaqc/flower/controller/UpdateAccountController.java index 26c8ee5..43c12af 100644 --- a/src/main/java/com/bakaqc/flower/controller/UpdateAccountController.java +++ b/src/main/java/com/bakaqc/flower/controller/UpdateAccountController.java @@ -6,6 +6,7 @@ import com.bakaqc.flower.model.option.UserStatus; import java.io.IOException; import java.io.PrintWriter; +import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -16,12 +17,16 @@ public class UpdateAccountController extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); String id = request.getParameter("id"); String fullname = request.getParameter("fullname"); String year = request.getParameter("year"); @@ -29,17 +34,21 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) String gender = request.getParameter("gender"); String status = request.getParameter("status"); String address = request.getParameter("address"); - String url = request.getHeader("referer"); - if (UserDAO.getInstance().selectByEmail(email) != null) { + User u = UserDAO.getInstance().selectByEmail(email); + if (u != null && u.getId() != Integer.parseInt(id)) { request.setAttribute("error", "Email existed!"); - request.getRequestDispatcher(url).forward(request, response); + List users = UserDAO.getInstance().selectAll(); + request.setAttribute("users", users); + request.getRequestDispatcher("/view/AccountAdmin.jsp").forward(request, response); } else { User user = new User(); + user.setPassword(u.getPassword()); user.setId(Integer.parseInt(id)); user.setAddress(address); user.setEmail(email); user.setFullName(fullname); + user.setPhone_number(u.getPhone_number()); user.setStatus(UserStatus.create(status)); user.setGender(UserGender.create(gender)); user.setYearOfBirth(Integer.parseInt(year)); diff --git a/src/main/java/com/bakaqc/flower/controller/UpdateProductController.java b/src/main/java/com/bakaqc/flower/controller/UpdateProductController.java index bb86e81..da11c47 100644 --- a/src/main/java/com/bakaqc/flower/controller/UpdateProductController.java +++ b/src/main/java/com/bakaqc/flower/controller/UpdateProductController.java @@ -32,11 +32,15 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); ProductDAO productDAO = new ProductDAO(); String id = request.getParameter("id"); Product product = productDAO.selectById(id).get(0); @@ -61,7 +65,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) public String uploadFile(HttpServletRequest request) throws IOException, ServletException { String fileName = ""; int length = getServletContext().getRealPath("/").length(); - String uploadPath = new StringBuilder(getServletContext().getRealPath("/")).delete(length - 10, length - 4).toString() + File.separator + "img"; + String uploadPath = new StringBuilder(getServletContext().getRealPath("/")).toString() + File.separator + "img"; File uploadDir = new File(uploadPath); if (!uploadDir.exists()) { uploadDir.mkdir(); diff --git a/src/main/java/com/bakaqc/flower/dao/ProductDAO.java b/src/main/java/com/bakaqc/flower/dao/ProductDAO.java index 0ee6030..9afcbbe 100644 --- a/src/main/java/com/bakaqc/flower/dao/ProductDAO.java +++ b/src/main/java/com/bakaqc/flower/dao/ProductDAO.java @@ -182,7 +182,7 @@ public void insert(Product ob) { smt.setInt(1, ob.getCategoryID()); smt.setString(2, ob.getName()); smt.setString(3, ob.getBanners()); - smt.setString(4, Convert.toJson(ob.getThumb())); + smt.setString(4, ob.getThumb() != null ? Convert.toJson(ob.getThumb()) : ""); smt.setInt(5, ob.getPrice()); smt.setString(6, ob.getDetail()); @@ -203,7 +203,7 @@ public void update(Product ob) { smt.setInt(1, ob.getCategoryID()); smt.setString(2, ob.getName()); smt.setString(3, ob.getBanners()); - smt.setString(4, Convert.toJson(ob.getThumb())); + smt.setString(4, ob.getThumb() != null ? Convert.toJson(ob.getThumb()) : ""); smt.setInt(5, ob.getPrice()); smt.setString(6, ob.getDetail()); smt.setInt(7, ob.getId()); diff --git a/src/main/java/com/bakaqc/flower/service/JDBC.java b/src/main/java/com/bakaqc/flower/service/JDBC.java index 1b0dc40..aa2016b 100644 --- a/src/main/java/com/bakaqc/flower/service/JDBC.java +++ b/src/main/java/com/bakaqc/flower/service/JDBC.java @@ -4,7 +4,7 @@ public class JDBC { - private static String DBURL = "jdbc:mysql://localhost:3333/flower_shop"; + private static String DBURL = "jdbc:mysql://localhost:3306/flower_shop"; private static String USERNAME = "root"; private static String PASSWORD = ""; diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 8f1a68e..0e8aec2 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -84,6 +84,18 @@ CreateProductController com.bakaqc.flower.controller.CreateProductController + + AdminListController + com.bakaqc.flower.controller.AdminListController + + + AdminDeleteController + com.bakaqc.flower.controller.AdminDeleteController + + + CreateAccountAdminController + com.bakaqc.flower.controller.CreateAccountAdminController + HomeController /home @@ -160,6 +172,18 @@ CreateProductController /admin/create-product + + AdminListController + /admin/list-admin + + + AdminDeleteController + /admin/deleteAdmin + + + CreateAccountAdminController + /admin/createAccountAdmin + 15 diff --git a/src/main/webapp/view/AccountAdmin.jsp b/src/main/webapp/view/AccountAdmin.jsp index 0464e31..1b014c6 100644 --- a/src/main/webapp/view/AccountAdmin.jsp +++ b/src/main/webapp/view/AccountAdmin.jsp @@ -6,7 +6,7 @@ Quản trị Admin - + @@ -20,7 +20,6 @@ - @@ -36,14 +35,20 @@
-
- + +
+ +
@@ -56,30 +61,29 @@ - - + + + - + - - - +
- +
@@ -129,13 +133,13 @@
- +
- + @@ -160,7 +164,7 @@
-
Giới tính Email Trạng TháiTính năng
Tính năng
#${item.id}#${item.id} ${item.getFullName()} ${item.getAddress()} ${item.getYearOfBirth()} ${item.gender.toString() == 'male' ? 'Nam' : 'Nữ'} ${item.email} ${item.status.toString() == 'activate' ? 'Hoạt Động' : 'Không Hoạt Động'} - - - + + +
+ + + + + + + + + + + + + + + + + + + +
ID Khách HàngUsernameTính năng
#${item.id}${item.getUserName()} + +
+
+
+
+
+ + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/view/navbaradmin.jsp b/src/main/webapp/view/navbaradmin.jsp index 136d35b..7e4ce91 100644 --- a/src/main/webapp/view/navbaradmin.jsp +++ b/src/main/webapp/view/navbaradmin.jsp @@ -1,15 +1,16 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@page contentType="text/html" pageEncoding="UTF-8"%>
Đăng xuất + aria-label="Hide Sidebar"> @@ -17,12 +18,12 @@