From 684f0040ae0602b299732f25bea851cd33165add Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Fri, 21 Apr 2017 00:24:46 -0400 Subject: [PATCH 1/2] I have learned to hate JSON. Goodnight. --- .../webpages/administration/adminApprove.jsp | 8 ++- .../webpages/administration/ticketApprove.jsp | 66 +++++++++++++++++++ .../webpages/redirect/locationRedirect.jsp | 4 +- .../webpages/redirect/orderFormHandler.jsp | 12 ++-- .../webpages/redirect/ticketAdminRedirect.jsp | 19 +++--- src/database/LocationQueries.java | 40 +++++++++++ src/database/TicketQueries.java | 9 ++- src/entities/Ticket.java | 8 ++- src/utilities/NotificationQueue.java | 2 +- 9 files changed, 146 insertions(+), 22 deletions(-) create mode 100644 WebContent/html/webpages/administration/ticketApprove.jsp diff --git a/WebContent/html/webpages/administration/adminApprove.jsp b/WebContent/html/webpages/administration/adminApprove.jsp index e144f39..1820d59 100644 --- a/WebContent/html/webpages/administration/adminApprove.jsp +++ b/WebContent/html/webpages/administration/adminApprove.jsp @@ -107,6 +107,7 @@ Location Name Device Name Status + Permanent? Return Date @@ -118,6 +119,7 @@ + @@ -133,6 +135,7 @@ Location Name Device Name Status + Permanent? Return Date @@ -167,18 +170,19 @@ var html = ""; for(var i = 0; i < tickets.length; i++){ //NEED TO ADD IN RETURN DATE AT END BUT THAT WOULD BREAK THINGS AT THE MOMENT - html += "" + tickets[i].id + "" + tickets[i].username + "" + tickets[i].locationname + "" + tickets[i].devicename + "" + tickets[i].status + "" + tickets[i].return + ""; + html += "" + tickets[i].id + "" + tickets[i].username + "" + tickets[i].locationname + "" + tickets[i].devicename + "" + tickets[i].status + "" + tickets[i].permanent + "" + tickets[i].return + ""; } document.getElementById("tablebodymain").innerHTML = html; } function ticketAction(){ var id = this.id; - var html = "" + tickets[id].id + "" + tickets[id].username + "" + tickets[id].locationname + "" + tickets[id].devicename + "" + tickets[id].status + "" + tickets[id].return + ""; + var html = "" + tickets[id].id + "" + tickets[id].username + "" + tickets[id].locationname + "" + tickets[id].devicename + "" + tickets[id].status + "" + tickets[id].permanent + "" + tickets[id].return + ""; document.getElementById("tablemodal").innerHTML = html; $("#ticketIDfield").val(tickets[id].id); $("#deviceIDfield").val(tickets[id].deviceID); $("#locationIDfield").val(tickets[id].location); + $("#permField").val(tickets[id].permanent); $("#Modal").show(); } diff --git a/WebContent/html/webpages/administration/ticketApprove.jsp b/WebContent/html/webpages/administration/ticketApprove.jsp new file mode 100644 index 0000000..7b35f4c --- /dev/null +++ b/WebContent/html/webpages/administration/ticketApprove.jsp @@ -0,0 +1,66 @@ +<%@ page import = "database.*,entities.Location" %> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + + + + + + + + Innovation Hub + + + + + + + + + + + +
+

Approving Tickets

+

Thanks for approving a ticket!

+

You can ship the devices to the following address:

+
+ Synchrony Financial

+
+
+ +
+
+ +<% +int locationid = -1; +for(Cookie c : usercookies){ + if(c.getName().equals("location")){ + locationid = Integer.parseInt(c.getValue()); + c.setMaxAge(0); + c.setPath("/"); + response.addCookie(c); + } +} +Location location = LocationQueries.getLocationByID(locationid); +String address = location.getAddress(); +String town = location.getTown(); +String state = location.getState(); +String zip = location.getZip(); +%> + + \ No newline at end of file diff --git a/WebContent/html/webpages/redirect/locationRedirect.jsp b/WebContent/html/webpages/redirect/locationRedirect.jsp index 8700f23..9c80f3d 100644 --- a/WebContent/html/webpages/redirect/locationRedirect.jsp +++ b/WebContent/html/webpages/redirect/locationRedirect.jsp @@ -37,7 +37,7 @@ String lng = request.getParameter("lng"); int er = 0; //add form was submitted if(request.getParameter("add") != null){ - Location location = new Location(0,name,address,town,state,zip,0,lat,lng); + Location location = new Location(0,name,address,town,state,zip,0,lat,lng,0,0); LocationQueries.addLocation(location); } //modify form was submitted @@ -46,7 +46,7 @@ if(request.getParameter("modify") != null){ String strID = request.getParameter("id"); //turn to int for constructor int id = Integer.parseInt(strID); - Location location = new Location(id,name,address,town,state,zip,0,lat,lng); + Location location = new Location(id,name,address,town,state,zip,0,lat,lng,0,0); LocationQueries.modifyLocation(location); } //delete form was submitted diff --git a/WebContent/html/webpages/redirect/orderFormHandler.jsp b/WebContent/html/webpages/redirect/orderFormHandler.jsp index b2c680a..aff74f9 100644 --- a/WebContent/html/webpages/redirect/orderFormHandler.jsp +++ b/WebContent/html/webpages/redirect/orderFormHandler.jsp @@ -43,11 +43,13 @@ String email = request.getParameter("email"); String[] options = request.getParameterValues("checkboxes"); int perm = 0; int urgent = 0; -for(int j = 0; j < options.length; j++){ - if(options[j].equals("perm")) - perm = 1; - if(options[j].equals("urgent")) - urgent = 1; +if(options != null){ + for(int j = 0; j < options.length; j++){ + if(options[j].equals("perm")) + perm = 1; + if(options[j].equals("urgent")) + urgent = 1; + } } // read location ID, but only if we haven't already generated it when adding new location to db if(location==-1){ location = Integer.parseInt(request.getParameter("location_dropdown"));} diff --git a/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp b/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp index e85a30f..2ab57a0 100644 --- a/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp +++ b/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp @@ -23,27 +23,32 @@ -

Redirect Page

-

You shouldn't be seeing this page :)

- <% //make instance String ticketidstr = request.getParameter("ticketid"); String deviceidstr = request.getParameter("deviceid"); String locationidstr = request.getParameter("locationid"); +String permanent = request.getParameter("permField"); int ticketid = Integer.parseInt(ticketidstr); int deviceid = Integer.parseInt(deviceidstr); int locationid = Integer.parseInt(locationidstr); +int perm = permanent.equals("Yes") ? 1 : 0; //approve form was submitted if(request.getParameter("approve") != null){ - TicketQueries.acceptTicket(ticketid,deviceid,locationid,Integer.parseInt(navsso)); + Cookie location = new Cookie("location",Integer.toString(locationid)); + location.setMaxAge(30*60); + location.setPath("/"); + response.addCookie(location); + TicketQueries.acceptTicket(ticketid,deviceid,locationid,Integer.parseInt(navsso),perm); User client = EmployeeQueries.getEmployeeByID(TicketQueries.getUserID(ticketid)); boolean notificationPreferences = (Math.floor(client.getNotificationPreferences()/2)%2==1); //The second least significant bit of notificationPreferences - the 2's place - is used for ticket approval notifications. if(notificationPreferences){ NotificationQueue q = new NotificationQueue(client,"ticketConfirmations"); q.start(); + response.sendRedirect("../administration/ticketApprove.jsp"); + return; } } //reject form was submitted @@ -55,12 +60,10 @@ if(request.getParameter("reject") != null){ if(notificationPreferences){ NotificationQueue q = new NotificationQueue(client, "ticketRejections"); q.start(); + response.sendRedirect("../administration/adminApprove.jsp"); + return; } } %> - - \ No newline at end of file diff --git a/src/database/LocationQueries.java b/src/database/LocationQueries.java index db96484..d3e5222 100644 --- a/src/database/LocationQueries.java +++ b/src/database/LocationQueries.java @@ -386,4 +386,44 @@ public static Location[] getAllLocations() throws SQLException, ClassNotFoundExc connection.close(); return locations; } + + public static Location getLocationByID(int id) throws InterruptedException, ClassNotFoundException, SQLException{ + //database connect + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + ResultSet resultSet = stmt.executeQuery("SELECT * FROM location WHERE Location_ID = " + id); + resultSet.next(); + return new Location( + resultSet.getInt("Location_ID"), + resultSet.getString("Name"), + resultSet.getString("Address"), + resultSet.getString("Town"), + resultSet.getString("State"), + resultSet.getString("Zip_Code"), + resultSet.getInt("Employee_Flag"), + resultSet.getString("Latitude"), + resultSet.getString("Longitude"), + 0,0 + ); + } } \ No newline at end of file diff --git a/src/database/TicketQueries.java b/src/database/TicketQueries.java index 0f28d9e..65d29d7 100644 --- a/src/database/TicketQueries.java +++ b/src/database/TicketQueries.java @@ -102,7 +102,8 @@ public static Ticket[] getTickets() resultSet.getString("Return_Date"), resultSet.getString("username"), resultSet.getString("Device_Name"), - resultSet.getString("locationname") + resultSet.getString("locationname"), + resultSet.getInt("Permanent_Order") ); i++; } @@ -111,7 +112,7 @@ public static Ticket[] getTickets() return tickets; } - public static void acceptTicket(int ticketid, int deviceid, int locationid, int sso) + public static void acceptTicket(int ticketid, int deviceid, int locationid, int sso, int perm) throws SQLException, ClassNotFoundException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); @@ -141,6 +142,7 @@ public static void acceptTicket(int ticketid, int deviceid, int locationid, int +", devices.Ticket_ID = " + ticketid +", devices.Status = \"Ready to Ship\", devices.Renter = " + sso +", devices.Location = " + locationid + +", devices.Permanent = " + perm +" WHERE ticket.Ticket_ID = " + ticketid + " AND devices.Device_ID = " + deviceid; System.out.println("Executing query: "+query); stmt.executeUpdate(query); @@ -246,7 +248,8 @@ public static Ticket[] getRecentlyChangedTickets(int userID, String status, long results.getString("Return_Date"), results.getString("username"), results.getString("locationname"), - results.getString("Device_Name") + results.getString("Device_Name"), + results.getInt("Permanent_Order") ); i++; } diff --git a/src/entities/Ticket.java b/src/entities/Ticket.java index f66ec62..e6b1bea 100644 --- a/src/entities/Ticket.java +++ b/src/entities/Ticket.java @@ -15,8 +15,9 @@ public class Ticket { private String username; private String locationname; private String devicename; + private String permanent; - public Ticket(int id, int requestor, long requestDate, int location, int deviceId, String status, long statusDateFields, String returnDate, String username, String locationname, String devicename){ + public Ticket(int id, int requestor, long requestDate, int location, int deviceId, String status, long statusDateFields, String returnDate, String username, String locationname, String devicename, int permanent){ this._id = id; this._requestor = requestor; this._requestDate = requestDate; @@ -28,6 +29,10 @@ public Ticket(int id, int requestor, long requestDate, int location, int deviceI this.username = username; this.locationname = locationname; this.devicename = devicename; + if(permanent == 0) + this.permanent = "No"; + else + this.permanent = "Yes"; } public String toString(){ @@ -41,6 +46,7 @@ public String toString(){ sb.append("\"username\": \"").append(username).append("\"").append(comma); sb.append("\"locationname\": \"").append(locationname).append("\"").append(comma); sb.append("\"devicename\": \"").append(devicename).append("\"").append(comma); + sb.append("\"permanent\": \"").append(permanent).append("\"").append(comma); sb.append("\"return\": \"").append(_returnDate).append("\""); sb.append("}"); return sb.toString(); diff --git a/src/utilities/NotificationQueue.java b/src/utilities/NotificationQueue.java index 06bf161..62e39e0 100644 --- a/src/utilities/NotificationQueue.java +++ b/src/utilities/NotificationQueue.java @@ -99,7 +99,7 @@ private void startTicketApproveQueue(User employee) throws InterruptedException, long milliseconds = new Date().getTime()-5000; Thread.sleep(threadWaitTime); System.out.println("NotificationQueue: sending summary approval email from thread "+Thread.currentThread().getName()); - Ticket[] tickets = TicketQueries.getRecentlyChangedTickets(employee.getID(), "Shipped", milliseconds); + Ticket[] tickets = TicketQueries.getRecentlyChangedTickets(employee.getID(), "Approved", milliseconds); Mail mail = new Mail(employee); mail.sendTicketApproval(tickets); } From fc200b494e1efbc687dc8058b89b935bf3df7aa3 Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Fri, 21 Apr 2017 13:32:11 -0400 Subject: [PATCH 2/2] Password Reset Functionality --- WebContent/adminLogin.jsp | 277 ++++++--- .../administration/adminpasswordsetting.jsp | 62 ++ .../adminpasswordsettingtryagain.jsp | 63 ++ .../webpages/administration/ticketApprove.jsp | 6 +- .../html/webpages/components/adminnavbar.jsp | 3 +- .../html/webpages/components/adminsidebar.jsp | 1 + .../html/webpages/components/navbar.jsp | 3 +- WebContent/html/webpages/error.jsp | 2 +- WebContent/html/webpages/index.jsp | 2 +- WebContent/html/webpages/listingPage.jsp | 14 +- WebContent/html/webpages/profileSettings.jsp | 33 +- .../webpages/redirect/adminpasswordchange.jsp | 22 +- .../webpages/redirect/adminpasswordupdate.jsp | 205 +++++++ WebContent/html/webpages/requestPage.jsp | 12 +- WebContent/html/webpages/returnComplete.jsp | 32 +- WebContent/html/webpages/returnPage.jsp | 92 +-- WebContent/html/webpages/shoppingCart.jsp | 576 +++++++++--------- WebContent/html/webpages/somethingwrong.jsp | 2 +- WebContent/html/webpages/statisticsPage.jsp | 104 ++-- WebContent/html/webpages/userLogin.jsp | 76 +-- WebContent/index.jsp | 73 +-- 21 files changed, 1077 insertions(+), 583 deletions(-) create mode 100644 WebContent/html/webpages/administration/adminpasswordsetting.jsp create mode 100644 WebContent/html/webpages/administration/adminpasswordsettingtryagain.jsp create mode 100644 WebContent/html/webpages/redirect/adminpasswordupdate.jsp diff --git a/WebContent/adminLogin.jsp b/WebContent/adminLogin.jsp index e33796f..df36b10 100644 --- a/WebContent/adminLogin.jsp +++ b/WebContent/adminLogin.jsp @@ -1,88 +1,221 @@ <%@ page import = "database.*" %> -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import = "java.sql.*" %> <%@ page import = "java.security.MessageDigest" %> <%@ page import = "java.security.NoSuchAlgorithmException" %> -<% -int ssoNum; -String pass; -Cookie adminCookie; +<%@ page import = "java.util.Random" %> + + + + + + + + + -ssoNum = Integer.parseInt(request.getParameter("username")); -pass = request.getParameter("pass"); -String generatedPass = null; + Innovation Hub -try { - MessageDigest md = MessageDigest.getInstance("MD5"); - md.update(pass.getBytes()); - byte[] bytes = md.digest(); - StringBuilder sb = new StringBuilder(); - for(int i = 0; i + + + + + + + + + +<% +/* + If admin chose to login, we work on this form. +*/ +if(request.getParameter("login") != null){ + /* + Get form information from last page. + */ + int ssoNum = Integer.parseInt(request.getParameter("username")); + String pass = request.getParameter("pass"); + Cookie adminCookie; + String generatedPass = null; -} - -String database = "jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317"; -String user = "b372dfe7409692"; -String password = "74f6e317"; -Class.forName("com.mysql.jdbc.Driver"); -Connection connection; -Statement stmt; -for(;;){ - try{ - connection = DriverManager.getConnection(database, user, password); - break; + /* + Hash what the user put in, so we can see if the passwords match up. + */ + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update(pass.getBytes()); + byte[] bytes = md.digest(); + StringBuilder sb = new StringBuilder(); + for(int i = 0; i \ No newline at end of file +/* + Goes back to the previous page. +*/ +function goBack(){ + window.history.back(); +} + + \ No newline at end of file diff --git a/WebContent/html/webpages/administration/adminpasswordsetting.jsp b/WebContent/html/webpages/administration/adminpasswordsetting.jsp new file mode 100644 index 0000000..0359bc0 --- /dev/null +++ b/WebContent/html/webpages/administration/adminpasswordsetting.jsp @@ -0,0 +1,62 @@ + + + + + + + + + + Innovation Hub + + + + + + + + + + + + + + + +
+ +
+

Change Your Password

+
+ + +
+
+ + +
+
+ + +
+ +
+
+

Change Pincode

+
+ + +
+ +
+
+ + \ No newline at end of file diff --git a/WebContent/html/webpages/administration/adminpasswordsettingtryagain.jsp b/WebContent/html/webpages/administration/adminpasswordsettingtryagain.jsp new file mode 100644 index 0000000..f006479 --- /dev/null +++ b/WebContent/html/webpages/administration/adminpasswordsettingtryagain.jsp @@ -0,0 +1,63 @@ + + + + + + + + + + Innovation Hub + + + + + + + + + + + + + + + +
+ +
+

Something went wrong. Try again!

+

Change Your Password

+
+ + +
+
+ + +
+
+ + +
+ +
+
+

Change Pincode

+
+ + +
+ +
+
+ + \ No newline at end of file diff --git a/WebContent/html/webpages/administration/ticketApprove.jsp b/WebContent/html/webpages/administration/ticketApprove.jsp index 7b35f4c..7116095 100644 --- a/WebContent/html/webpages/administration/ticketApprove.jsp +++ b/WebContent/html/webpages/administration/ticketApprove.jsp @@ -29,6 +29,10 @@ + +

Approving Tickets

Thanks for approving a ticket!

@@ -36,7 +40,7 @@
Synchrony Financial

-
+
diff --git a/WebContent/html/webpages/components/adminnavbar.jsp b/WebContent/html/webpages/components/adminnavbar.jsp index 160a20a..e3cde2c 100644 --- a/WebContent/html/webpages/components/adminnavbar.jsp +++ b/WebContent/html/webpages/components/adminnavbar.jsp @@ -24,6 +24,7 @@
  • Device Hub
  • Location Hub
  • +
  • Update Password/Pincode
  • \ No newline at end of file diff --git a/WebContent/html/webpages/components/navbar.jsp b/WebContent/html/webpages/components/navbar.jsp index 0f32c01..ac1ec25 100644 --- a/WebContent/html/webpages/components/navbar.jsp +++ b/WebContent/html/webpages/components/navbar.jsp @@ -24,6 +24,7 @@