User.java
上传用户:yuyunping
上传日期:2013-03-21
资源大小:1844k
文件大小:11k
源码类别:

Java书籍

开发平台:

Java

  1. // created on 2002-2-26 at 20:54
  2. package net.acai.forum;
  3. /**
  4.  * Title:        清清网络
  5.  * Description:
  6.  * Copyright:    Copyright (c) 2002
  7.  * Company:      www.SuperSpace.com
  8.  * @author:       SuperSpace
  9.  * @version 1.0
  10.  */
  11. import net.acai.forum.UserNotFoundException;
  12. import net.acai.database.*;
  13. import net.acai.forum.util.*;
  14. import net.acai.util.*;
  15. import javax.servlet.http.*;
  16. import java.sql.ResultSet;
  17. import net.acai.filter.*;
  18. public class User
  19. {
  20. private String username,password,lastlogin;
  21. private int userID,article,logins,width,height,bbsType,lockUser,userClass,userWealth,userEP,userCP;
  22. private String userName,userEmail,userPassword,sign,sex,homePage,addDate;
  23. private String face,oicq,lastLogin,userGroup,title,showRE,reann;
  24. String errMSG="";
  25. public User(){
  26. }
  27. public void setUserID(int userID){
  28. this.userID=userID;
  29. }
  30. public int getUserID(){
  31. return this.userID;
  32. }
  33. public void setUserName(String userName){
  34. this.userName=userName;
  35. }
  36. public String getUserName(){
  37. return this.userName;
  38. }
  39. public void setUserEmail(String userEmail ){
  40. this.userEmail=userEmail;
  41. }
  42. public String getUserEmail(){
  43. return this.userEmail;
  44. }
  45. public void setArticle(int article ){
  46. this.article=article;
  47. }
  48. public int getArticle(){
  49. return this.article;
  50. }
  51. public void setUserPassword(String userPassword){
  52. this.userPassword=userPassword;
  53. }
  54. public String getUserPassword(){
  55. return this.userPassword;
  56. }
  57. public void setSign(String sign){
  58. this.sign=sign;
  59. }
  60. public String getNoFilterSign(){
  61. return this.sign;
  62. }
  63. public String getSign(){
  64. return (new MyFilter(StringUtils.replace(StringUtils.convertNewlines(StringUtils.escapeHTMLTags(this.sign))," "," "))).getFilterString();
  65. }
  66. public void setSex(String sex){
  67. this.sex=sex;
  68. }
  69. public String getSex(){
  70. return this.sex;
  71. }
  72. public void setHomePage(String homePage){
  73. this.homePage=homePage;
  74. }
  75. public String getHomePage(){
  76. return this.homePage;
  77. }
  78. public void setAddDate(String addDate){
  79. this.addDate=addDate;
  80. }
  81. public String getAddDate(){
  82. return this.addDate;
  83. }
  84. public void setLogins(int logins ){
  85. this.logins=logins;
  86. }
  87. public int getLogins(){
  88. return this.logins;
  89. }
  90. public void setFace(String face){
  91. this.face=face;
  92. }
  93. public String getFace(){
  94. return this.face;
  95. }
  96. public void setWidth(int width){
  97. this.width=width;
  98. }
  99. public int getWidth(){
  100. return this.width;
  101. }
  102. public void setHeight(int height ){
  103. this.height=height;
  104. }
  105. public int getHeight(){
  106. return this.height;
  107. }
  108. public void setOicq(String oicq){
  109. this.oicq=oicq;
  110. }
  111. public String getOicq(){
  112. return this.oicq;
  113. }
  114. public void setLastLogin(String lastLogin){
  115. this.lastLogin=lastLogin;
  116. }
  117. public String getLastLogin(){
  118. return this.lastLogin;
  119. }
  120. public void setBbsType(int bbsType){
  121. this.bbsType=bbsType;
  122. }
  123. public int getBbsType(){
  124. return this.bbsType;
  125. }
  126. public void setLockUser(int lockUser){
  127. this.lockUser=lockUser;
  128. }
  129. public int getLockUser(){
  130. return this.lockUser;
  131. }
  132. public void setUserClass(int userClass){
  133. this.userClass=userClass;
  134. }
  135. public int getUserClass(){
  136. return this.userClass;
  137. }
  138. public void setUserGroup(String userGroup ){
  139. this.userGroup=userGroup;
  140. }
  141. public String getUserGroup(){
  142. return this.userGroup;
  143. }
  144. public void setUserWealth(int userWealth){
  145. this.userWealth=userWealth;
  146. }
  147. public int getUserWealth(){
  148. return this.userWealth;
  149. }
  150. public void setUserEP(int userEP){
  151. this.userEP=userEP;
  152. }
  153. public int getUserEP(){
  154. return this.userEP;
  155. }
  156. public void setUserCP(int userCP){
  157. this.userCP=userCP;
  158. }
  159. public int getUserCP(){
  160. return this.userCP;
  161. }
  162. public void setTitle(String title ){
  163. this.title=title;
  164. }
  165. public String getTitle(){
  166. return this.title;
  167. }
  168. public void setReann(String reann ){
  169. this.reann=reann;
  170. }
  171. public String getReann(){
  172. return this.reann;
  173. }
  174. public User(String userName,String userPassword,int loginSign) throws UserNotFoundException ,Exception
  175. {
  176. boolean foundErr=false;
  177. if("".equals(userName)){
  178. errMSG=errMSG+"<br>"+"<li>请输入您的用户名。";
  179. foundErr=true;
  180. }
  181. if("".equals(userPassword)){
  182. errMSG=errMSG+"<br>"+"<li>请输入您的密码。";
  183. foundErr=true;
  184. }
  185. if(foundErr)
  186. throw new Exception(errMSG);
  187. this.userName=userName;
  188. this.userPassword=userPassword;
  189. if(loginSign>0)
  190. checkUser(loginSign);
  191. }
  192. public void checkUser(int loginSign) throws UserNotFoundException,Exception
  193. {
  194. try{
  195. MD5 md5=new MD5();
  196. /*
  197. DBConnect dbc=new DBConnect("select * from bbs.myuser where UserName=? and UserPassword=?");
  198. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  199. dbc.setBytes(2,(new String(md5.getMD5ofStr(userPassword).getBytes("ISO-8859-1"),"GBK")).getBytes());
  200. ResultSet rs=dbc.executeQuery();
  201. */
  202. String s1 = new String(userName.getBytes("ISO-8859-1"),"GBK") ;
  203. String s2 = new String(md5.getMD5ofStr(userPassword).getBytes("ISO-8859-1"),"GBK") ;
  204. String sql1 = "select * from bbs.myuser where UserName='"+s1.trim()+"' and UserPassword='"+s2.trim()+"'";
  205. DBConnect dbc=new DBConnect();
  206. ResultSet rs=dbc.executeQuery(sql1);
  207. //System.out.println(sql1);
  208. if(rs.next())
  209. {
  210. if(loginSign==4){
  211. //dbc.close();
  212. this.setUserClass(rs.getInt("userclass"));
  213. //System.out.println("____________"+this.getUserClass());
  214. this.setLastLogin(rs.getString("lastlogin"));
  215. return;
  216. }
  217. //System.out.println("----------------");
  218. //use the resultset to define the varible used!
  219. lastLogin=rs.getString("lastlogin");
  220. article=rs.getInt("Article");
  221. userClass=rs.getInt("userclass");
  222. if (userClass<18){
  223. if (article<SkinUtil.getPoint(2)) userClass=1;
  224. for(int i=2;i<17;i++){
  225. if (article>=SkinUtil.getPoint(i) && article<SkinUtil.getPoint(i+1))
  226.  userClass=i;
  227. }
  228. if (article>=SkinUtil.getPoint(17)) userClass=17;
  229. }
  230. String thegetdate=Format.getDateTime();
  231. //此处对user的各种属性进行了重新定义;
  232. /*this.setUserID(rs.getInt(
  233. this.setUserName(rs.getString(13));
  234. this.setUserEmail(rs.getString(14));
  235. this.setHomePage(rs.getString(15));
  236. this.setOicq(rs.getString(16));
  237. this.setSign(rs.getString(17));
  238. this.setUserClass(rs.getInt(18));
  239. this.setTitle(rs.getString(19));
  240. this.setWidth(rs.getInt(20));
  241. this.setHeight(rs.getInt(21));
  242. this.setArticle(rs.getInt(22));
  243. this.setFace(rs.getString(23));
  244. this.setAddDate(rs.getString(24));
  245. this.setUserWealth(rs.getInt(25));
  246. this.setUserEP(rs.getInt(26));
  247. this.setUserCP(rs.getInt(27));
  248. */
  249. this.lastLogin=rs.getString("lastlogin");
  250. //dbc.clearParameters();
  251. String sql="";
  252. int wealthLogin=Integer.parseInt(ForumPropertiesManager.getString("wealthLogin"));
  253. int epLogin=Integer.parseInt(ForumPropertiesManager.getString("epLogin"));
  254. int cpLogin=Integer.parseInt(ForumPropertiesManager.getString("cpLogin"));
  255. int wealthAnnounce=Integer.parseInt(ForumPropertiesManager.getString("wealthAnnounce"));
  256. int wealthReAnnounce=Integer.parseInt(ForumPropertiesManager.getString("wealthReannounce"));
  257. int epAnnounce=Integer.parseInt(ForumPropertiesManager.getString("epAnnounce"));
  258. int epReAnnounce=Integer.parseInt(ForumPropertiesManager.getString("epReannounce"));
  259. int cpAnnounce=Integer.parseInt(ForumPropertiesManager.getString("cpAnnounce"));
  260. int cpReAnnounce=Integer.parseInt(ForumPropertiesManager.getString("cpReannounce"));
  261. switch(loginSign){
  262. case 1:
  263. sql="update bbs.myuser set userWealth=userWealth+"+wealthLogin+",userEP=userEP+"+epLogin+",userCP=userCP+"+cpLogin+",userClass="+userClass+",lastlogin='"+thegetdate+"',logins=logins+1 where username='"+s1+"'";
  264. break;
  265. case 2:
  266. sql="update bbs.myuser set article=article+1,userWealth=userWealth+"+wealthAnnounce+",userEP=userEP+"+epAnnounce+",userCP=userCP+"+cpAnnounce+",userclass="+userClass+",lastlogin=getdate() where username='"+s1+"'";
  267. break;
  268. case 3:
  269. sql="update bbs.myuser set article=article+1,userWealth=userWealth+"+wealthReAnnounce+",userEP=userEP+"+epReAnnounce+",userCP=userCP+"+cpReAnnounce+",userclass="+userClass+",lastlogin=getdate() where username='"+s1+"'";
  270. break;
  271. default:
  272. sql="update bbs.myuser set userWealth=userWealth+"+wealthLogin+",userEP=userEP+"+epLogin+",userCP=userCP+"+cpLogin+",userClass="+userClass+",lastlogin='"+thegetdate+"',logins=logins+1 where username='"+s1+"'";
  273. break;
  274. }
  275. //dbc.prepareStatement(sql);
  276. //dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  277. dbc.executeUpdate(sql);
  278. dbc.close();
  279. }
  280. else
  281. {
  282. dbc.close();
  283. throw new UserNotFoundException("<br><li>对不起此用户不存在请检查你的密码与用户名");
  284. }
  285. }
  286. catch(UserNotFoundException ue)
  287. {
  288. ue.printStackTrace();
  289. }
  290. catch(java.sql.SQLException se)
  291. {
  292. se.printStackTrace();
  293. }
  294. catch(Exception e)
  295. {
  296. throw new Exception("<br><li>数据库操作失败,请与<a href="mailto:"+ForumPropertiesManager.getString("SystemEmail")+"">系统管理员联系</a>");
  297. }
  298. }
  299. public String getUserClassStr(){
  300. String tempStr="";
  301. switch(this.getUserClass()){
  302. case 1:
  303.   tempStr="&nbsp;&nbsp;<img src=pic/level0.gif>";
  304.   break;
  305. case 2:
  306.  tempStr="&nbsp;&nbsp;<img src=pic/level1.gif>";
  307. break;
  308. case 3:
  309. tempStr="&nbsp;&nbsp;<img src=pic/level2.gif>";
  310. break;
  311. case 5:
  312. tempStr="&nbsp;&nbsp;<img src=pic/level3.gif>";
  313. break;
  314. case 6:
  315. tempStr="&nbsp;&nbsp;<img src=pic/level4.gif>";
  316. break;
  317. case 7:
  318. tempStr="&nbsp;&nbsp;<img src=pic/level5.gif>";
  319. break;
  320. case 8:
  321. tempStr="&nbsp;&nbsp;<img src=pic/level6.gif>";
  322. break;
  323. case 9:
  324. tempStr="&nbsp;&nbsp;<img src=pic/level7.gif>";
  325. break;
  326. case 10:
  327. tempStr="&nbsp;&nbsp;<img src=pic/level8.gif>";
  328. break;
  329. case 11:
  330. tempStr="&nbsp;&nbsp;<img src=pic/level9.gif>";
  331. break;
  332. case 12:
  333. tempStr="&nbsp;&nbsp;<img src=pic/level9.gif>";
  334. break;
  335. case 13:
  336. tempStr="&nbsp;&nbsp;<img src=pic/level9.gif>";
  337. break;
  338. case 14:
  339. tempStr="&nbsp;&nbsp;<img src=pic/level9.gif>";
  340. break;
  341. case 15:
  342. tempStr="&nbsp;&nbsp;<img src=pic/level9.gif>";
  343. break;
  344. case 16:
  345. tempStr="&nbsp;&nbsp;<img src=pic/level9.gif>";
  346. break;
  347. case 17:
  348. tempStr="&nbsp;&nbsp;<img src=pic/level9.gif>";
  349. break;
  350. case 18:
  351. tempStr="&nbsp;&nbsp;<img src=pic/level9.gif>";
  352. break;
  353. case 19:
  354. tempStr="&nbsp;&nbsp;<img src=pic/level10.gif>";
  355. break;
  356. case 20:
  357. tempStr="&nbsp;&nbsp;<img src=pic/level10.gif>";
  358. break;
  359. }
  360. return tempStr;
  361. }
  362. }