Skip to content

Commit

Permalink
Reducing queries via navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
clj13001 committed Apr 19, 2017
1 parent af9ba3d commit 16d0493
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 20 deletions.
6 changes: 5 additions & 1 deletion WebContent/adminLogin.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection(database, user, password);
Statement stmt = connection.createStatement();
ResultSet result;
result = stmt.executeQuery("select * FROM admin where Admin_ID='" + ssoNum + "' AND Password='" + generatedPass + "'");
result = stmt.executeQuery("select admin.*,employee.Name FROM admin INNER JOIN employee ON admin.Admin_ID = employee.Employee_ID WHERE Admin_ID='" + ssoNum + "' AND Password='" + generatedPass + "'");
if (result.next()){
request.getSession();
Expand All @@ -46,6 +46,10 @@ if (result.next()){
Cookie adminCookie2 = new Cookie("admin", Integer.toString(ssoNum));
adminCookie2.setPath("/");
response.addCookie(adminCookie2);
Cookie newCookie = new Cookie("name",result.getString("Name"));
newCookie.setMaxAge(30*60);
newCookie.setPath("/");
response.addCookie(newCookie);
if(result.getInt("Password_Flag") == 1){
stmt.close();
connection.close();
Expand Down
12 changes: 6 additions & 6 deletions WebContent/html/webpages/components/adminnavbar.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,26 @@
Cookie[] usercookies = request.getCookies();
String navsso = "invalid";
String navname = "error";
User self = new User();
int admin = 0;
//iterate cookies
if(usercookies != null){
for(Cookie c : usercookies){
if(c.getName().equals("ssoNum") || c.getName().equals("admin")){//when (and if) we get to user cookie we want to reset it
navsso = c.getValue();
String cookiename = c.getName();
c.setMaxAge(30*60);//delete current
c.setPath("/");
response.addCookie(c);
}
if(c.getName().equals("admin")){
admin = 1;
}
if(c.getName().equals("name")){
navname = c.getValue();
c.setMaxAge(30*60);
c.setPath("/");
response.addCookie(c);
}
}
}
if(navsso.equals("invalid")){//if we didn't get a cookie, redirect to the homepage to log in again!
Expand All @@ -68,10 +72,6 @@
response.sendRedirect("../index.jsp");
return;
}
else{
self = EmployeeQueries.getEmployeeByID(Integer.parseInt(navsso));
navname = self.getName();
}
}
%>
</div>
Expand Down
12 changes: 6 additions & 6 deletions WebContent/html/webpages/components/navbar.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,32 @@
Cookie[] usercookies = request.getCookies();
String navsso = "invalid";
String navname = "error";
User self = new User();
int admin = 0;
//iterate cookies
if(usercookies != null){
for(Cookie c : usercookies){
if(c.getName().equals("ssoNum") || c.getName().equals("admin")){//when (and if) we get to user cookie we want to reset it
navsso = c.getValue();
String cookiename = c.getName();
c.setMaxAge(30*60);//delete current
c.setPath("/");
response.addCookie(c);
}
if(c.getName().equals("admin")){
admin = 1;
}
if(c.getName().equals("name")){
navname = c.getValue();
c.setMaxAge(30*60);
c.setPath("/");
response.addCookie(c);
}
}
}
if(navsso.equals("invalid")){//if we didn't get a cookie, redirect to the homepage to log in again!
response.sendRedirect("../../index.jsp");
return;
}
else{
self = EmployeeQueries.getEmployeeByID(Integer.parseInt(navsso));
navname = self.getName();
}
%>
</div>
<script>
Expand Down
4 changes: 4 additions & 0 deletions WebContent/html/webpages/profileSettings.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
</div>
</form>
</div>

<%
User self = EmployeeQueries.getEmployeeByID(Integer.parseInt(navsso));
%>
<script>
var iconSelect;
Expand Down
1 change: 1 addition & 0 deletions WebContent/html/webpages/redirect/orderFormHandler.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pageEncoding="ISO-8859-1"%>
</nav>
<script type="text/javascript">
<%
User self = EmployeeQueries.getEmployeeByID(Integer.parseInt(navsso));
// If location id is 0, it is a custom location which must be added to the database before employee preffered location can be updated
int location=-1;
if(Integer.parseInt(request.getParameter("location_dropdown"))==0)
Expand Down
4 changes: 0 additions & 4 deletions WebContent/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@

<%
Cookie[] usercookies = request.getCookies();
String navsso = "invalid";
String navname = "error";
User self = new User();
Cookie newCookie;
//iterate cookies
if(usercookies != null){
for(Cookie c : usercookies){
Expand Down
9 changes: 6 additions & 3 deletions WebContent/userLogin.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
pageEncoding="ISO-8859-1"%>
<%@ page import = "java.sql.*" %>
<%
int ssoNum;
Cookie userCookie;
Cookie userCookie,newCookie;
ssoNum = Integer.parseInt(request.getParameter("username"));
int ssoNum = Integer.parseInt(request.getParameter("username"));
Class.forName("com.mysql.jdbc.Driver");
String database = "jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317";
Expand All @@ -24,6 +23,10 @@ if (result.next()){
userCookie.setMaxAge(30*60);
userCookie.setPath("/");
response.addCookie(userCookie);
newCookie = new Cookie("name",result.getString("Name"));
newCookie.setMaxAge(30*60);
newCookie.setPath("/");
response.addCookie(newCookie);
stmt.close();
connection.close();
response.sendRedirect("html/webpages/index.jsp");
Expand Down

0 comments on commit 16d0493

Please sign in to comment.