Skip to content

Commit

Permalink
Login Page Stuffs with Cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
Brianna authored and Brianna committed Mar 23, 2017
1 parent 11fe650 commit 316f9ad
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 31 deletions.
27 changes: 27 additions & 0 deletions WebContent/adminLogin.jsp
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");
}
%>
27 changes: 18 additions & 9 deletions WebContent/index.jsp
Original file line number Diff line number Diff line change
@@ -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
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");
}
%>
27 changes: 5 additions & 22 deletions src/database/MySQLAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,14 @@
import java.sql.*;

public class MySQLAccess {

String[][] result = new String[20][3];

public void connectDB() throws SQLException, ClassNotFoundException {
System.getenv("VCAP_SERVICES");


public Statement 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();
//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 String[][] getResult(){
return result;
return statement;

}
}

0 comments on commit 316f9ad

Please sign in to comment.