001: package vqwiki;
002:
003: import org.apache.log4j.Logger;
004:
005: /**
006: * Represents a single user account in a VQWiki members list.
007: *
008: * @author Robert E Brewer
009: * @version 0.1
010: */
011: public class WikiMember implements java.io.Serializable {
012:
013: private static final Logger logger = Logger
014: .getLogger(WikiMember.class);
015: private String userName;
016: private String email;
017: private String key;
018: private String password;
019:
020: /**
021: *
022: */
023: public WikiMember() {
024: this .key = NULL_KEY();
025: }
026:
027: /**
028: *
029: */
030: public WikiMember(String newUserName) {
031: this .userName = newUserName;
032: this .key = NULL_KEY();
033: }
034:
035: /**
036: *
037: */
038: public WikiMember(String newUserName, String newEmail) {
039: this .userName = newUserName;
040: this .email = newEmail;
041: this .key = NULL_KEY();
042: }
043:
044: /**
045: *
046: */
047: private String NULL_KEY() {
048: return "NULL";
049: }
050:
051: /**
052: *
053: */
054: private String CONFIRM_KEY() {
055: return "";
056: }
057:
058: /**
059: *
060: */
061: public String getUserName() {
062: return this .userName;
063: }
064:
065: /**
066: *
067: */
068: public void setUserName(String newUserName) {
069: this .userName = newUserName;
070: }
071:
072: /**
073: *
074: */
075: public String getEmail() {
076: return this .email;
077: }
078:
079: /**
080: *
081: */
082: public void setEmail(String newEmail) {
083: this .email = newEmail;
084: }
085:
086: /**
087: *
088: */
089: public void confirm() {
090: this .key = CONFIRM_KEY();
091: }
092:
093: /**
094: *
095: */
096: public boolean isConfirmed() {
097: if (this .key == null)
098: return false;
099: return (this .key.equals(CONFIRM_KEY()));
100: }
101:
102: /**
103: *
104: */
105: public boolean isPending() {
106: return (!CONFIRM_KEY().equals(this .key) && !this .NULL_KEY()
107: .equals(this .key));
108: }
109:
110: /**
111: *
112: */
113: public boolean checkKey(String keyToCheck) {
114: logger.debug("Checking that key '" + keyToCheck.trim() + "'=='"
115: + this .key.trim() + "' (" + keyToCheck.equals(this .key)
116: + ")");
117: return keyToCheck.trim().equals(this .key.trim());
118: }
119:
120: /**
121: *
122: */
123: public void setKey(String newKey) {
124: this .key = newKey;
125: }
126:
127: /**
128: *
129: */
130: public String getKey() {
131: return key;
132: }
133:
134: /**
135: *
136: */
137: public String getPassword() {
138: return password;
139: }
140:
141: /**
142: *
143: */
144: public void setPassword(String password) {
145: this .password = password;
146: }
147:
148: /**
149: *
150: */
151: public boolean isValidPassword(String password) {
152: return this .password.equals(password);
153: }
154:
155: /**
156: * Returns a string representation of the object.
157: * @return a string representation of the object.
158: */
159: public String toString() {
160: StringBuffer buffer = new StringBuffer();
161: buffer.append(this .getClass().getName());
162: buffer.append("[");
163: buffer.append("username=");
164: buffer.append(this .userName);
165: buffer.append(",email=");
166: buffer.append(this .email);
167: buffer.append(",key=");
168: buffer.append(this .key);
169: buffer.append(",confirmed=");
170: buffer.append(this .isConfirmed());
171: buffer.append("]");
172: return buffer.toString();
173: }
174: }
|