1 13 14 package com.espada.bugtracker.servlets; 15 16 17 import org.webmacro.*; 19 import org.webmacro.broker.*; 20 import org.webmacro.resource.*; 21 import org.webmacro.servlet.WebContext; 22 23 import javax.servlet.http.*; 25 import javax.servlet.*; 26 27 import javax.mail.MessagingException ; 29 30 import com.espada.bugtracker.app.*; 32 import com.espada.bugtracker.util.*; 33 34 35 public class ForgotPassword extends BTServlet 36 { 37 38 42 43 44 45 private String defaultTemplate = "forgotPassword.wm"; 46 private String error = "errorMesg.wm"; 47 private String errorTemplate = defaultTemplate; 48 49 50 51 52 53 54 private void findPasswd(HttpServletRequest request, HttpServletResponse response,WebContext c) 55 { 56 57 HttpSession session = request.getSession(); 58 59 String errorId = ""; 60 61 if (request.getParameter("action") != null ) 62 { 63 errorTemplate = error; 64 65 String userEmail = request.getParameter("eml"); 66 67 String msg = User.forgotPassword(userEmail,getServletContext()); 68 69 if (msg == null) 70 { 71 72 errorId = "5"; 74 75 c.put("errorId",errorId); 76 77 c.put("eml",userEmail); 78 } 79 else 80 { 81 try 82 { 83 SimpleEmail SE = new SimpleEmail((String ) PropertyFactory.getInstance().get("bugtracker.server.mailserver")); 84 SE.setMsg(msg); 85 SE.setFrom("no-reply@infomutual.com", "BUGTRACKER APPLICATION"); 86 SE.addTo(userEmail,userEmail); 87 SE.setSubject("Password Retrieval"); 88 SE.send(); 89 errorId="6"; 90 } 91 catch (MessagingException e) 92 { 93 errorId="5"; 94 } 95 96 c.put("errorId",errorId); 97 c.put("eml",userEmail); 98 } 99 } 100 else 101 { 102 errorTemplate = defaultTemplate; 103 } 104 105 106 } 108 109 110 111 112 114 public void doGet(HttpServletRequest req, HttpServletResponse resp) 115 { 116 117 try 118 { 119 try 120 { 121 122 WebContext c = _wm.getWebContext(req,resp); 124 125 126 127 String s = "http://" + req.getServerName(); 128 c.put("serverName", s); 129 c.put("loggedIn",String.valueOf(new Boolean (false))); 130 131 132 133 findPasswd(req,resp,c); 135 136 137 Template t = _wm.getTemplate(errorTemplate); 139 140 FastWriter fw = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding()); 142 143 144 t.write(fw, c); 146 fw.close(); 147 148 } 149 catch (org.webmacro.NotFoundException e) 150 { 151 152 FastWriter out = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding()); 153 154 out.write("ERROR! Could not locate template " + errorTemplate + ", check that your template path is set properly in WebMacro.properties"); 155 156 out.close(); 157 158 } 159 catch (org.webmacro.ContextException e) 160 { 161 162 FastWriter out = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding()); 163 164 out.write("ERROR! Could not locate required data in the Context."); 165 166 out.close(); 167 168 } 169 } 170 catch (java.io.IOException e) 171 { 172 173 System.out.println("ERROR: IOException while writing to servlet output stream."); 175 176 } 177 178 } 180 181 } 183 | Popular Tags |