KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > espada > bugtracker > servlets > ForgotPassword


1 /*
2 ====================================================================
3 Project Name: bugtracker
4 File Name: /src/com/espada/bugtracker/servlets/ForgotPassword.java
5 Author: Kishan Peiris <kishan@espadanet.com>
6 Description: Search for the password and reply and email
7 CVS Repository: goliath:/projects/repository/cvsroot/
8 CVS Module: bugtracker
9 Version: CVS $Id: $
10 ====================================================================
11
12 */

13
14 package com.espada.bugtracker.servlets;
15
16
17 // webmacro resources
18
import org.webmacro.*;
19  import org.webmacro.broker.*;
20  import org.webmacro.resource.*;
21  import org.webmacro.servlet.WebContext;
22
23 // servlet libraries
24
import javax.servlet.http.*;
25  import javax.servlet.*;
26
27 // java library
28
import javax.mail.MessagingException JavaDoc;
29
30 // bugtracker java apps
31
import com.espada.bugtracker.app.*;
32  import com.espada.bugtracker.util.*;
33
34
35 public class ForgotPassword extends BTServlet
36 {
37
38    /**
39      * This is the core WebMacro interface which we use to create Contexts,
40      * load Templates, and begin other WebMacro operations.
41      */

42
43
44    /** the default template to use **/
45    private String JavaDoc defaultTemplate = "forgotPassword.wm";
46    private String JavaDoc error = "errorMesg.wm";
47    private String JavaDoc errorTemplate = defaultTemplate;
48
49
50
51    /********************************** Start Of Method findPasswd *************************************************/
52    /** Find a user's password...*/
53
54    private void findPasswd(HttpServletRequest request, HttpServletResponse response,WebContext c)
55    {
56
57         HttpSession session = request.getSession();
58
59         String JavaDoc errorId = "";
60
61         if (request.getParameter("action") != null )
62         {
63             errorTemplate = error;
64
65             String JavaDoc userEmail = request.getParameter("eml");
66
67             String JavaDoc msg = User.forgotPassword(userEmail,getServletContext());
68
69             if (msg == null)
70             {
71
72              // value 5 is included in erroMesg.wm file, and its used for a check statement...
73
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 JavaDoc) 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 JavaDoc 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    } //end of method
107

108    /********************************** End Of Method findPasswd *************************************************/
109
110
111
112    /**
113      */

114    public void doGet(HttpServletRequest req, HttpServletResponse resp)
115    {
116
117        try
118        {
119          try
120          {
121
122             // create a context for the current request
123
WebContext c = _wm.getWebContext(req,resp);
124
125             /******************************************************************/
126
127             String JavaDoc s = "http://" + req.getServerName();
128             c.put("serverName", s);
129             c.put("loggedIn",String.valueOf(new Boolean JavaDoc(false)));
130
131             /*****************************************************************/
132
133             // forgot password method....
134
findPasswd(req,resp,c);
135
136
137             // get the template we intend to execute
138
Template t = _wm.getTemplate(errorTemplate);
139
140             // Create FastWriter for fast output encoding
141
FastWriter fw = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding());
142
143
144             // write the template to the output, using our context
145
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 JavaDoc e)
171         {
172
173           // what else can we do?
174
System.out.println("ERROR: IOException while writing to servlet output stream.");
175
176         }
177
178     } //end of method
179

180
181 } //end of class
182

183
Popular Tags