This repository has been archived by the owner on May 11, 2024. 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.
Merge pull request #10 from bakaqc/fix-admin
Fix admin
- Loading branch information
Showing
36 changed files
with
20,985 additions
and
13 deletions.
There are no files selected for viewing
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
46 changes: 46 additions & 0 deletions
46
src/main/java/com/bakaqc/flower/controller/AdminAccountController.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,46 @@ | ||
/* | ||
* 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 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 { | ||
String error = request.getParameter("error"); | ||
if(error != null){ | ||
request.setAttribute("error", error); | ||
} | ||
UserDAO userDAO = new UserDAO(); | ||
List<User> users = userDAO.selectAll(); | ||
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 { | ||
|
||
} | ||
|
||
|
||
} |
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
46 changes: 46 additions & 0 deletions
46
src/main/java/com/bakaqc/flower/controller/AdminProductController.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,46 @@ | ||
|
||
|
||
package com.bakaqc.flower.controller; | ||
|
||
import com.bakaqc.flower.dao.CategoriesDAO; | ||
import com.bakaqc.flower.dao.ProductDAO; | ||
import com.bakaqc.flower.model.Categories; | ||
import com.bakaqc.flower.model.Product; | ||
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 AdminProductController extends HttpServlet { | ||
|
||
|
||
|
||
|
||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
CategoriesDAO categoriesDAO = new CategoriesDAO(); | ||
List<Categories> categorieses = categoriesDAO.selectAll(); | ||
ProductDAO productDAO = new ProductDAO(); | ||
List<Product> products = productDAO.selectAll(); | ||
request.setAttribute("categories", categorieses); | ||
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 { | ||
|
||
} | ||
|
||
|
||
|
||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/com/bakaqc/flower/controller/CreateAccountController.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,65 @@ | ||
package com.bakaqc.flower.controller; | ||
|
||
import com.bakaqc.flower.dao.UserDAO; | ||
import com.bakaqc.flower.model.User; | ||
import com.bakaqc.flower.model.option.UserGender; | ||
import com.bakaqc.flower.model.option.UserStatus; | ||
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 CreateAccountController 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 fullname = request.getParameter("fullname"); | ||
String year = request.getParameter("year"); | ||
String email = request.getParameter("email"); | ||
String gender = request.getParameter("gender"); | ||
String status = request.getParameter("status"); | ||
String address = request.getParameter("address"); | ||
String password = request.getParameter("password"); | ||
String url = request.getHeader("referer"); | ||
if (UserDAO.getInstance().selectByEmail(email) != null) { | ||
request.setAttribute("error", "Email existed!"); | ||
request.getRequestDispatcher(url).forward(request, response); | ||
} else { | ||
User user = new User(); | ||
user.setPassword(password); | ||
user.setAddress(address); | ||
user.setEmail(email); | ||
user.setFullName(fullname); | ||
user.setStatus(UserStatus.create(status)); | ||
user.setGender(UserGender.create(gender)); | ||
user.setYearOfBirth(Integer.parseInt(year)); | ||
UserDAO.getInstance().insert(user); | ||
response.sendRedirect(url); | ||
} | ||
} | ||
} | ||
|
||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
processRequest(request, response); | ||
} | ||
|
||
|
||
@Override | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
processRequest(request, response); | ||
} | ||
|
||
|
||
|
||
|
||
} |
94 changes: 94 additions & 0 deletions
94
src/main/java/com/bakaqc/flower/controller/CreateProductController.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,94 @@ | ||
package com.bakaqc.flower.controller; | ||
|
||
import static com.bakaqc.flower.controller.UpdateProductController.DEFAULT_FILENAME; | ||
import com.bakaqc.flower.dao.ProductDAO; | ||
import com.bakaqc.flower.model.Product; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.MultipartConfig; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
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 { | ||
response.setContentType("text/html;charset=UTF-8"); | ||
try ( PrintWriter out = response.getWriter()) { | ||
ProductDAO productDAO = new ProductDAO(); | ||
Product product = new Product(); | ||
String name = request.getParameter("name"); | ||
String categoryID = request.getParameter("category"); | ||
String price = request.getParameter("price"); | ||
String image = uploadFile(request); | ||
String detail = request.getParameter("detail"); | ||
product.setName(name); | ||
product.setCategoryId(Integer.parseInt(categoryID)); | ||
product.setCategoryID(Integer.parseInt(categoryID)); | ||
product.setPrice(Integer.parseInt(price)); | ||
product.setDetail(detail); | ||
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); | ||
} | ||
|
||
|
||
@Override | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
processRequest(request, 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"; | ||
File uploadDir = new File(uploadPath); | ||
if (!uploadDir.exists()) { | ||
uploadDir.mkdir(); | ||
} | ||
try { | ||
for (Part part : request.getParts()) { | ||
String temp = getFileName(part); | ||
if (!temp.equals(DEFAULT_FILENAME) && !temp.trim().isEmpty()) { | ||
fileName = temp; | ||
part.write(uploadPath + File.separator + fileName); | ||
break; | ||
} | ||
} | ||
} catch (FileNotFoundException fne) { | ||
} | ||
return fileName; | ||
} | ||
|
||
private String getFileName(Part part) { | ||
for (String content : part.getHeader("content-disposition").split(";")) { | ||
if (content.trim().startsWith("filename")) { | ||
return content.substring(content.indexOf("=") + 2, content.length() - 1); | ||
} | ||
} | ||
return DEFAULT_FILENAME; | ||
} | ||
|
||
} |
86 changes: 86 additions & 0 deletions
86
src/main/java/com/bakaqc/flower/controller/DeleteAccountController.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,86 @@ | ||
/* | ||
* 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 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; | ||
|
||
/** | ||
* | ||
* @author vungo | ||
*/ | ||
public class DeleteAccountController extends HttpServlet { | ||
|
||
/** | ||
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> | ||
* 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("<!DOCTYPE html>"); | ||
out.println("<html>"); | ||
out.println("<head>"); | ||
out.println("<title>Servlet DeleteAccountController</title>"); | ||
out.println("</head>"); | ||
out.println("<body>"); | ||
out.println("<h1>Servlet DeleteAccountController at " + request.getContextPath() + "</h1>"); | ||
out.println("</body>"); | ||
out.println("</html>"); | ||
} | ||
} | ||
|
||
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> | ||
/** | ||
* Handles the HTTP <code>GET</code> 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); | ||
} | ||
|
||
/** | ||
* Handles the HTTP <code>POST</code> 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); | ||
} | ||
|
||
/** | ||
* Returns a short description of the servlet. | ||
* | ||
* @return a String containing servlet description | ||
*/ | ||
@Override | ||
public String getServletInfo() { | ||
return "Short description"; | ||
}// </editor-fold> | ||
|
||
} |
Oops, something went wrong.