Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix formatting and a couple warnings.

  • Loading branch information...
commit 1439266ade321f95af1098f64dce476af5f32027 1 parent 3839d3a
Graylin Kim authored February 01, 2013
126  BBSignup/src/main/java/bbsignup/src/Controller.java
@@ -18,19 +18,23 @@
18 18
 import javax.mail.internet.InternetAddress;
19 19
 import javax.mail.internet.MimeMessage;
20 20
 
21  
-import bbsignup.model.*;
  21
+import bbsignup.model.Senator;
  22
+import bbsignup.model.User;
  23
+import bbsignup.model.UserAuth;
  24
+import bbsignup.src.PMF;
  25
+import bbsignup.src.Resource;
22 26
 
23 27
 public class Controller {
24  
-	
  28
+
25 29
 	public String WEBLINK = "http://billbuzz.nysenate.gov/";
26  
-	
  30
+
27 31
 	public static void main(String[] args) throws IOException {
28 32
 		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
29 33
 		String in = "";
30  
-		
  34
+
31 35
 		System.out.print("> ");
32 36
 		while(!(in = br.readLine()).equals("exit")) {
33  
-			
  37
+
34 38
 			if(in.startsWith("add user")) {
35 39
 				Pattern p = Pattern.compile("add user (.+?) (.+?) (.+?) (true|false)$");
36 40
 				Matcher m = p.matcher(in);
@@ -60,15 +64,15 @@ else if(in.startsWith("delete user")) {
60 64
 			else if(in.startsWith("set other")) {
61 65
 				PersistenceManager pm = PMF.getPersistenceManager();
62 66
 				Transaction tx = pm.currentTransaction();
63  
-				
  67
+
64 68
 				try {
65 69
 					tx.begin();
66  
-					
  70
+
67 71
 					List<User> users = (List<User>)PMF.getObjects(pm, User.class);
68 72
 					for(User user:users) {
69 73
 						user.setOtherData(true);
70 74
 					}
71  
-					
  75
+
72 76
 					tx.commit();
73 77
 				}
74 78
 				finally {
@@ -81,32 +85,32 @@ else if(in.startsWith("set other")) {
81 85
 			System.out.print("> ");
82 86
 		}
83 87
 	}
84  
-	
  88
+
85 89
 	public Controller() {
86 90
 	}
87  
-	
  91
+
88 92
 	@SuppressWarnings("unchecked")
89 93
 	public List<Senator> getSenators() {
90 94
 		return (List<Senator>) PMF.getDetachedObjects(Senator.class);
91  
-		
  95
+
92 96
 	}
93  
-	
  97
+
94 98
 	public String tryDelete(String email) {
95  
-		
  99
+
96 100
 		User u = (User) PMF.getDetachedObject(User.class, "email", email);
97  
-		
  101
+
98 102
 		if(u != null) {
99 103
 			UserAuth ua = this.getUserAuth(email);
100 104
 			if(ua == null) {
101 105
 				ua = new UserAuth(email);
102 106
 			}
103  
-			
  107
+
104 108
 			String message = "Hello!<br/><br/>To remove yourself from BillBuzz please click the following link:";
105  
-			
  109
+
106 110
 			message += "<br/><br/>" + WEBLINK + "delete.jsp?email=" + email + "&key=" + ua.getHash();
107  
-			
  111
+
108 112
 			message += "<br/><br/>If you have any questions please contact us at <a href=\"mailto:billbuzz@nysenate.gov\">billbuzz@nysenate.gov</a> or reply to this email.";
109  
-			
  113
+
110 114
 			try {
111 115
 				sendMail(email,"Finalize your BillBuzz cancellation", message, "billbuzz@nysenate.gov", "BillBuzz");
112 116
 				PMF.persistObject(ua);
@@ -114,66 +118,66 @@ public String tryDelete(String email) {
114 118
 				e.printStackTrace();
115 119
 			}
116 120
 			return null;
117  
-			
  121
+
118 122
 		}
119 123
 		return "errno4";
120 124
 	}
121  
-	
  125
+
122 126
 	public boolean deleteUser(String email, String key) {
123 127
 		UserAuth ua = getUserAuth(email);
124  
-		
125  
-		if(ua != null && ua.getHash() != null && ua.isHashCorrect(key)) {	
126  
-			PMF.deleteObjects(new Class[] {User.class,UserAuth.class}, 
127  
-					new String[] {"email","email"}, 
  128
+
  129
+		if(ua != null && ua.getHash() != null && ua.isHashCorrect(key)) {
  130
+			PMF.deleteObjects(new Class[] {User.class,UserAuth.class},
  131
+					new String[] {"email","email"},
128 132
 					new String[] {email,email});
129 133
 
130  
-			return true;	
  134
+			return true;
131 135
 		}
132 136
 		return false;
133 137
 	}
134  
-	
  138
+
135 139
 	public User getUser(String email) {
136 140
 		return (User) PMF.getDetachedObject(User.class, "email", email);
137 141
 	}
138  
-	
  142
+
139 143
 	public UserAuth getUserAuth(String email) {
140 144
 		return (UserAuth) PMF.getDetachedObject(UserAuth.class, "email", email);
141 145
 	}
142  
-	
143  
-	
  146
+
  147
+
144 148
 	public void newUserEmail(String email, String hash) {
145 149
 		String message = "Hello!<br/><br/>Thanks for signing up for BillBuzz.  To finalize your subscription please click the following link:";
146  
-		
  150
+
147 151
 		message += "<br/><br/>" + WEBLINK + "authenticate.jsp?email=" + email + "&key=" + hash;
148  
-		
  152
+
149 153
 		message += "<br/><br/>If you have any questions please contact us at <a href=\"mailto:billbuzz@nysenate.gov\">billbuzz@nysenate.gov</a> or reply to this email.";
150  
-		
  154
+
151 155
 		try {
152 156
 			sendMail(email,"Finalize your BillBuzz subscription", message, "billbuzz@nysenate.gov", "BillBuzz");
153 157
 		} catch (Exception e) {
154 158
 			e.printStackTrace();
155  
-		}		
  159
+		}
156 160
 	}
157  
-	
  161
+
158 162
 	public String updateEmail(String email) {
159  
-		
  163
+
160 164
 		User u = getUser(email);
161  
-		
  165
+
162 166
 		if(u == null) {
163 167
 			return "errno5";
164 168
 		}
165  
-		
  169
+
166 170
 		UserAuth ua = getUserAuth(email);
167 171
 		if(ua == null) {
168  
-			ua = new UserAuth(email);	
  172
+			ua = new UserAuth(email);
169 173
 		}
170  
-		
  174
+
171 175
 		String message = "Hello!<br/><br/>It looks like you're trying to update your subscription, to do so please click the link below and follow the instructions:";
172  
-		
  176
+
173 177
 		message += "<br/><br/>" + WEBLINK + "update.jsp?uemail=" + email + "&key=" + ua.getHash();
174  
-		
  178
+
175 179
 		message += "<br/><br/>If you have any questions please contact us at <a href=\"mailto:billbuzz@nysenate.gov\">billbuzz@nysenate.gov</a> or reply to this email.";
176  
-		
  180
+
177 181
 		try {
178 182
 			sendMail(email,"Update your BillBuzz subscription", message, "billbuzz@nysenate.gov", "BillBuzz");
179 183
 			PMF.deleteObjectById(UserAuth.class, "email", email);
@@ -183,22 +187,22 @@ public String updateEmail(String email) {
183 187
 		}
184 188
 		return null;
185 189
 	}
186  
-	
  190
+
187 191
 	public boolean authenticateUser(String email, String key){
188 192
 		UserAuth ua = getUserAuth(email);
189  
-				
  193
+
190 194
 		if(ua != null && ua.isHashCorrect(key)) {
191  
-			
  195
+
192 196
 			PersistenceManager pm = PMF.getPersistenceManager();
193 197
 			Transaction tx = pm.currentTransaction();
194  
-			
  198
+
195 199
 			User u = null;
196  
-			
  200
+
197 201
 			try {
198 202
 				tx.begin();
199 203
 				u = (User)PMF.getObject(pm, User.class, "email", email);
200  
-				
201  
-				if(u != null) {					
  204
+
  205
+				if(u != null) {
202 206
 					u.setAuth("y");
203 207
 				}
204 208
 				tx.commit();
@@ -208,13 +212,13 @@ public boolean authenticateUser(String email, String key){
208 212
 					tx.rollback();
209 213
 				}
210 214
 				pm.close();
211  
-				
  215
+
212 216
 				PMF.deleteObjectById(UserAuth.class, "email", email);
213 217
 			}
214  
-			
  218
+
215 219
 			if(u != null) {
216 220
 				return true;
217  
-			}			
  221
+			}
218 222
 		}
219 223
 		return false;
220 224
 	}
@@ -238,25 +242,25 @@ protected PasswordAuthentication getPasswordAuthentication() {
238 242
 		InternetAddress addressFrom = new InternetAddress(from);
239 243
 		addressFrom.setPersonal(fromDisplay);
240 244
 		msg.setFrom(addressFrom);
241  
-	
242  
-		
  245
+
  246
+
243 247
 		StringTokenizer st = new StringTokenizer (to,",");
244  
-		
  248
+
245 249
 		InternetAddress[] rcps = new InternetAddress[st.countTokens()];
246 250
 		int idx = 0;
247  
-		
  251
+
248 252
 		while (st.hasMoreTokens())
249 253
 		{
250 254
 			InternetAddress addressTo = new InternetAddress(st.nextToken());
251 255
 			rcps[idx++] = addressTo;
252  
-			
  256
+
253 257
 		}
254  
-		
  258
+
255 259
 		msg.setRecipients(Message.RecipientType.TO,rcps);
256  
-		
  260
+
257 261
 		msg.setSubject(subject);
258 262
 		msg.setContent(message, "text/html");
259 263
 		Transport.send(msg);
260  
-	}	
261  
-	
  264
+	}
  265
+
262 266
 }
38  BBSignup/src/main/java/bbsignup/src/Dump.java
@@ -11,41 +11,43 @@
11 11
 import bbsignup.model.User;
12 12
 
13 13
 public class Dump {
14  
-	
15  
-	
  14
+
  15
+
16 16
 	public static void main(String[] args) throws IOException {
17  
-		
  17
+
18 18
 		if(args.length == 0) {
19 19
 			System.out.println("filename must be provided");
20 20
 			return;
21 21
 		}
22  
-		
  22
+
23 23
 		BufferedWriter bw = new BufferedWriter(new FileWriter(new File(args[0])));
24  
-		
25  
-		
  24
+
  25
+
26 26
 		@SuppressWarnings("unchecked")
27 27
 		Collection<User> users = (Collection<User>) PMF.getDetachedObjects(User.class);
28  
-		
29  
-		
  28
+
  29
+
30 30
 		for(User user:users) {
31  
-			
  31
+
32 32
 			if(user.getAuth().equals("y")) {
33  
-				
  33
+
34 34
 				bw.write(user.getFirstName() + ":" + user.getEmail()+":");
35  
-				
  35
+
36 36
 				List<String> subs = user.getSubscriptions();
37  
-								
  37
+
38 38
 				for(Iterator<String> itr = subs.iterator(); itr.hasNext();) {
39 39
 					bw.write(itr.next() + ((itr.hasNext()) ? ",":""));
40 40
 				}
41  
-				
  41
+
42 42
 				bw.newLine();
43  
-				
44  
-				
  43
+
  44
+
45 45
 			}
46  
-			
  46
+
47 47
 		}
48  
-		
  48
+
  49
+		bw.close();
  50
+
49 51
 	}
50  
-	
  52
+
51 53
 }
51  BBSignup/src/main/java/servlets/MainServlet.java
@@ -15,56 +15,55 @@
15 15
 import bbsignup.model.UserAuth;
16 16
 import bbsignup.src.Controller;
17 17
 import bbsignup.src.PMF;
18  
-import bbsignup.src.Resource;
19 18
 
20 19
 /**
21 20
  * Servlet implementation class MainServlet
22 21
  */
23 22
 public class MainServlet extends HttpServlet {
24 23
 	private static final long serialVersionUID = 1L;
25  
-	
  24
+
26 25
 
27 26
 	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
28 27
 		// will store selected subscriptions
29 28
 		List<String> subs = new ArrayList<String>();
30  
-		
  29
+
31 30
 		HttpSession session = request.getSession();
32 31
 		Object o = SenatorContext.getSenators(this.getServletContext());
33  
-		
  32
+
34 33
 		String fname = null;
35 34
 		String lname = null;
36 35
 		String email = null;
37 36
 		String otherData = null;
38  
-		
  37
+
39 38
 		// if update exists in the session then the user already xists */
40 39
 		String update = (String)session.getAttribute("update");
41  
-		
  40
+
42 41
 		if(o != null) {
43  
-			fname = (String)request.getParameter("firstname");
44  
-			lname = (String)request.getParameter("lastname");
45  
-			email = (String)request.getParameter("email1");
46  
-			otherData = (String)request.getParameter("otherData");
47  
-			
  42
+			fname = request.getParameter("firstname");
  43
+			lname = request.getParameter("lastname");
  44
+			email = request.getParameter("email1");
  45
+			otherData = request.getParameter("otherData");
  46
+
48 47
 			/* this is a session variable stored from index.jsp, verifies
49 48
 			 * that the user is following proper workflow */
50 49
 			@SuppressWarnings("unchecked")
51 50
 			List<Senator> senators = (List<Senator>)o;
52  
-			
53  
-			// if the button to select all senators has been selected 
  51
+
  52
+			// if the button to select all senators has been selected
54 53
 			if(request.getParameter("cb_all") != null) {
55 54
 				subs.add("all");
56 55
 			}
57 56
 			else {
58 57
 				for(Senator senator:senators) {
59 58
 					String[] params = request.getParameterValues(senator.getOpenLegName());
60  
-					
  59
+
61 60
 					if(params != null) {
62 61
 						//it has been selected
63 62
 						subs.add(senator.getOpenLegName());
64 63
 					}
65 64
 				}
66 65
 			}
67  
-			
  66
+
68 67
 			//they didn't select anything, return back to index.jsp
69 68
 			if(subs.size() == 0) {
70 69
 				session.setAttribute("fn", fname);
@@ -74,24 +73,24 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
74 73
 				response.sendRedirect("index.jsp");
75 74
 				return;
76 75
 			}
77  
-			
  76
+
78 77
 			//they selected everything, change to 'all'
79 78
 			if(subs.size() == 62) {
80 79
 				subs.clear();
81 80
 				subs.add("all");
82 81
 			}
83  
-			
  82
+
84 83
 			Controller c = new Controller();
85 84
 			String message = null;
86 85
 			User u = new User(fname, lname, email, "n", (otherData.equals("yes") ? true:false));
87 86
 			u.setSubscriptions(subs);
88  
-			
  87
+
89 88
 			if(update == null) {
90 89
 				User cur = (User)PMF.getDetachedObject(User.class, "email", email);
91  
-				
  90
+
92 91
 				if(cur == null) {
93 92
 					UserAuth ua = new UserAuth(email);
94  
-					
  93
+
95 94
 					c.newUserEmail(email, ua.getHash());
96 95
 					PMF.persistObject(u, ua);
97 96
 					message = "<div class=\"good\" style=\"width:500px;\">" +
@@ -108,18 +107,18 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
108 107
 						"<br/><br/>" +
109 108
 						"</div>";
110 109
 				}
111  
-				
112  
-				
  110
+
  111
+
113 112
 			}
114 113
 			else {
115 114
 				String oldEmail = (String) session.getAttribute("oldemail");
116 115
 				u.setAuth("y");
117  
-				
  116
+
118 117
 				PMF.deleteObjects(new Class[] {UserAuth.class, User.class},
119 118
 						new String[] {"email","email"},
120 119
 						new String[] {oldEmail,oldEmail});
121 120
 				PMF.persistObject(u);
122  
-								
  121
+
123 122
 				message = "<div class=\"good\" style=\"width:500px;\">" +
124 123
 					"Your account has been successfully updated!  Thanks for using BillBuzz." +
125 124
 					"<br/><br/>" +
@@ -134,7 +133,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
134 133
 			session.setAttribute("e", null);
135 134
 			session.setAttribute("oldemail", null);
136 135
 			session.setAttribute("update", null);
137  
-			
  136
+
138 137
 			session.setAttribute("message", message);
139 138
 			response.sendRedirect("message.jsp");
140 139
 		}
@@ -142,7 +141,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
142 141
 			response.sendRedirect("index.jsp");
143 142
 		}
144 143
 	}
145  
-	
  144
+
146 145
 	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
147 146
 		doGet(request, response);
148 147
 	}

0 notes on commit 1439266

Please sign in to comment.
Something went wrong with that request. Please try again.