Skip to content

Commit

Permalink
Restructured Mail.java a bit and added ticket confirmation email temp…
Browse files Browse the repository at this point in the history
…late
  • Loading branch information
arc12012 committed Apr 16, 2017
1 parent c4ec0a7 commit 20f7ba5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
15 changes: 10 additions & 5 deletions WebContent/html/webpages/orderFormHandler.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pageEncoding="ISO-8859-1"%>
<html>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
<%@ include file="navbar.jsp"%>
<%@include file="navbar.jsp"%>
</nav>
<script type="text/javascript">
<%
Expand Down Expand Up @@ -51,16 +51,21 @@ for(int i=0; i<idStringArray.length; i++)
devIDs[j]=Integer.parseInt(idStringArray[i]);
j++;
}
// Now just call generateTicket once for each device
// Now just call generateTicket once for each device (and store ticket IDs)
int[] ticketIDs = new int[devIDs.length];
for(int i=0; i<devIDs.length; i++)
{
TicketQueries.generateTicket(Integer.parseInt(navsso), location, devIDs[i], request.getParameter("timeNeeded"));//TODO get ID somehow
ticketIDs[i] = TicketQueries.generateTicket(Integer.parseInt(navsso), location, devIDs[i], request.getParameter("timeNeeded"));
}
// Now that tickets have been generated we will want to notify users.
boolean emailNotificationEnabled = true; //If/when we enable opting out of notifications this is where that check will take place
if(emailNotificationEnabled)
{
new Mail(self).sendTicketConfirmation(ticketIDs); //'self' is the current user, and is defined in navbar.jsp
}
%>
window.location.replace("shoppingCart.jsp");
</script>
Expand Down
15 changes: 15 additions & 0 deletions emails/ticketConfirmation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h4>We've received your order! We'll let you know when your device{s} will ship.</h2>
<p>The following ticket{s} {was/were} generated:</p>
<div name = 'tickets' style='text-indent: 20px'>
<p>Ticket #<a href='../WebContent/html/webpages/'>12321312</a></p>
<p>Ticket #<a href='../WebContent/html/webpages/'>12321312</a></p>
</div>
</body>
<footer style='text-align: center;'><font size='2'>To change notification settings, please visit your <a href='../WebContent/html/webpages/profileSettings.jsp'>profile settings page</a></font></footer>
</html>
3 changes: 2 additions & 1 deletion src/database/TicketQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TicketQueries {
private static String user = "b372dfe7409692";
private static String password = "74f6e317";

public static void generateTicket(int requester, int location, int device, String returnDate) throws ClassNotFoundException, SQLException
public static int generateTicket(int requester, int location, int device, String returnDate) throws ClassNotFoundException, SQLException
{
long time = new Date().getTime(); //Using milliseconds because sql is annoying with dates.
int ticketID = (int)((time+requester+device+location)%10000);
Expand All @@ -34,6 +34,7 @@ public static void generateTicket(int requester, int location, int device, Strin
stmt.executeUpdate(query);
stmt.close();
connection.close();
return ticketID;
}

//get all tickets
Expand Down
29 changes: 17 additions & 12 deletions src/utilities/Mail.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,34 @@
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

import entities.User;

import javax.activation.*;


public class Mail {

public Mail() {
}
public void email() {
String from = "arclaxton@gmail.com";
String password = "*****";
String to = "arclaxton@gmail.com";
String subject = "test";
String msg = "this is a test";
private String sender = "arclaxton@gmail.com";
private String password = "*****";
private User client;
public Mail(User client){
this.client=client;
}
//Sends an email to address specified by recipient param
// messegeIndex param is for choosing which
public void sendTicketConfirmation(int[] ticketIDs) {
String subject = "Your test device order";
String msg = "";
Properties properties = System.getProperties();
properties = setProp(from, to);
properties = setProp(sender, client.getEmail());
Session session = Session.getInstance(properties, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(from, password);
return new PasswordAuthentication(sender, password);
}
});

try {
Address address = new InternetAddress(to);
Address address = new InternetAddress(client.getEmail());
MimeMessage message = new MimeMessage(session);
message.setFrom(address);
message.addRecipient(Message.RecipientType.TO, address);
Expand Down

0 comments on commit 20f7ba5

Please sign in to comment.