001: /**
002: * @author garethc
003: * 22/10/2002 13:20:38
004: */package vqwiki;
005:
006: import java.util.Random;
007: import java.util.ResourceBundle;
008: import java.net.MalformedURLException;
009: import javax.servlet.http.HttpServletRequest;
010: import org.apache.log4j.Logger;
011: import vqwiki.servlets.WikiServlet;
012: import vqwiki.utils.JSPUtils;
013: import vqwiki.utils.Utilities;
014:
015: public abstract class AbstractWikiMembers implements WikiMembers {
016:
017: protected String virtualWiki;
018: private static final Logger logger = Logger
019: .getLogger(AbstractWikiMembers.class);
020: private static final int KEY_LENGTH = 20;
021: private static Random rn = new Random();
022:
023: /**
024: * Confirms a member (that is, gives them the ability to set notifications and reminders)
025: * if the supplied key matches the key generated when the account was created. It is expected
026: * that another class or JSP page will call this function at the request of a user.
027: *
028: * @param username the name of the user to confirm
029: * @param key the key to compare to the key generated when the account was created
030: * @return boolean True if the user is in the list.
031: */
032: public boolean confirmMembership(String username, String key)
033: throws Exception {
034: WikiMember aMember = findMemberByName(username);
035: logger.debug("Confirming membership by key " + key + " for "
036: + aMember);
037: if (aMember.isConfirmed())
038: return true;
039: return false;
040: }
041:
042: /**
043: * Send the confirmation email to the member
044: */
045: protected void mailMember(String username,
046: HttpServletRequest request, WikiMember aMember, String email) {
047: ResourceBundle messages = ResourceBundle.getBundle(
048: "ApplicationResources", request.getLocale());
049: // Send an email to the requester with the generated key
050: logger.debug("Sending email to " + email);
051: StringBuffer buffer = new StringBuffer();
052: buffer.append(username);
053: buffer.append("\n");
054: buffer.append(messages.getString("mail.confirmation.body"));
055: buffer.append("\n\n");
056: String wikiServerHostname = Environment.getInstance()
057: .getStringSetting(
058: Environment.PROPERTY_WIKI_SERVER_HOSTNAME);
059: buffer.append(JSPUtils.createRootPath(request, virtualWiki,
060: wikiServerHostname));
061: buffer.append("Wiki");
062: buffer.append("?userName=");
063: buffer.append(JSPUtils.encodeURL(username));
064: buffer.append("&key=");
065: buffer.append(aMember.getKey());
066: buffer.append("&action=").append(WikiServlet.ACTION_MEMBER);
067: WikiMail mailer = WikiMail.getInstance();
068: String replyAddress = Environment.getInstance()
069: .getStringSetting(Environment.PROPERTY_REPLY_ADDRESS);
070: mailer.sendMail(replyAddress, email, messages
071: .getString("mail.confirmation.subject"), buffer
072: .toString());
073: }
074:
075: /**
076: * Create a new member with a random key
077: */
078: protected WikiMember createMember(String username, String email) {
079: // Generate a key to confirm the request
080: WikiMember aMember = new WikiMember(username, email);
081: byte b[] = new byte[KEY_LENGTH];
082: for (int i = 0; i < KEY_LENGTH; i++) {
083: b[i] = (byte) (rn.nextInt(26) + 65);
084: }
085: String newKey = new String(b);
086: aMember.setKey(newKey);
087: return aMember;
088: }
089: }
090:
091: // $Log$
092: // Revision 1.20 2006/04/24 18:07:18 studer
093: // Just a small change for making bugfix http://www.vqwiki.org/jira/browse/VQW-72 perfect.
094: //
095: // Revision 1.19 2006/04/23 07:52:28 wrh2
096: // Coding style updates (VQW-73).
097: //
098: // Revision 1.18 2006/04/22 07:39:36 studer
099: // Fixing http://www.vqwiki.org/jira/browse/VQW-72
100: //
101: // Revision 1.17 2006/04/19 08:31:58 wrh2
102: // Implement VQW-77 to remove hard-coding of action values.
103: //
104: // Revision 1.16 2006/04/12 21:01:56 studer
105: // fix for http://www.vqwiki.org/jira/browse/VQW-72
106: //
107: // Revision 1.15 2006/04/11 21:43:18 mvdkleijn
108: // fixes generation of confirmation link in email (VQW-72)
109: //
110: // Revision 1.14 2006/04/05 21:53:39 studer
111: // Small fix for Tomcat 5 <> 5.5 incompatibility.
112: //
113: // Revision 1.13 2003/10/05 05:07:30 garethc
114: // fixes and admin file encoding option + merge with contributions
115: //
116: // Revision 1.12 2003/09/21 20:52:43 garethc
117: // merge and typos
118: //
119: // Revision 1.11 2003/05/14 19:02:58 mrgadget4711
120: // MOD: Internationalization extended
121: //
122: // Revision 1.10 2003/04/28 03:54:41 garethc
123: // beginning of work on import tool
124: //
125: // Revision 1.9 2003/04/15 23:10:57 garethc
126: // lucene fixes
127: //
128: // Revision 1.8 2003/04/09 20:44:09 garethc
129: // package org
130: //
131: // Revision 1.7 2003/02/18 20:48:07 garethc
132: // 2.4.0 RC3
133: //
134: // Revision 1.6 2003/01/07 23:54:39 garethc
135: // almost finished taglibs
136: //
137: // Revision 1.5 2003/01/07 03:11:51 garethc
138: // beginning of big cleanup, taglibs etc
139: //
140: // Revision 1.4 2002/12/08 20:58:58 garethc
141: // 2.3.6 almost ready
142: //
143: // Revision 1.3 2002/12/02 19:26:51 garethc
144: // fixes
145: //
146: // Revision 1.2 2002/11/11 22:19:23 garethc
147: // printable page
148: //
149: // Revision 1.1 2002/10/22 20:14:32 garethc
150: // 2.2.0
151: //
|