-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from arc12012/BriBranch
Login Page Stuffs with Cookies
- Loading branch information
Showing
4 changed files
with
144 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<%@ page import = "database.MySQLAccess" %> | ||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" | ||
pageEncoding="ISO-8859-1"%> | ||
<%@ page import = "java.sql.*" %> | ||
<% | ||
int ssoNum; | ||
String pass; | ||
Cookie adminCookie; | ||
ssoNum = Integer.parseInt(request.getParameter("ssoNum2")); | ||
pass = request.getParameter("pass"); | ||
MySQLAccess myaccess = new MySQLAccess(); | ||
Statement statement = myaccess.connectDB(); | ||
ResultSet result; | ||
result = statement.executeQuery("select * FROM admin where Admin_ID='" + ssoNum + "' AND Password='" + pass + "'"); | ||
if (result.next()){ | ||
request.getSession(); | ||
session.setAttribute("ssoNum", ssoNum); | ||
adminCookie = new Cookie("ssoNum", Integer.toString(ssoNum)); | ||
adminCookie.setMaxAge(30*60); | ||
response.addCookie(adminCookie); | ||
response.sendRedirect("html/webpages/admin.html"); | ||
} else { | ||
response.sendRedirect("index.jsp"); | ||
} | ||
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<%@ page import = "database.MySQLAccess" %> | ||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" | ||
pageEncoding="ISO-8859-1"%> | ||
<%@ page import = "java.sql.*" %> | ||
<% | ||
int ssoNum; | ||
Cookie userCookie; | ||
ssoNum = Integer.parseInt(request.getParameter("ssoNum")); | ||
MySQLAccess myaccess = new MySQLAccess(); | ||
Statement statement = myaccess.connectDB(); | ||
ResultSet result; | ||
result = statement.executeQuery("select * FROM employee where Employee_ID='" + ssoNum + "'"); | ||
if (result.next()){ | ||
request.getSession(); | ||
session.setAttribute("ssoNum", ssoNum); | ||
userCookie = new Cookie("ssoNum", Integer.toString(ssoNum)); | ||
userCookie.setMaxAge(30*60); | ||
response.addCookie(userCookie); | ||
response.sendRedirect("html/webpages/index.html"); | ||
} else { | ||
response.sendRedirect("index.jsp"); | ||
} | ||
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,74 @@ | ||
package database; | ||
|
||
import java.sql.*; | ||
|
||
import entities.ListedDevice; | ||
import entities.RentedDevice; | ||
|
||
public class MySQLAccess { | ||
|
||
String[][] result = new String[20][3]; | ||
|
||
public void connectDB() throws SQLException, ClassNotFoundException { | ||
System.getenv("VCAP_SERVICES"); | ||
Class.forName("com.mysql.jdbc.Driver"); | ||
Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317"); | ||
Statement statement = connect.createStatement(); | ||
//PreparedStatement preparedStatement = null; | ||
ResultSet resultSet = statement.executeQuery("SELECT * FROM devices"); | ||
|
||
while(resultSet.next()){ | ||
String deviceName = resultSet.getString("Device_Name"); | ||
String deviceDescription = resultSet.getString("Device_Description"); | ||
String hardwareType = resultSet.getString("Hardware_Model"); | ||
|
||
for(int i = 0; i<1; i++){ | ||
result[i][0] = deviceName; | ||
result[i][1] = deviceDescription; | ||
result[i][2] = hardwareType; | ||
} | ||
} | ||
} | ||
|
||
public RentedDevice[] getUserDevices(String userID) throws SQLException, ClassNotFoundException{ | ||
//Not sure how to get cookie information (if that is how we choose to accomplish this...) ? But this should be a passed parameter | ||
System.getenv("VCAP_SERVICES"); | ||
Class.forName("com.mysql.jdbc.Driver"); | ||
Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317"); | ||
Statement stmt = connect.createStatement(); | ||
ResultSet resultSet = stmt.executeQuery("SELECT Device_ID, Device_Name, Device_Description, Ticket_ID, Hardware, Model, Borrow_Date FROM devices WHERE Renter = " + userID); | ||
int counter = 0; | ||
|
||
resultSet.last(); | ||
int rows = resultSet.getRow(); | ||
resultSet.beforeFirst(); | ||
|
||
//Covers amount of rows, and 6 attributes (indices 0-5) | ||
RentedDevice[] devices = new RentedDevice[rows]; | ||
|
||
//iterate result set | ||
while(resultSet.next()){ | ||
devices[counter] = new RentedDevice(resultSet.getInt("Device_ID") + "",resultSet.getString("Device_Name"),resultSet.getString("Device_Description"),resultSet.getInt("Ticket_ID") + "",resultSet.getString("Hardware"),resultSet.getString("Model"),resultSet.getString("Borrow_Date")); | ||
counter++; | ||
} | ||
|
||
return devices; | ||
} | ||
|
||
public ListedDevice[] getAllDevices() throws SQLException, ClassNotFoundException{ | ||
//Not sure how to get cookie information (if that is how we choose to accomplish this...) ? But this should be a passed parameter | ||
System.getenv("VCAP_SERVICES"); | ||
Class.forName("com.mysql.jdbc.Driver"); | ||
Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317"); | ||
Statement stmt = connect.createStatement(); | ||
ResultSet resultSet = stmt.executeQuery("SELECT * FROM devices"); | ||
int counter = 0; | ||
|
||
resultSet.last(); | ||
int rows = resultSet.getRow(); | ||
resultSet.beforeFirst(); | ||
|
||
//Covers amount of rows, and 6 attributes (indices 0-5) | ||
ListedDevice[] devices = new ListedDevice[rows]; | ||
|
||
//iterate result set | ||
while(resultSet.next()){ | ||
devices[counter] = new ListedDevice(resultSet.getString("Device_Name"),resultSet.getString("Device_Description"),resultSet.getString("Hardware"),resultSet.getString("Model")); | ||
counter++; | ||
} | ||
|
||
return devices; | ||
} | ||
|
||
public String[][] getResult(){ | ||
return result; | ||
} | ||
} | ||
package database; | ||
|
||
import java.sql.*; | ||
|
||
import entities.ListedDevice; | ||
import entities.RentedDevice; | ||
|
||
public class MySQLAccess { | ||
|
||
String[][] result = new String[20][3]; | ||
|
||
public void connectDB() throws SQLException, ClassNotFoundException { | ||
Class.forName("com.mysql.jdbc.Driver"); | ||
Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317"); | ||
Statement statement = connect.createStatement(); | ||
|
||
return statement; | ||
|
||
} | ||
|
||
public RentedDevice[] getUserDevices(String userID) throws SQLException, ClassNotFoundException{ | ||
//Not sure how to get cookie information (if that is how we choose to accomplish this...) ? But this should be a passed parameter | ||
System.getenv("VCAP_SERVICES"); | ||
Class.forName("com.mysql.jdbc.Driver"); | ||
Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317"); | ||
Statement stmt = connect.createStatement(); | ||
ResultSet resultSet = stmt.executeQuery("SELECT Device_ID, Device_Name, Device_Description, Ticket_ID, Hardware, Model, Borrow_Date FROM devices WHERE Renter = " + userID); | ||
int counter = 0; | ||
|
||
resultSet.last(); | ||
int rows = resultSet.getRow(); | ||
resultSet.beforeFirst(); | ||
|
||
//Covers amount of rows, and 6 attributes (indices 0-5) | ||
RentedDevice[] devices = new RentedDevice[rows]; | ||
|
||
//iterate result set | ||
while(resultSet.next()){ | ||
devices[counter] = new RentedDevice(resultSet.getInt("Device_ID") + "",resultSet.getString("Device_Name"),resultSet.getString("Device_Description"),resultSet.getInt("Ticket_ID") + "",resultSet.getString("Hardware"),resultSet.getString("Model"),resultSet.getString("Borrow_Date")); | ||
counter++; | ||
} | ||
|
||
return devices; | ||
} | ||
|
||
public ListedDevice[] getAllDevices() throws SQLException, ClassNotFoundException{ | ||
//Not sure how to get cookie information (if that is how we choose to accomplish this...) ? But this should be a passed parameter | ||
System.getenv("VCAP_SERVICES"); | ||
Class.forName("com.mysql.jdbc.Driver"); | ||
Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317"); | ||
Statement stmt = connect.createStatement(); | ||
ResultSet resultSet = stmt.executeQuery("SELECT * FROM devices"); | ||
int counter = 0; | ||
|
||
resultSet.last(); | ||
int rows = resultSet.getRow(); | ||
resultSet.beforeFirst(); | ||
|
||
//Covers amount of rows, and 6 attributes (indices 0-5) | ||
ListedDevice[] devices = new ListedDevice[rows]; | ||
|
||
//iterate result set | ||
while(resultSet.next()){ | ||
devices[counter] = new ListedDevice(resultSet.getString("Device_Name"),resultSet.getString("Device_Description"),resultSet.getString("Hardware"),resultSet.getString("Model")); | ||
counter++; | ||
} | ||
|
||
return devices; | ||
} | ||
|
||
public String[][] getResult(){ | ||
return result; | ||
} | ||
} |