Skip to content

Commit

Permalink
some login stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
chasinhues committed May 27, 2016
1 parent 1b95a07 commit 62a42b4
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/jTransfer/AdminLoginServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package jTransfer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @author JASON
*/
@WebServlet(name = "AdminLoginServlet")
public class AdminLoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/adminLogin.jsp").forward(request, response);
}
}
30 changes: 30 additions & 0 deletions src/jTransfer/AdminServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package jTransfer;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
* Created by JasonHughes on 26/05/2016.
*/
public class AdminServlet extends HttpServlet {

public void doPost( HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
doGet(request, response);
}

public void doGet( HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
AdminSession as = new AdminSession();
List<Types> result = as.getTypes();
//response.getWriter().print("hello world");
request.setAttribute("sessions", result);
request.getRequestDispatcher("adminView.jsp").forward(request, response);
//RequestDispatcher view = request.getRequestDispatcher("adminView.jsp");
//view.forward(request, response);
}
}
79 changes: 79 additions & 0 deletions src/jTransfer/AdminSession.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package jTransfer;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

/**
* Created by JasonHughes on 26/05/2016.
*/
public class AdminSession {

// JDBC driver name and database URL
private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
private static final String DB_URL = "jdbc:mysql://localhost:3306/";

// Database credentials
// TODO: Change the username and password for a production environment
private static final String USER = "jtransfer";
private static final String PASS = "pass";

// returns a list of all the things in the logging_session database
public List<Types> getTypes() {
ResultSet rs;
List<Types> list = new ArrayList();
Types type = new Types();

try{
Connection con = getConnection();
String Query = "SELECT * FROM logging_session";
// System.out.println(Query);

rs = con.createStatement().executeQuery(Query);

while (rs.next()) {
type.setId(rs.getString(1));
type.setTimestamp(rs.getString(2));
type.setSessionId(rs.getString(3));
type.setLog(rs.getString(4));
// System.out.println(">> Types: " + type.toString());
list.add(type);
}
rs.close();
con.close();

}catch (SQLException e) {
System.out.println("SQLException");
e.printStackTrace();
}
return(list);
}

// retrieve and return a connection to the logging_session database
public static Connection getConnection() {
// instantiate variables
java.sql.Connection connection = null;

try {
// String driverName = "oracle.jdbc.OracleDriver";
Class.forName(JDBC_DRIVER);

// Create a connection to the database
connection = DriverManager.getConnection(DB_URL,USER,PASS);
connection.setCatalog("jtransfer");

return connection;


} catch (ClassNotFoundException e) {
System.out.println("ClassNotFoundException");
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}

}
83 changes: 83 additions & 0 deletions src/jTransfer/Types.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package jTransfer;

import java.sql.Connection;
import java.util.*;
import java.sql.*;

/**
* Created by JasonHughes on 26/05/2016.
*/

public class Types {
// instantiate logging_session database metadata types
private String id;
private String timestamp;
private String sessionId;
private String log;

// constructor
public Types() {
this.id = null;
this.timestamp = null;
this.sessionId = null;
this.log = null;
}

// getter method for id variable
public String getId() { return id; }

// setter method for id variable
public void setId(String id) {
this.id = id;
}

// getter method for timestamp variable
public String getTimestamp() {
return timestamp;
}

// setter method for timestamp variable
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}

// getter method for sessionId variable
public String getSessionId() {
return sessionId;
}

// setter method for sessionId variable
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}

// getter method for log variable
public String getLog() {
return log;
}

// setter method for log variable
public void setLog(String log) {
this.log = log;
}

@Override
public String toString() {
return "Types{" +
"id='" + id + '\'' +
", timestamp='" + timestamp + '\'' +
", sessionId='" + sessionId + '\'' +
", log='" + log + '\'' +
'}';
}

public String toHTML(){
return "<td>" + id + "</td>" +
"<td>" + timestamp + "</td>" +
"<td>" + sessionId + "</td>" +
"<td>" + log + "</td>";
}


}

20 changes: 20 additions & 0 deletions web/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@
<url-pattern>/login</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>AdminServlet</servlet-name>
<servlet-class>jTransfer.AdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdminServlet</servlet-name>
<url-pattern>/admin</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>AdminLoginServlet</servlet-name>
<servlet-class>jTransfer.AdminLoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdminLoginServlet</servlet-name>
<url-pattern>/adminLogin</url-pattern>
</servlet-mapping>



<listener>
<listener-class>jTransfer.TransferSessionListener</listener-class>
</listener>
Expand Down
24 changes: 24 additions & 0 deletions web/adminLogin.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<html>
<head>
<%@include file="includes/head.jsp" %>
</head>
<body>
<div class="container">
<div class="jumbotron">
<h1>Browser Transfer</h1>
<form action="./admin" method="post" id="loginform">
<div class="row">
<h2>Admin login</h2>
<label for="admin-username">Username:</label>
<input type="text" name="username" id="admin-username" class="form-control"/><br>
<label for="admin-password">Password:</label>
<input type="password" name="password" id="admin-password" class="form-control"/><br>
<input type="submit" name="submit" value="Submit" class="btn"/>
</div>
</form>
</div>
</div>
<%@include file="includes/bootstrapjs.jsp" %>
<script src="${pageContext.request.contextPath}/js/common.js" type="text/javascript"></script>
</body>
</html>
42 changes: 42 additions & 0 deletions web/adminView.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<%@ page import="java.util.List" %>
<%@ page import="jTransfer.Types" %>
<html>
<head>
<%@include file="includes/head.jsp" %>
</head>
<body>
<div class="row">
<div class="col-sm-11">
<h1>Browser Transfer</h1>
</div>
<div class="col-sm-1">
<form method="get" action="logout">
<input type="submit" name="logout" value="Logout" class="btn" id="logout">
</form>
</div>
</div>
<div class="jumbotron files row">
<div id="filecontainer" class="row">
<table>
<tr>
<th>id</th>
<th>timestamp</th>
<th>session id</th>
<th>log</th>
</tr>
<%
List<Types> results = (List) request.getAttribute("sessions");
for (Types type : results){
out.print("<tr>");
out.print(type.toHTML());
out.print("</tr>");
}
%>
</table>
</div>
</div>

<%@include file="includes/bootstrapjs.jsp" %>
<script src="${pageContext.request.contextPath}/js/common.js" type="text/javascript"></script>
</body>
</html>
8 changes: 5 additions & 3 deletions web/index.jsp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<%@include file="includes/head.jsp" %>
<%@include file="includes/head.jsp" %>
</head>
<body>
<div class="container">
Expand All @@ -11,14 +11,16 @@
<label for="remote">SFTP Server Address:</label>
<input type="text" name="remote" id="remote" value="remote.labs.eait.uq.edu.au" class="form-control"/><br>
</div>
<div class="form-group">
<div class="row">
<h2>User Login</h2>
<label for="username">Username:</label>
<input type="text" name="username" id="username" class="form-control"/><br>
<label for="password">Password:</label>
<input type="password" name="password" id="password" class="form-control"/><br>
<input type="submit" name="submit" value="Submit" class="btn"/>
</div>
<input type="submit" name="submit" value="Submit" class="btn"/>
</form>
<a href="./adminLogin">Log in to admin view</a>
</div>
</div>
<%@include file="includes/bootstrapjs.jsp" %>
Expand Down

0 comments on commit 62a42b4

Please sign in to comment.