Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
Merge branch 'anh-fix-admin' of https://github.com/bakaqc/flower into…
Browse files Browse the repository at this point in the history
… anh-fix-admin
  • Loading branch information
Anhvnqe170052 committed Dec 8, 2023
2 parents ae3d712 + 68f7bd1 commit 60d52a5
Show file tree
Hide file tree
Showing 54 changed files with 1,615 additions and 775 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
List<Categories> listCAT = CategoriesDAO.getInstance().selectAll();

request.setAttribute("listCAT", listCAT);

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.bakaqc.flower.controller;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;

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

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

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

addItem(request, pid, amount);

response.sendRedirect("cart");
}

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

public void addItem(HttpServletRequest request, int pid, int amount) {
HttpSession session = request.getSession();
Map<Integer, Integer> cart = (Map<Integer, Integer>) session.getAttribute("cart");

if (cart == null) {
return;
}

if (cart.containsKey(pid)) {
cart.put(pid, cart.get(pid) + amount);
} else {
cart.put(pid, amount);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class AdminDeleteController extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
String id = request.getParameter("id");
AdminDAO adminDAO = new AdminDAO();
Expand All @@ -35,10 +36,4 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class AdminListController extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
AdminDAO adminDAO = new AdminDAO();
List<Admin> list = adminDAO.selectAll();
Expand All @@ -39,10 +40,4 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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.*;
import javax.servlet.*;
Expand Down Expand Up @@ -37,13 +36,15 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
return;
}

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

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

request.setAttribute("errorUSN", errorUSN);
this.doGet(request, response);
}

String errorMsg = "Sai mật khẩu!";
request.setAttribute("username", username);
request.setAttribute("errorMsg", errorMsg);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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;
Expand All @@ -32,9 +31,6 @@ 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");

}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.bakaqc.flower.controller;

import com.bakaqc.flower.dao.CategoriesDAO;
import com.bakaqc.flower.dao.UserDAO;
import com.bakaqc.flower.model.Categories;
import com.bakaqc.flower.model.User;
import com.bakaqc.flower.service.Hash;
import java.io.*;
import java.util.List;
import javax.servlet.*;
import javax.servlet.http.*;

Expand All @@ -14,7 +17,9 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
List<Categories> listCAT = CategoriesDAO.getInstance().selectAll();

request.setAttribute("listCAT", listCAT);
request.getRequestDispatcher("/view/user_change_pass.jsp").forward(request, response);
}

Expand All @@ -23,26 +28,44 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

String oldPassword = Hash.hashCode(request.getParameter("oldPassword"));
String newPassword = Hash.hashCode(request.getParameter("newPassword"));
String conPassword = Hash.hashCode(request.getParameter("conPassword"));
String oldPass = request.getParameter("oldPassword");
String newPass = request.getParameter("newPassword");
String conPass = request.getParameter("conPassword");
String oldPassword = Hash.hashCode(oldPass);
String newPassword = Hash.hashCode(newPass);
String conPassword = Hash.hashCode(conPass);

HttpSession session = request.getSession();
User us = (User) session.getAttribute("user");
if (oldPassword.equals(us.getPassword())) {
if (conPassword.equals(newPassword)) {
UserDAO.getInstance().changePass(us.getId(), newPassword);
if (newPass.length() < 6) {
String errGotPass = "Mật khẩu mới phải nhập tối thiểu 6 ký tự!";
request.setAttribute("errGotPass", errGotPass);

// String success = "Đổi mật khẩu thành công.";
// request.setAttribute("success", success);
response.sendRedirect("../profile");

this.doGet(request, response);
} else {
String errConfPass = "Xác nhận Mật khẩu mới không đúng!";
request.setAttribute("errConfPass", errConfPass);
if (newPassword.equals(oldPassword)) {
String errOldPass = "Mật khẩu mới trùng với mật khẩu cũ!";
request.setAttribute("errOldPass", errOldPass);

this.doGet(request, response);
} else {
if (conPassword.equals(newPassword)) {
UserDAO.getInstance().changePass(us.getId(), newPassword);

// String success = "Đổi mật khẩu thành công.";
// request.setAttribute("success", success);
// request.getRequestDispatcher("/view/user_profile.jsp").forward(request, response);
response.sendRedirect("profile");

} else {
String errConfPass = "Xác nhận Mật khẩu mới không đúng!";
request.setAttribute("errConfPass", errConfPass);

this.doGet(request, response);
}
}

this.doGet(request, response);
}
} else {
String errPass = "Mật khẩu không đúng!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ public class CreateAccountAdminController extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
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.getInstance().insert(admin);
String url = request.getHeader("referer");
response.sendRedirect(url);

}
}

Expand All @@ -44,6 +47,6 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
}


}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bakaqc.flower.controller;


import com.bakaqc.flower.dao.UserDAO;
import java.io.IOException;
import java.io.PrintWriter;
Expand All @@ -13,7 +12,8 @@ public class DeleteAccountController extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
String id = request.getParameter("id");
UserDAO.getInstance().delete(id);
Expand All @@ -35,10 +35,4 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class DeleteProductController extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
String id = request.getParameter("id");
ProductDAO.getInstance().delete(id);
Expand Down
Loading

0 comments on commit 60d52a5

Please sign in to comment.