1 25 package org.snipsnap.user; 26 27 import org.snipsnap.app.Application; 28 import org.snipsnap.config.Configuration; 29 import org.snipsnap.snip.SnipLink; 30 import org.snipsnap.render.macro.list.Linkable; 31 32 import java.sql.Timestamp ; 33 34 40 public class User implements Linkable { 41 private String applicationOid; 42 private String login; 43 private String passwd; 44 private String email; 45 private String status; 46 private Roles roles; 47 private Timestamp lastLogin, lastAccess, lastLogout; 49 private Timestamp cTime, mTime; 51 52 private boolean guest = false; 53 private boolean nonUser = false; 54 55 public User() { 56 this("", "", ""); 57 } 58 59 public User(String login, String passwd, String email) { 60 this.login = login; 61 setPasswd(passwd); 62 setEmail(email); 63 } 64 65 public void setApplication(String applicationOid) { 66 this.applicationOid = applicationOid; 67 } 68 69 public String getApplication() { 70 return applicationOid; 71 } 72 73 74 public Timestamp getCTime() { 75 return cTime; 76 } 77 78 public void setCTime(Timestamp cTime) { 79 this.cTime = cTime; 80 } 81 82 public Timestamp getMTime() { 83 return mTime; 84 } 85 86 public void setMTime(Timestamp mTime) { 87 this.mTime = mTime; 88 } 89 90 95 public void lastAccess() { 96 this.lastAccess = new Timestamp (new java.util.Date ().getTime()); 97 } 100 101 public Timestamp getLastLogout() { 102 return lastLogout; 103 } 104 105 public void setLastLogout(Timestamp lastLogout) { 106 this.lastLogout = lastLogout; 109 } 110 111 public Timestamp getLastAccess() { 112 return this.lastAccess; 113 } 114 115 public void setLastAccess(Timestamp lastAccess) { 116 this.lastAccess = lastAccess; 117 } 118 119 public Timestamp getLastLogin() { 120 return lastLogin; 121 } 122 123 public void lastLogin() { 124 setLastLogin(new Timestamp (new java.util.Date ().getTime())); 125 } 126 127 public void setLastLogin(Timestamp lastLogin) { 128 this.lastLogin = lastLogin; 129 } 130 131 public void setStatus(String status) { 132 this.status = status; 133 return; 134 } 135 136 public String getStatus() { 137 if (null == status) { 138 status = "not set"; 139 } 140 return status; 141 } 142 143 public void setEmail(String email) { 144 this.email = email; 145 } 146 147 public String getEmail() { 148 return email; 149 } 150 151 public void setPasswd(String passwd) { 154 if (passwd != null && passwd.length() > 30) { 155 this.passwd = passwd; 156 } else { 157 this.passwd = Digest.getDigest(passwd); 158 } 159 } 160 161 public String getPasswd() { 162 return passwd; 163 } 164 165 169 public void setLogin(String login) { 170 this.login = login; 171 } 172 173 public String getLogin() { 174 return login; 175 } 176 177 public void setRoles(Roles roles) { 178 this.roles = roles; 179 return; 180 } 181 182 public Roles getRoles() { 183 if (null == roles) { 184 roles = new Roles(); 185 } 186 return roles; 187 } 188 189 public boolean isAdmin() { 190 Application app = Application.get(); 191 Configuration config = app.getConfiguration(); 192 return (config.getAdminLogin() != null && config.getAdminLogin().equals(login)) 193 || getRoles().contains(Roles.ADMIN); 194 } 195 196 public void setGuest(boolean guest) { 197 this.guest = guest; 198 } 199 200 public boolean isGuest() { 201 return guest; 202 } 203 204 public void setNonUser(boolean nonUser) { 205 this.nonUser = nonUser; 206 } 207 208 public boolean isNonUser() { 209 return nonUser; 210 } 211 212 public int hashCode() { 213 return getLogin().hashCode(); 214 } 215 216 public boolean equals(Object obj) { 217 if (obj instanceof User && obj != null && this.getLogin() != null) { 218 return this.getLogin().equals(((User) obj).getLogin()); 219 } 220 return false; 221 } 222 223 public String toString() { 224 return "User[" + login + "," + (passwd != null ? "pass set" : "no pass") + "," + email + "," + status + "," + roles + "]"; 225 } 226 227 public String getLink() { 228 if (isNonUser()) { 229 StringBuffer tmp = new StringBuffer (); 230 tmp.append("<a HREF=\""); 231 tmp.append(getEmail()); 232 tmp.append("\">"); 233 tmp.append(getLogin()); 234 tmp.append("</a>"); 235 return tmp.toString(); 236 } else if (isGuest()) { 237 return "Guest"; 238 } else { 239 return SnipLink.createLink(getLogin()); 240 } 241 } 242 243 } | Popular Tags |