User.java
Upload User: gdxydsw
Upload Date: 2019-01-29
Package Size: 16721k
Code Size: 17k
Category:

Java Develop

Development Platform:

Java

  1. /*
  2.  * Copyright (c) JForum Team
  3.  * All rights reserved.
  4.  * 
  5.  * Redistribution and use in source and binary forms, 
  6.  * with or without modification, are permitted provided 
  7.  * that the following conditions are met:
  8.  * 
  9.  * 1) Redistributions of source code must retain the above 
  10.  * copyright notice, this list of conditions and the 
  11.  * following  disclaimer.
  12.  * 2)  Redistributions in binary form must reproduce the 
  13.  * above copyright notice, this list of conditions and 
  14.  * the following disclaimer in the documentation and/or 
  15.  * other materials provided with the distribution.
  16.  * 3) Neither the name of "Rafael Steil" nor 
  17.  * the names of its contributors may be used to endorse 
  18.  * or promote products derived from this software without 
  19.  * specific prior written permission.
  20.  * 
  21.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
  22.  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
  23.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
  24.  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
  25.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  26.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
  27.  * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
  29.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  30.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  31.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
  32.  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
  33.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
  34.  * IN CONTRACT, STRICT LIABILITY, OR TORT 
  35.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
  36.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
  37.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  38.  * 
  39.  * This file creating date: Feb 17, 2003 / 10:25:04 PM
  40.  * The JForum Project
  41.  * http://www.jforum.net 
  42.  * 
  43.  * $Id: User.java,v 1.21 2007/07/25 03:08:15 rafaelsteil Exp $
  44.  */
  45. package net.jforum.entities;
  46. import java.io.Serializable;
  47. import java.text.SimpleDateFormat;
  48. import java.util.ArrayList;
  49. import java.util.Date;
  50. import java.util.HashMap;
  51. import java.util.List;
  52. import java.util.Map;
  53. import net.jforum.SessionFacade;
  54. import net.jforum.util.preferences.ConfigKeys;
  55. import net.jforum.util.preferences.SystemGlobals;
  56. /**
  57.  * Represents a single user in the system.
  58.  * An user is every person which uses the forum. Well,
  59.  * every registered user. Anonymous users does not have
  60.  * a specific ID, for example. This class contains all information
  61.  * about some user configuration options and preferences.
  62.  * 
  63.  * @author Rafael Steil
  64.  */
  65. public class User implements Serializable
  66. {
  67. private int id;
  68. private int themeId;
  69. private int level;
  70. private int totalPosts;
  71. private boolean attachSignatureEnabled = true;
  72. private int rankId = 1;
  73. private boolean htmlEnabled = true;
  74. private boolean bbCodeEnabled = true;
  75. private boolean smiliesEnabled = true;
  76. private boolean avatarEnabled = true;
  77. private boolean privateMessagesEnabled = true;
  78. private boolean viewOnlineEnabled = true;
  79. private boolean notifyPrivateMessagesEnabled = true;
  80. private boolean notifyOnMessagesEnabled = true;
  81. private boolean notifyAlways;
  82. private boolean notifyText;
  83. private String username;
  84. private String password;
  85. private Date lastVisit;
  86. private Date registrationDate;
  87. private String avatar;
  88. private boolean isExternalAvatar;
  89. private String email;
  90. private String icq;
  91. private String webSite;
  92. private String from;
  93. private String signature;
  94. private String aim;
  95. private String yim;
  96. private String msnm; 
  97. private String occupation;
  98. private String interests;
  99. private String biography;
  100. private String gender;
  101. private String timeZone;
  102. private String lang;
  103. private String dateFormat;
  104. private boolean viewEmailEnabled = true;
  105. private List groupsList;
  106. private int privateMessagesCount;
  107. private KarmaStatus karma;
  108. private int active;
  109. private String activationKey;
  110. private int deleted;
  111. private String firstName;
  112. private String lastName;
  113. private Map extra = new HashMap();
  114. public User(int userId)
  115. {
  116. this.id = userId;
  117. }
  118. /**
  119.  * Default Constructor
  120.  */
  121. public User() 
  122. {
  123. this.groupsList = new ArrayList(); 
  124. }
  125. public void addExtra(String name, Object value)
  126. {
  127. this.extra.put(name, value);
  128. }
  129. public Object getExtra(String name)
  130. {
  131. return this.extra.get(name);
  132. }
  133. public void setFirstName(String name)
  134. {
  135. this.firstName = name;
  136. }
  137. public String getFirstName()
  138. {
  139. return this.firstName;
  140. }
  141. public void setLastName(String name)
  142. {
  143. this.lastName = name;
  144. }
  145. public String getLastNmame()
  146. {
  147. return this.lastName;
  148. }
  149. public String getName()
  150. {
  151. return this.firstName + " " + this.lastName;
  152. }
  153. public boolean isDeleted() {
  154. return this.deleted == 1;
  155. }
  156. public void setDeleted(int deleted){
  157. this.deleted = deleted;
  158. }
  159. /**
  160.  * Gets the AIM identification
  161.  * 
  162.  * @return String with the AIM ID
  163.  */
  164. public String getAim() {
  165. return this.aim;
  166. }
  167. /**
  168.  * Gets the avatar of the user
  169.  * 
  170.  * @return String with the avatar
  171.  */
  172. public String getAvatar() {
  173. return this.avatar;
  174. }
  175. /**
  176.  * Checks if avatar is enabled
  177.  * 
  178.  * @return boolean value
  179.  */
  180. public boolean isAvatarEnabled() {
  181. return this.avatarEnabled;
  182. }
  183. /**
  184.  * Checks if BB code is enabled
  185.  * 
  186.  * @return boolean value
  187.  */
  188. public boolean isBbCodeEnabled() {
  189. return this.bbCodeEnabled;
  190. }
  191. /**
  192.  * Gets the format to represent dates and time
  193.  * 
  194.  * @return String with the format
  195.  */
  196. public String getDateFormat() {
  197. return this.dateFormat;
  198. }
  199. /**
  200.  * Gets the user email
  201.  * 
  202.  * @return String with the email
  203.  */
  204. public String getEmail() {
  205. return this.email;
  206. }
  207. /**
  208.  * Gets the user location ( where he lives )
  209.  * 
  210.  * @return String with the location
  211.  */
  212. public String getFrom() {
  213. return this.from;
  214. }
  215. /**
  216.  * Gets the user gender
  217.  * 
  218.  * @return String value. Possible values are <code>M</code> or <code>F</code>
  219.  */
  220. public String getGender() {
  221. return this.gender;
  222. }
  223. /**
  224.  * Checks if HTML code is enabled by default in user messages
  225.  * 
  226.  * @return boolean value
  227.  */
  228. public boolean isHtmlEnabled() {
  229. return this.htmlEnabled;
  230. }
  231. /**
  232.  * Gets the ICQ UIM
  233.  * 
  234.  * @return String with the UIN
  235.  */
  236. public String getIcq() {
  237. return this.icq;
  238. }
  239. /**
  240.  * Gets the user id
  241.  * 
  242.  * @return int value with the id
  243.  */
  244. public int getId() {
  245. return this.id;
  246. }
  247. /**
  248.  * Gets the user interests
  249.  * 
  250.  * @return String literal
  251.  */
  252. public String getInterests() {
  253. return this.interests;
  254. }
  255. /**
  256.  * Gets the user language
  257.  * 
  258.  * @return String value with the language chosen
  259.  */
  260. public String getLang() {
  261. return this.lang;
  262. }
  263. /**
  264.  * Gets the last visit time the user was in the forum
  265.  * 
  266.  * @return long value representing the time
  267.  */
  268. public Date getLastVisit() {
  269. return this.lastVisit;
  270. }
  271. /**
  272.  * Gets the user leve
  273.  * 
  274.  * @return int value with the level
  275.  */
  276. public int getLevel() {
  277. return this.level;
  278. }
  279. /**
  280.  * Checks if notification of new private messages is enabled
  281.  * 
  282.  * @return boolean value
  283.  */
  284. public boolean isNotifyPrivateMessagesEnabled() {
  285. return this.notifyPrivateMessagesEnabled;
  286. }
  287. /**
  288.  * Gets the OCC 
  289.  * 
  290.  * @return String
  291.  */
  292. public String getOccupation() {
  293. return this.occupation;
  294. }
  295. /**
  296.  * Gets the user password
  297.  * 
  298.  * @return String with the password ( in plain/text )
  299.  */
  300. public String getPassword() {
  301. return this.password;
  302. }
  303. /**
  304.  * Checks if user permits other people to sent private messages to him
  305.  * 
  306.  * @return boolean value
  307.  */
  308. public boolean isPrivateMessagesEnabled() {
  309. return this.privateMessagesEnabled;
  310. }
  311. /**
  312.  * Gets the ranking ID of the user
  313.  * 
  314.  * @return int
  315.  */
  316. public int getRankId() {
  317. return this.rankId;
  318. }
  319. /**
  320.  * Gets the registration date of the user
  321.  * 
  322.  * @return String value with the registration date
  323.  */
  324. public String getRegistrationDate() 
  325. {
  326. SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
  327. return df.format(this.registrationDate);
  328. }
  329. /**
  330.  * Gets the user signature
  331.  * 
  332.  * @return String literal with the signature
  333.  */
  334. public String getSignature() {
  335. return this.signature;
  336. }
  337. /**
  338.  * Checks if smilies are enabled
  339.  * 
  340.  * @return boolean value
  341.  */
  342. public boolean isSmiliesEnabled() {
  343. return this.smiliesEnabled;
  344. }
  345. /**
  346.  * Gets the id of the theme chosen by the user
  347.  * 
  348.  * @return int value with the theme ID
  349.  */
  350. public int getThemeId() {
  351. return this.themeId;
  352. }
  353. /**
  354.  * Gets the timezone
  355.  * 
  356.  * @return String value with the timezone
  357.  */
  358. public String getTimeZone() {
  359. return this.timeZone;
  360. }
  361. /**
  362.  * Gets the total number of messages posted by the user
  363.  * 
  364.  * @return int value with the total of messages
  365.  */
  366. public int getTotalPosts() {
  367. return this.totalPosts;
  368. }
  369. /**
  370.  * Gets the username
  371.  * 
  372.  * @return String with the username
  373.  */
  374. public String getUsername() {
  375. return this.username;
  376. }
  377. /**
  378.  * Checks if the user permits other people to see he online
  379.  * 
  380.  * @return boolean value
  381.  */
  382. public boolean isViewOnlineEnabled() {
  383. return this.viewOnlineEnabled;
  384. }
  385. /**
  386.  * Gets the user website address
  387.  * 
  388.  * @return String with the URL
  389.  */
  390. public String getWebSite() {
  391. return this.webSite;
  392. }
  393. /**
  394.  * Gets the Yahoo messenger ID
  395.  * 
  396.  * @return String with the ID
  397.  */
  398. public String getYim() {
  399. return this.yim;
  400. }
  401. /**
  402.  * Is the user's email authenticated?
  403.  * 
  404.  * @return integer 1 if true
  405.  */
  406. public boolean isActive(){
  407. return this.active == 1;
  408. }
  409. /**
  410.  * Gets the Yahoo messenger ID
  411.  * 
  412.  * @return String with the activation key that is created during user registration
  413.  */
  414. public String getActivationKey(){
  415. return this.activationKey;
  416. }
  417. /**
  418.  * Sets the aim.
  419.  * 
  420.  * @param aim The aim ID to set
  421.  */
  422. public void setAim(String aim) {
  423. this.aim = aim;
  424. }
  425. /**
  426.  * Sets the avatar.
  427.  * 
  428.  * @param avatar The avatar to set
  429.  */
  430. public void setAvatar(String avatar) {
  431. this.avatar = avatar;
  432. if (avatar != null && avatar.toLowerCase().startsWith("http://")) {
  433. this.isExternalAvatar = true;
  434. }
  435. }
  436. /**
  437.  * Indicates if the avatar points to an external URL
  438.  * @return <code>true</code> if the avatar is some external image
  439.  */
  440. public boolean isExternalAvatar() {
  441. return this.isExternalAvatar;
  442. }
  443. /**
  444.  * Sets avatar status
  445.  * 
  446.  * @param avatarEnabled <code>true</code> or <code>false</code>
  447.  */
  448. public void setAvatarEnabled(boolean avatarEnabled) {
  449. this.avatarEnabled = avatarEnabled;
  450. }
  451. /**
  452.  * Sets the status for BB codes
  453.  * 
  454.  * @param bbCodeEnabled <code>true</code> or <code>false</code>
  455.  */
  456. public void setBbCodeEnabled(boolean bbCodeEnabled) {
  457. this.bbCodeEnabled = bbCodeEnabled;
  458. }
  459. /**
  460.  * Sets the date format.
  461.  * 
  462.  * @param dateFormat The date format to set
  463.  */
  464. public void setDateFormat(String dateFormat) {
  465. this.dateFormat = dateFormat;
  466. }
  467. /**
  468.  * Sets the email.
  469.  * 
  470.  * @param email The email to set
  471.  */
  472. public void setEmail(String email) {
  473. this.email = email;
  474. }
  475. /**
  476.  * Sets the user location ( where he lives )
  477.  * 
  478.  * @param from The location
  479.  */
  480. public void setFrom(String from) {
  481. this.from = from;
  482. }
  483. /**
  484.  * Sets the gender.
  485.  * 
  486.  * @param gender The gender to set. Possible values must be <code>M</code> or <code>F</code>
  487.  */
  488. public void setGender(String gender) {
  489. this.gender = gender;
  490. }
  491. /**
  492.  * Enable or not HTML code into the messages
  493.  * 
  494.  * @param htmlEnabled <code>true</code> or <code>false</code>
  495.  */
  496. public void setHtmlEnabled(boolean htmlEnabled) {
  497. this.htmlEnabled = htmlEnabled;
  498. }
  499. /**
  500.  * Sets the icq UIN
  501.  * 
  502.  * @param icq The icq to set
  503.  */
  504. public void setIcq(String icq) {
  505. this.icq = icq;
  506. }
  507. /**
  508.  * Sets the user id.
  509.  * 
  510.  * @param id The user id to set
  511.  */
  512. public void setId(int id) {
  513. this.id = id;
  514. }
  515. /**
  516.  * Sets the interests.
  517.  * 
  518.  * @param interests The interests to set
  519.  */
  520. public void setInterests(String interests) {
  521. this.interests = interests;
  522. }
  523. /**
  524.  * Sets the language.
  525.  * 
  526.  * @param lang The lang to set
  527.  */
  528. public void setLang(String lang) {
  529. this.lang = lang;
  530. }
  531. /**
  532.  * Sets the last visit time
  533.  * 
  534.  * @param lastVisit Last visit time, represented as a long value
  535.  */
  536. public void setLastVisit(Date lastVisit) {
  537. this.lastVisit = lastVisit;
  538. }
  539. /**
  540.  * Sets the level.
  541.  * 
  542.  * @param level The level to set
  543.  */
  544. public void setLevel(int level) {
  545. this.level = level;
  546. }
  547. /**
  548.  * Sets the status for notification of new private messages
  549.  * 
  550.  * @param notifyPrivateMessagesEnabled <code>true</code> or <code>false</code>
  551.  */
  552. public void setNotifyPrivateMessagesEnabled(boolean notifyPrivateMessagesEnabled) {
  553. this.notifyPrivateMessagesEnabled = notifyPrivateMessagesEnabled;
  554. }
  555. /**
  556.  * Sets the occ.
  557.  * 
  558.  * @param occ The occ to set
  559.  */
  560. public void setOccupation(String occupation) {
  561. this.occupation = occupation;
  562. }
  563. /**
  564.  * Sets the password.
  565.  * 
  566.  * @param password The password to set
  567.  */
  568. public void setPassword(String password) {
  569. this.password = password;
  570. }
  571. /**
  572.  * Enable or not private messages to the user
  573.  * 
  574.  * @param privateMessagesEnabled <code>true</code> or <code>false</code>
  575.  */
  576. public void setPrivateMessagesEnabled(boolean privateMessagesEnabled) {
  577. this.privateMessagesEnabled = privateMessagesEnabled;
  578. }
  579. /**
  580.  * Sets the ranking id
  581.  * 
  582.  * @param rankId The id of the ranking
  583.  */
  584. public void setRankId(int rankId) {
  585. this.rankId = rankId;
  586. }
  587. /**
  588.  * Sets the registration date.
  589.  * 
  590.  * @param registrationDate The registration date to set
  591.  */
  592. public void setRegistrationDate(Date registrationDate) {
  593. this.registrationDate = registrationDate;
  594. }
  595. /**
  596.  * Sets the signature.
  597.  * 
  598.  * @param signature The signature to set
  599.  */
  600. public void setSignature(String signature) {
  601. this.signature = signature;
  602. }
  603. /**
  604.  * Enable or not smilies in messages
  605.  * 
  606.  * @param smilesEnabled <code>true</code> or <code>false</code>
  607.  */
  608. public void setSmiliesEnabled(boolean smilesEnabled) {
  609. this.smiliesEnabled = smilesEnabled;
  610. }
  611. /**
  612.  * Sets the theme id
  613.  * 
  614.  * @param themeId The theme Id to set
  615.  */
  616. public void setThemeId(int themeId) {
  617. this.themeId = themeId;
  618. }
  619. /**
  620.  * Sets the Timezone.
  621.  * 
  622.  * @param timeZone The Timezone to set
  623.  */
  624. public void setTimeZone(String timeZone) {
  625. this.timeZone = timeZone;
  626. }
  627. /**
  628.  * Sets the total number of posts by the user
  629.  * 
  630.  * @param totalPosts int value with the total of messages posted by the user
  631.  */
  632. public void setTotalPosts(int totalPosts) {
  633. this.totalPosts = totalPosts;
  634. }
  635. /**
  636.  * Sets the username.
  637.  * 
  638.  * @param username The username to set
  639.  */
  640. public void setUsername(String username) {
  641. this.username = username;
  642. }
  643. /**
  644.  * Sets the viewOnlineEnabled.
  645.  * @param viewOnlineEnabled The viewOnlineEnabled to set
  646.  */
  647. public void setViewOnlineEnabled(boolean viewOnlineEnabled) {
  648. this.viewOnlineEnabled = viewOnlineEnabled;
  649. }
  650. /**
  651.  * Sets the webSite.
  652.  * 
  653.  * @param webSite The webSite to set
  654.  */
  655. public void setWebSite(String webSite) {
  656. this.webSite = webSite;
  657. }
  658. /**
  659.  * Sets the Yahoo messenger ID
  660.  * 
  661.  * @param yim The yim to set
  662.  */
  663. public void setYim(String yim) {
  664. this.yim = yim;
  665. }
  666. /**
  667.  * @return
  668.  */
  669. public String getMsnm() {
  670. return this.msnm;
  671. }
  672. /**
  673.  * @param string
  674.  */
  675. public void setMsnm(String string) {
  676. this.msnm = string;
  677. }
  678. /**
  679.  * @return
  680.  */
  681. public boolean isNotifyOnMessagesEnabled() {
  682. return this.notifyOnMessagesEnabled;
  683. }
  684. /**
  685.  * @param b
  686.  */
  687. public void setNotifyOnMessagesEnabled(boolean b) {
  688. this.notifyOnMessagesEnabled = b;
  689. }
  690. /**
  691.  * @return
  692.  */
  693. public boolean isViewEmailEnabled() {
  694. return this.viewEmailEnabled;
  695. }
  696. /**
  697.  * @param b
  698.  */
  699. public void setViewEmailEnabled(boolean b) {
  700. this.viewEmailEnabled = b;
  701. }
  702. /**
  703.  * @return
  704.  */
  705. public boolean getAttachSignatureEnabled() {
  706. return this.attachSignatureEnabled;
  707. }
  708. /**
  709.  * @param b
  710.  */
  711. public void setAttachSignatureEnabled(boolean b) {
  712. this.attachSignatureEnabled = b;
  713. }
  714. /**
  715.  * @return
  716.  */
  717. public List getGroupsList() {
  718. return this.groupsList;
  719. }
  720. /**
  721.  * @return Returns the privateMessagesCount.
  722.  */
  723. public int getPrivateMessagesCount()
  724. {
  725. return this.privateMessagesCount;
  726. }
  727. /**
  728.  * @param privateMessagesCount The privateMessagesCount to set.
  729.  */
  730. public void setPrivateMessagesCount(int privateMessagesCount)
  731. {
  732. this.privateMessagesCount = privateMessagesCount;
  733. }
  734. /**
  735.  * @return Returns the hasPrivateMessages.
  736.  */
  737. public boolean hasPrivateMessages()
  738. {
  739. return this.privateMessagesCount > 0;
  740. }
  741. /**
  742.  * Set when user authenticates his email after user registration
  743. */
  744. public void setActive(int active){
  745. this.active = active;
  746. }
  747. public void setActivationKey(String activationKey){
  748. this.activationKey = activationKey;
  749. }
  750. public void setKarma(KarmaStatus karma)
  751. {
  752. this.karma = karma;
  753. }
  754. public KarmaStatus getKarma()
  755. {
  756. return this.karma;
  757. }
  758. /**
  759.  * Is the user online?
  760.  * 
  761.  * @return true if user is in Session
  762.  */
  763. public boolean isOnline()
  764. {
  765. return (SessionFacade.isUserInSession(this.id) != null);
  766. }
  767. /**
  768.  * Gets the user's biography
  769.  * @return the user biography
  770.  */
  771. public String getBiography() {
  772. return biography;
  773. }
  774. /**
  775.  * Sets the user's biography
  776.  * @param biography the user's biography
  777.  */
  778. public void setBiography(String biography) {
  779. this.biography = biography;
  780. }
  781. /**
  782.  * @return the notifyAlways
  783.  */
  784. public boolean notifyAlways()
  785. {
  786. return this.notifyAlways;
  787. }
  788. /**
  789.  * @return the notifyText
  790.  */
  791. public boolean notifyText()
  792. {
  793. return this.notifyText;
  794. }
  795. /**
  796.  * @param notifyAlways the notifyAlways to set
  797.  */
  798. public void setNotifyAlways(boolean notifyAlways)
  799. {
  800. this.notifyAlways = notifyAlways;
  801. }
  802. /**
  803.  * @param notifyText the notifyText to set
  804.  */
  805. public void setNotifyText(boolean notifyText)
  806. {
  807. this.notifyText = notifyText;
  808. }
  809. }