KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > forum > actions > ForgotPassword


1 /* Copyright 2000-2005 Anders Hovmöller
2  *
3  * The person or persons who have associated their work with
4  * this document (the "Dedicator") hereby dedicate the entire
5  * copyright in the work of authorship identified below (the
6  * "Work") to the public domain.
7  *
8  * Dedicator makes this dedication for the benefit of the
9  * public at large and to the detriment of Dedicator's heirs
10  * and successors. Dedicator intends this dedication to be an
11  * overt act of relinquishment in perpetuity of all present
12  * and future rights under copyright law, whether vested or
13  * contingent, in the Work. Dedicator understands that such
14  * relinquishment of all rights includes the relinquishment of
15  * all rights to enforce (by lawsuit or otherwise) those
16  * copyrights in the Work.
17  *
18  * Dedicator recognizes that, once placed in the public
19  * domain, the Work may be freely reproduced, distributed,
20  * transmitted, used, modified, built upon, or otherwise
21  * exploited by anyone for any purpose, commercial or non-
22  * commercial, and in any way, including by methods that have
23  * not yet been invented or conceived.
24  */

25
26 package net.killingar.forum.actions;
27
28 import java.util.Properties JavaDoc;
29
30 public class ForgotPassword
31     extends net.killingar.actions.email.Send
32     implements webwork.action.SessionAware
33 {
34     String JavaDoc
35         smtpserver,
36         subject,
37         from,
38         forumAddress,
39         username;
40
41     protected net.killingar.forum.internal.managers.ForumManager manager;
42
43     // SessionAware implementation ------------------------------------
44
public void setSession(java.util.Map JavaDoc session)
45     {
46         // Get model
47
try
48         {
49             synchronized (session)
50             {
51                 manager = (net.killingar.forum.internal.managers.ForumManager)session.get("manager");
52                 if (manager == null)
53                 {
54                     manager = new net.killingar.forum.internal.managers.ForumManager();
55                     session.put("manager", manager);
56                 }
57             }
58         }
59         catch (Exception JavaDoc e)
60         {
61             addErrorMessage("failed to initialize forum manager, exception thrown ("+e.toString()+")");
62         }
63     }
64
65     public void setUsername(String JavaDoc in) { username = in; }
66
67     public void doValidation()
68     {
69         Properties JavaDoc p = net.killingar.Utils.getProperties();
70
71         smtpserver = p.getProperty(getClass().getName()+".smtp.server");
72         subject = p.getProperty(getClass().getName()+".smtp.subject");
73         from = p.getProperty(getClass().getName()+".smtp.from");
74         forumAddress = p.getProperty("net.killingar.forum.address");
75
76         if (forumAddress == null || forumAddress.length() == 0)
77             addErrorMessage("net.killingar.forum.address not set");
78         if (smtpserver == null || smtpserver.length() == 0)
79             addErrorMessage(getClass().getName()+".smtp.server not set");
80         if (subject == null || subject.length() == 0)
81             addErrorMessage(getClass().getName()+".smtp.subject not set");
82         if (from == null || from.length() == 0)
83             addErrorMessage(getClass().getName()+".smtp.from not set");
84     }
85
86     public String JavaDoc doExecute()
87     {
88         try
89         {
90             if (username == null)
91                 return INPUT;
92
93             //setUsername();
94
//setPassword();
95
setSmtpServer(smtpserver);
96             setSubject(subject);
97             setFrom(from);
98
99             String JavaDoc foo = manager.getNewPasswordKey(username);
100
101             String JavaDoc body =
102                 "This e-mail is sent to you from SKForum at "+forumAddress+" because someone filled in that you had forgotten your password.\n\n"+
103
104                 "If you did not do this, just ignore this email. Your old password will continue to work until you use the following code to set a new one.\n"+
105                 "The code to set a new password is: "+foo+"\n"+
106                 "Go to "+forumAddress+"/public/SetPassword.action?newPasswordKey="+foo+" to change your password now.";
107
108             setTo(manager.getSecretEmail(username));
109
110             setBody(body);
111
112             return super.doExecute();
113         }
114         catch (Exception JavaDoc exception)
115         {
116             addErrorMessage("Sending password to user failed, exception thrown (" + exception.toString() + ")");
117             exception.printStackTrace();
118             return ERROR;
119         }
120     }
121 }
Popular Tags