1 25 26 package net.killingar.forum.actions; 27 28 import java.util.Properties ; 29 30 public class ForgotPassword 31 extends net.killingar.actions.email.Send 32 implements webwork.action.SessionAware 33 { 34 String 35 smtpserver, 36 subject, 37 from, 38 forumAddress, 39 username; 40 41 protected net.killingar.forum.internal.managers.ForumManager manager; 42 43 public void setSession(java.util.Map session) 45 { 46 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 e) 60 { 61 addErrorMessage("failed to initialize forum manager, exception thrown ("+e.toString()+")"); 62 } 63 } 64 65 public void setUsername(String in) { username = in; } 66 67 public void doValidation() 68 { 69 Properties 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 doExecute() 87 { 88 try 89 { 90 if (username == null) 91 return INPUT; 92 93 setSmtpServer(smtpserver); 96 setSubject(subject); 97 setFrom(from); 98 99 String foo = manager.getNewPasswordKey(username); 100 101 String 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 exception) 115 { 116 addErrorMessage("Sending password to user failed, exception thrown (" + exception.toString() + ")"); 117 exception.printStackTrace(); 118 return ERROR; 119 } 120 } 121 } | Popular Tags |