001: /*
002: ====================================================================
003: Project Name: bugtracker
004: File Name: /src/com/espada/bugtracker/servlets/ForgotPassword.java
005: Author: Kishan Peiris <kishan@espadanet.com>
006: Description: Search for the password and reply and email
007: CVS Repository: goliath:/projects/repository/cvsroot/
008: CVS Module: bugtracker
009: Version: CVS $Id: $
010: ====================================================================
011:
012: ====================================================================
013: Copyright (C) 2001, Silk Road (Pvt.) Ltd.
014: ====================================================================
015: */
016:
017: package com.espada.bugtracker.servlets;
018:
019: import com.sr.espada.se.util.config.*;
020: import com.sr.espada.se.util.mail.*;
021:
022: // webmacro resources
023: import org.webmacro.*;
024: import org.webmacro.broker.*;
025: import org.webmacro.resource.*;
026: import org.webmacro.servlet.WebContext;
027:
028: // servlet libraries
029: import javax.servlet.http.*;
030: import javax.servlet.*;
031:
032: // java library
033: import javax.mail.MessagingException;
034:
035: // bugtracker java apps
036: import com.espada.bugtracker.app.*;
037:
038: public class ForgotPassword extends BTServlet {
039:
040: /**
041: * This is the core WebMacro interface which we use to create Contexts,
042: * load Templates, and begin other WebMacro operations.
043: */
044:
045: /** the default template to use **/
046: private String defaultTemplate = "forgotPassword.wm";
047: private String error = "errorMesg.wm";
048: private String errorTemplate = defaultTemplate;
049:
050: /********************************** Start Of Method findPasswd *************************************************/
051: /** Find a user's password...*/
052:
053: private void findPasswd(HttpServletRequest request,
054: HttpServletResponse response, WebContext c) {
055:
056: HttpSession session = request.getSession();
057:
058: String errorId = "";
059:
060: if (request.getParameter("action") != null) {
061: errorTemplate = error;
062:
063: String userEmail = request.getParameter("eml");
064:
065: String msg = User.forgotPassword(userEmail,
066: getServletContext());
067:
068: if (msg == null) {
069:
070: // value 5 is included in erroMesg.wm file, and its used for a check statement...
071: errorId = "5";
072:
073: c.put("errorId", errorId);
074:
075: c.put("eml", userEmail);
076: } else {
077: try {
078: SimpleEmail SE = new SimpleEmail(ConfigFactory
079: .getInstance());
080: SE.setMsg(msg);
081: SE.setFrom("no-reply@infomutual.com",
082: "BUGTRACKER APPLICATION");
083: SE.addTo(userEmail, userEmail);
084: SE.setSubject("Password Retrieval");
085: SE.send();
086: errorId = "6";
087: } catch (MessagingException e) {
088: errorId = "5";
089: } catch (ConfigFileMissingException ex) {
090: System.out.println("File Missing....!");
091: }
092:
093: c.put("errorId", errorId);
094: c.put("eml", userEmail);
095: }
096: } else {
097: errorTemplate = defaultTemplate;
098: }
099:
100: } //end of method
101:
102: /********************************** End Of Method findPasswd *************************************************/
103:
104: /**
105: */
106: public void doGet(HttpServletRequest req, HttpServletResponse resp) {
107:
108: try {
109: try {
110:
111: // create a context for the current request
112: WebContext c = _wm.getWebContext(req, resp);
113:
114: /******************************************************************/
115:
116: String s = "http://" + req.getServerName();
117: c.put("serverName", s);
118: c.put("loggedIn", String.valueOf(new Boolean(false)));
119:
120: /*****************************************************************/
121:
122: // forgot password method....
123: findPasswd(req, resp, c);
124:
125: // get the template we intend to execute
126: Template t = _wm.getTemplate(errorTemplate);
127:
128: // Create FastWriter for fast output encoding
129: FastWriter fw = new FastWriter(resp.getOutputStream(),
130: resp.getCharacterEncoding());
131:
132: // write the template to the output, using our context
133: t.write(fw, c);
134: fw.close();
135:
136: } catch (org.webmacro.NotFoundException e) {
137:
138: FastWriter out = new FastWriter(resp.getOutputStream(),
139: resp.getCharacterEncoding());
140:
141: out
142: .write("ERROR! Could not locate template "
143: + errorTemplate
144: + ", check that your template path is set properly in WebMacro.properties");
145:
146: out.close();
147:
148: } catch (org.webmacro.ContextException e) {
149:
150: FastWriter out = new FastWriter(resp.getOutputStream(),
151: resp.getCharacterEncoding());
152:
153: out
154: .write("ERROR! Could not locate required data in the Context.");
155:
156: out.close();
157:
158: }
159: } catch (java.io.IOException e) {
160:
161: // what else can we do?
162: System.out
163: .println("ERROR: IOException while writing to servlet output stream.");
164:
165: }
166:
167: } //end of method
168:
169: } //end of class
|