Skip to content

Login Page Stuffs with Cookies #31

Merged
merged 2 commits into from Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions WebContent/adminLogin.jsp
@@ -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");
}

%>
27 changes: 18 additions & 9 deletions WebContent/index.jsp
@@ -1,6 +1,7 @@
<%@ page import = "database.MySQLAccess" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import = "java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
Expand All @@ -19,6 +20,9 @@
<link rel = "stylesheet" type = "text/css" href = "html/css/stylesheet.css">
<link rel = "shortcut icon" href = "html/imgs/synchrony-financial-logo-dlpx_1.ico">
<style>
.hidden{
display:none;
}
div.deviceContainer{
border: solid;
border-width: thin;
Expand Down Expand Up @@ -87,18 +91,23 @@
</nav>
<div class = "menuBox">
<div>
<a class = "divlink" href = "html/webpages/index.html">

<div class = "menuOption">
<h2>User Login</h2>
<img src = "html/imgs/cat.png"> </img>
</div>
</a>
<a class = "divlink" href="html/webpages/admin.html">
<form action="userLogin.jsp" method="post">
<input type="text" name="ssoNum" placeholder="SSO Number" /><br>
<input type ="submit" value="Login" />
</form>
</div>
<div class = "menuOption">
<h2>Admin Login</h2>
<img src = "html/imgs/cat_admin.png"> </img>
</div>
</a>
<form action="adminLogin.jsp" method="post">
<input type="text" name="ssoNum2" placeholder="SSO Number" />
<input type="password" name="pass" placeholder="Password" />
<input type ="submit" value="Login" />
</form>
</div>
</div>
</div>
</body>
</html>
</html>
25 changes: 25 additions & 0 deletions WebContent/userLogin.jsp
@@ -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");
}

%>
160 changes: 74 additions & 86 deletions src/database/MySQLAccess.java
@@ -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;
}
}