diff --git a/src/java/controller/admin/dashboard/DashboardController.java b/src/java/controller/admin/dashboard/DashboardController.java index ee5f933..24a65e3 100644 --- a/src/java/controller/admin/dashboard/DashboardController.java +++ b/src/java/controller/admin/dashboard/DashboardController.java @@ -52,7 +52,7 @@ protected void processGet(HttpServletRequest request, HttpServletResponse respon HttpSession session = request.getSession(); User user = (User) session.getAttribute("admin"); - ArrayList calendars = calendarDB.listByUser(user.getId()); + ArrayList calendars = calendarDB.list(); ArrayList listCategory = categoryDB.list(); ArrayList events = eventDB.list(); ArrayList users = userDB.list(); diff --git "a/src/java/controller/auth/ChangePassworControll\341\272\273.java" b/src/java/controller/auth/ChangePassworController.java similarity index 95% rename from "src/java/controller/auth/ChangePassworControll\341\272\273.java" rename to src/java/controller/auth/ChangePassworController.java index 3c35df8..2fac0aa 100644 --- "a/src/java/controller/auth/ChangePassworControll\341\272\273.java" +++ b/src/java/controller/auth/ChangePassworController.java @@ -21,7 +21,7 @@ * * @author giaki */ -public class ChangePassworControllẻ extends HttpServlet { +public class ChangePassworController extends HttpServlet { private final Validate validate = new Validate(); @@ -56,7 +56,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) } } else { - request.setAttribute("error", "Username or olđ password wrong!"); + request.setAttribute("error", "Username or old password wrong!"); request.getRequestDispatcher("/views/auth/change.jsp").forward(request, response); } } catch (Exception e) { diff --git a/src/java/dal/auth/PermissionDBContext.java b/src/java/dal/auth/PermissionDBContext.java index b1864f1..61d2d63 100644 --- a/src/java/dal/auth/PermissionDBContext.java +++ b/src/java/dal/auth/PermissionDBContext.java @@ -25,7 +25,7 @@ public Permission findOne(String name) { String sql = "SELECT [id]\n" + " ,[name]\n" + " FROM [permission]\n" - + " WHERE name = ?"; + + " WHERE LOWER(name) = LOWER(?)"; PreparedStatement statement = null; try { statement = connection.prepareStatement(sql); diff --git a/src/java/dal/auth/UserDBContext.java b/src/java/dal/auth/UserDBContext.java index 8047b74..39bc9b3 100644 --- a/src/java/dal/auth/UserDBContext.java +++ b/src/java/dal/auth/UserDBContext.java @@ -6,6 +6,9 @@ package dal.auth; import dal.DBContext; +import dal.calendar.AdditionalCalendarDBContext; +import dal.calendar.CalendarDBContext; +import dal.calendar.EventCalendarDBContext; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -15,6 +18,9 @@ import model.auth.Permission; import model.auth.User; import model.auth.UserPermission; +import model.calendar.AdditionalCalendar; +import model.calendar.Calendar; +import model.calendar.EventCalendar; /** * @@ -495,7 +501,6 @@ public User getUser(int id) { @Override public User insert(User user) { PreparedStatement statement = null; - UserPermissionDBContext userPermissionDB = new UserPermissionDBContext(); try { String sql = "INSERT INTO [user]\n" + " ([username]\n" @@ -530,12 +535,15 @@ public User insert(User user) { ResultSet rs = statement.getGeneratedKeys(); if (rs.next()) { int id = rs.getInt(1); - User new_user = getUser(id); + user.setId(id); + UserPermissionDBContext userPermissionDB = new UserPermissionDBContext(); UserPermission userPermission = new UserPermission(); - userPermission.setUserId(new_user.getId()); + userPermission.setUserId(id); userPermission.setPermissionId(user.getUser_permission().getId()); - userPermissionDB.insert(userPermission); - return new_user; + userPermission = userPermissionDB.insert(userPermission); + System.out.println(user.getUsername()); + System.out.println(userPermission.getId()); + return user; } } catch (SQLException ex) { Logger.getLogger(UserDBContext.class.getName()).log(Level.SEVERE, null, ex); @@ -723,7 +731,19 @@ public void updateAvatar(User user) { @Override public void delete(int id) { UserPermissionDBContext userPermissionDB = new UserPermissionDBContext(); + CalendarDBContext calendarDB = new CalendarDBContext(); + EventCalendarDBContext eventDB = new EventCalendarDBContext(); + AdditionalCalendarDBContext additionalDB = new AdditionalCalendarDBContext(); try { + ArrayList calendars = calendarDB.listByUser(id); + for (Calendar calendar : calendars) { + ArrayList additionals = additionalDB.findMany("calendarId", calendar.getId() + ""); + for (AdditionalCalendar additional : additionals) { + eventDB.deleteByAdditional(additional.getId()); + additionalDB.delete(additional.getId()); + } + } + calendarDB.deleteByUser(id); userPermissionDB.deleteByUser(id); String sql = "DELETE FROM [user]\n" + "WHERE id = ? "; diff --git a/src/java/dal/auth/UserPermissionDBContext.java b/src/java/dal/auth/UserPermissionDBContext.java index 889f769..6bf5241 100644 --- a/src/java/dal/auth/UserPermissionDBContext.java +++ b/src/java/dal/auth/UserPermissionDBContext.java @@ -50,7 +50,29 @@ public ArrayList list() { @Override public UserPermission get(int id) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + String sql = "SELECT [id]\n" + + ",[licensed]\n" + + ",[userId]\n" + + ",[permissionId]\n" + + " FROM [user_permission]\n" + + " WHERE id = ?"; + PreparedStatement statement = null; + try { + statement = connection.prepareStatement(sql); + statement.setInt(1, id); + ResultSet result = statement.executeQuery(); + while (result.next()) { + UserPermission userPermission = new UserPermission(); + userPermission.setId(result.getInt("id")); + userPermission.setLicensed(result.getBoolean("licensed")); + userPermission.setUserId(result.getInt("userId")); + userPermission.setPermissionId(result.getInt("permissionId")); + return userPermission; + } + } catch (SQLException ex) { + ex.printStackTrace(); + } + return null; } @Override diff --git a/src/java/dal/calendar/CalendarDBContext.java b/src/java/dal/calendar/CalendarDBContext.java index 293bb8f..4610dd5 100644 --- a/src/java/dal/calendar/CalendarDBContext.java +++ b/src/java/dal/calendar/CalendarDBContext.java @@ -341,6 +341,19 @@ public void delete(int id) { } } + + public void deleteByUser(int id) { + try { + String sql = "DELETE FROM [calendar]\n" + + "WHERE [userId] = ? "; + PreparedStatement statement = connection.prepareStatement(sql); + statement.setInt(1, id); + statement.executeUpdate(); + } catch (SQLException ex) { + Logger.getLogger(AdditionalCalendarDBContext.class.getName()).log(Level.SEVERE, null, ex); + } + } + public int getSize() { String sql = "SELECT COUNT([calendar].[id]) as 'size' FROM [calendar]"; PreparedStatement statement = null; diff --git a/src/java/dal/calendar/EventCalendarDBContext.java b/src/java/dal/calendar/EventCalendarDBContext.java index b9a9ee5..5970e68 100644 --- a/src/java/dal/calendar/EventCalendarDBContext.java +++ b/src/java/dal/calendar/EventCalendarDBContext.java @@ -536,6 +536,18 @@ public void delete(int id) { Logger.getLogger(EventCalendarDBContext.class.getName()).log(Level.SEVERE, null, ex); } } + + public void deleteByUser(int id) { + try { + String sql = "DELETE FROM [event]\n" + + "WHERE [userId] = ? "; + PreparedStatement statement = connection.prepareStatement(sql); + statement.setInt(1, id); + statement.executeUpdate(); + } catch (SQLException ex) { + Logger.getLogger(EventCalendarDBContext.class.getName()).log(Level.SEVERE, null, ex); + } + } public int getSize() { String sql = "SELECT COUNT([event].[id]) as 'size' FROM [event]"; diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml index b6e84ef..a99827c 100644 --- a/web/WEB-INF/web.xml +++ b/web/WEB-INF/web.xml @@ -184,7 +184,7 @@ ChangePassworControllẻ - controller.auth.ChangePassworControllẻ + controller.auth.ChangePassworController ErrorHandler diff --git a/web/views/auth/signup.jsp b/web/views/auth/signup.jsp index 2009807..5d17ee1 100644 --- a/web/views/auth/signup.jsp +++ b/web/views/auth/signup.jsp @@ -128,7 +128,7 @@ } else{ location.pathname = "/login"; $("#showErrorForm").addClass("hidden") - $('#contentSuccessForm').text("Update success") + $('#contentSuccessForm').text("Signup success") $("#showSuccessForm").removeClass("hidden") } })