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 #78 from hardingadonis/hoang_admin_dashboard
Browse files Browse the repository at this point in the history
Hoang admin dashboard
  • Loading branch information
yuhtnguyen authored Dec 7, 2023
2 parents 32c09bb + 0f3bd82 commit 3466747
Show file tree
Hide file tree
Showing 32 changed files with 13,592 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.hardingadonis.miu.controller.admin;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "AdminServlet", urlPatterns = {"/admin"})
public class AdminServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

request.getRequestDispatcher("/view/admin/admin.jsp").forward(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}


@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.hardingadonis.miu.controller.admin;

import io.hardingadonis.miu.dao.impl.mysql.CategoryDAOMySQLImpl;
import io.hardingadonis.miu.model.Category;
import io.hardingadonis.miu.services.Singleton;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

@WebServlet(name = "ListCategoryServlet", urlPatterns = {"/listCategory"})
@MultipartConfig
public class ListCategoryServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

request.getRequestDispatcher("/view/admin/list_category.jsp").forward(request, response);

}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

package io.hardingadonis.miu.controller.admin;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "ListOrderServlet", urlPatterns = {"/listOrder"})
public class ListOrderServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

request.getRequestDispatcher("/view/admin/list_order.jsp").forward(request, response);
}


@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}


@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.hardingadonis.miu.controller.admin;

import io.hardingadonis.miu.services.Singleton;
import java.io.IOException;
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 org.json.simple.JSONObject;

@WebServlet(name = "ListUserServlet", urlPatterns = {"/listUser"})
public class ListUserServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

request.getRequestDispatcher("/view/admin/list_user.jsp").forward(request, response);
}

@Override
protected void doDelete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
int ID = Integer.parseInt(request.getParameter("id"));

Singleton.userDAO.delete(ID);

JSONObject jsonResponse = new JSONObject();
jsonResponse.put("status", "success");
jsonResponse.put("message", "User canceled successfully");

response.setContentType("application/json");
response.getWriter().write(jsonResponse.toString());

response.setStatus(HttpServletResponse.SC_OK);

} catch (NumberFormatException ex) {
System.err.println(ex.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.hardingadonis.miu.controller.admin;

import io.hardingadonis.miu.model.Admin;
import io.hardingadonis.miu.services.Hash;
import io.hardingadonis.miu.services.Singleton;
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

@WebServlet(name = "LoginAdmin", urlPatterns = {"/admin/login"})
public class LoginAdmin extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
request.getRequestDispatcher("/view/admin/login-admin.jsp").forward(request, response);

}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

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

Admin ad = Singleton.adminDAO.get(username);

if (ad != null && ad.getHashedPassword().equals(Hash.SHA256(password))) {
HttpSession session = request.getSession();
session.setAttribute("admin", ad);
response.sendRedirect(request.getContextPath() + "/admin");
return;
}

String errorMsg = "Sai mật khẩu!";

if (ad == null) {
errorMsg = "Tài khoản không tồn tại!";
username = null;
}

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

this.doGet(request, response);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.hardingadonis.miu.controller.admin;

import io.hardingadonis.miu.services.Singleton;
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import org.json.simple.JSONObject;

@WebServlet(name = "ProductManagement", urlPatterns = {"/productmanagement"})
public class ProductManagement extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

request.getRequestDispatcher("/view/admin/product-management.jsp").forward(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Handle form submission here
}

@Override
protected void doDelete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
int ID = Integer.parseInt(request.getParameter("id"));

Singleton.productDAO.delete(ID);

JSONObject jsonResponse = new JSONObject();
jsonResponse.put("status", "success");
jsonResponse.put("message", "User canceled successfully");

response.setContentType("application/json");
response.getWriter().write(jsonResponse.toString());

response.setStatus(HttpServletResponse.SC_OK);

} catch (NumberFormatException ex) {
System.err.println(ex.getMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public DBContextMySQLImpl() {
Properties prop = new Properties();

if (input == null) {
this.dbURL = "jdbc:mysql://localhost:3306/r7";
this.dbURL = "jdbc:mysql://localhost:3306/miu";
this.user = "root";
this.password = "";
} else {
Expand Down
32 changes: 32 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@
<filter-name>DefaultFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>ListUserServlet</servlet-name>
<servlet-class>io.hardingadonis.miu.controller.admin.ListUserServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>ListOrderServlet</servlet-name>
<servlet-class>io.hardingadonis.miu.controller.admin.ListOrderServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>ListCategoryServlet</servlet-name>
<servlet-class>io.hardingadonis.miu.controller.admin.ListCategoryServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>AdminServlet</servlet-name>
<servlet-class>io.hardingadonis.miu.controller.admin.AdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ListUserServlet</servlet-name>
<url-pattern>/listUser</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ListOrderServlet</servlet-name>
<url-pattern>/listOrder</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AdminServlet</servlet-name>
<url-pattern>/admin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ListCategoryServlet</servlet-name>
<url-pattern>/listCategory</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
15
Expand Down
Empty file.
Loading

0 comments on commit 3466747

Please sign in to comment.