SkinUtil.java
上传用户:toby834
上传日期:2013-10-21
资源大小:2613k
文件大小:13k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package net.acai.forum;
  2. /**
  3.  * Title:        清清网络
  4.  * Description:
  5.  * Copyright:    Copyright (c) 2002
  6.  * Company:      www.SuperSpace.com
  7.  * @author:       SuperSpace
  8.  * @version 1.0
  9.  */
  10. import net.acai.database.*;
  11. import net.acai.forum.*;
  12. import net.acai.forum.util.*;
  13. import net.acai.util.*;
  14. import net.acai.ip.*;
  15. import javax.servlet.http.*;
  16. import java.sql.*;
  17. import java.util.*;
  18. public class SkinUtil
  19. {
  20. public static void login(HttpServletRequest request,
  21.  HttpServletResponse response,
  22.  String username,
  23.  String password) throws UserNotFoundException,Exception
  24. {
  25. /*User sessionUser=new User(username,password);
  26. HttpSession session=request.getSession(true);
  27. session.setAttribute("UJBBUser",sessionUser);
  28. GCookie.setCookie(response,"UJBBUName",username,60*60*60);
  29. GCookie.setCookie(response,"UJBBUPSW",password,60*60*60);*/
  30. }
  31. public static User checkUser(HttpServletRequest request,HttpServletResponse response,int loginSign) throws UserNotFoundException,Exception{
  32. String userName=GCookie.getCookieValue(request,"UJBBUName","");
  33. String userPassword=GCookie.getCookieValue(request,"UJBBUPSW","");
  34. User tempUser=new User(userName,userPassword,loginSign);
  35. return tempUser;
  36. }
  37. public static void userLogin(HttpServletRequest request,HttpServletResponse response,int loginSign) throws UserNotFoundException,Exception{
  38. String userName=ParamUtil.getString(request,"userName","");
  39. String userPassword=ParamUtil.getString(request,"userPassword","");
  40. User tempUser=new User(userName,userPassword,loginSign);
  41. int cookieDate=ParamUtil.getInt(request,"cookieDate",1);
  42. switch(cookieDate){
  43. case 1:
  44. cookieDate=3600*24;
  45. break;
  46. case 2:
  47. cookieDate=30*3600*24;
  48. break;
  49. case 3:
  50. cookieDate=365*30*3600*24;
  51. break;
  52. default:
  53. cookieDate=3600*24;
  54. break;
  55. }
  56. GCookie.setCookie(response,"UJBBUName",userName,cookieDate);
  57. GCookie.setCookie(response,"UJBBUPSW",userPassword,cookieDate);
  58. }
  59. public static void userLogout(HttpServletResponse response,HttpServletRequest request) throws Exception
  60. {
  61. String userName=GCookie.getCookieValue(request,"UJBBUName","");
  62. String userPassword=GCookie.getCookieValue(request,"UJBBUPSW","");
  63. GCookie.setCookie(response,"UJBBUName",userName,0);
  64. GCookie.setCookie(response,"UJBBUPSW",userPassword,0);
  65. long  statUserID=Long.parseLong(StringUtils.replace(request.getRemoteAddr(),".",""));
  66.   String sql="delete from bbs.online where ID="+statUserID;
  67. DBConnect dbc=new DBConnect(sql);
  68. dbc.executeUpdate();
  69. }
  70. public static User userLogin(String userName,String userPassword,int loginSign) throws UserNotFoundException,Exception{
  71. User tempUser=new User(userName,userPassword,loginSign);
  72. return tempUser;
  73. }
  74. public static void checkUserStats(HttpServletRequest request,HttpServletResponse response){
  75. String stats;
  76. if((stats=ParamUtil.getString(request,"stats"))==null)
  77. {
  78. stats="论坛首页 response";
  79. }
  80. checkUserStats(request,response,stats);
  81. }
  82. public static void checkUserStats(HttpServletRequest request,HttpServletResponse response,String stats){
  83. String userName=GCookie.getCookieValue(request,"UJBBUName","");
  84. String userPassword=GCookie.getCookieValue(request,"UJBBUPSW","");
  85. String ip=request.getRemoteAddr();
  86. String[] addr=IPLocalizer.search(request);
  87. String comeFrom="";
  88. for(int i=0;i<addr.length;i++)
  89. comeFrom+=addr[i];
  90. String actCome=request.getHeader("X_FORWARDED_FOR");
  91. long  statUserID=Long.parseLong(StringUtils.replace(ip,".",""));
  92.   boolean onlineSign=false;
  93.   String browser=request.getHeader("User-Agent");
  94. ResultSet rs;
  95.   try{
  96. String sql="";
  97. DBConnect dbc=new DBConnect();
  98. try{
  99.   sql="select * from bbs.online where id=?";
  100. dbc.prepareStatement(sql);
  101. dbc.setLong(1,statUserID);
  102. //dbc.setBytes(2,userName(new String(.getBytes("ISO-8859-1"),"GBK")).getBytes());
  103. rs=dbc.executeQuery();
  104. if(rs.next())
  105. onlineSign=true;
  106. else
  107. onlineSign=false;
  108. rs.close();
  109. }
  110. catch(Exception e){
  111. onlineSign=false;
  112. }
  113. if("".equals(userName)){
  114. //System.out.println("++++++++++++++"+stats);
  115. //if(stats.indexOf("response")==-1)stats = net.ds.toGBK(stats);
  116. //System.out.println("--------------"+stats);
  117. if(!onlineSign){
  118. sql="insert into bbs.online (id,username,userclass,ip,startime,lastimebk,browser,stats,actforip,ComeFrom,actCome) values(?,?,?,?,?,?,?,?,?,?,?)";
  119. dbc.prepareStatement(sql);
  120. dbc.setLong(1,statUserID);
  121. dbc.setString(2,"guest");
  122. dbc.setBytes(3,("客人").getBytes());
  123. dbc.setBytes(4,(new String(ip.getBytes("ISO-8859-1"),"GBK")).getBytes());
  124. dbc.setString(5,Format.getDateTime());
  125. dbc.setString(6,Format.getDateTime());
  126. dbc.setString(7,browser);
  127. dbc.setBytes(8,stats.getBytes());
  128. dbc.setString(9,actCome);
  129. dbc.setBytes(10,comeFrom.getBytes());
  130. dbc.setString(11,actCome);
  131. dbc.executeUpdate();
  132. dbc.clearParameters();
  133. }
  134. else{
  135. sql="update bbs.online set lastimebk=?,lastime=?,ComeFrom=?,actCome=?,stats=? where id=?";
  136. dbc.prepareStatement(sql);
  137. dbc.setString(1,Format.getDateTime());
  138. dbc.setString(2,Format.getStrDateTime());
  139. dbc.setBytes(3,comeFrom.getBytes());
  140. dbc.setString(4,actCome);
  141. dbc.setBytes(5,stats.getBytes());
  142. dbc.setLong(6,statUserID);
  143. dbc.executeUpdate();
  144. dbc.clearParameters();
  145. }
  146. }
  147. else{
  148. sql="select * from bbs.online where  ID=? or username=?";
  149. dbc.prepareStatement(sql);
  150. dbc.setLong(1,statUserID);
  151. dbc.setBytes(2,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  152. rs=dbc.executeQuery();
  153. if(rs.next())
  154. onlineSign=true;
  155. else
  156. onlineSign=false;
  157. dbc.clearParameters();
  158. try{
  159. //stats = net.ds.toGBK(stats);
  160. User theUser=new User(userName,userPassword,4);
  161. if(onlineSign){
  162. sql="update bbs.online set id=?,userName=?,userClass=?,lastimebk=?,lastime=?,ComeFrom=?,actCome=?,stats=? where id=? or username=?";
  163. dbc.prepareStatement(sql);
  164. dbc.setLong(1,statUserID);
  165. dbc.setBytes(2,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  166. dbc.setBytes(3,getUserClass(theUser.getUserClass()).getBytes());
  167. dbc.setString(4,Format.getDateTime());
  168. dbc.setString(5,Format.getStrDateTime());
  169. dbc.setBytes(6,comeFrom.getBytes());
  170. dbc.setString(7,actCome);
  171. dbc.setBytes(8,stats.getBytes());
  172. dbc.setLong(9,statUserID);
  173. dbc.setBytes(10,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  174. dbc.executeUpdate();
  175. dbc.clearParameters();
  176. }
  177. else{
  178. sql="insert into bbs.online(id,username,userclass,ip,startime,lastimebk,browser,stats,actforip,ComeFrom,actCome) values(?,?,?,?,?,?,?,?,?,?,?)";
  179. dbc.prepareStatement(sql);
  180. dbc.setLong(1,statUserID);//statUserID);
  181. dbc.setBytes(2,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  182. dbc.setBytes(3,getUserClass(theUser.getUserClass()).getBytes());
  183. dbc.setString(4,ip);
  184. dbc.setString(5,Format.getDateTime());
  185. dbc.setString(6,Format.getStrDateTime());
  186. dbc.setString(7,browser);
  187. dbc.setBytes(8,stats.getBytes());
  188. if(actCome==null){
  189. dbc.setString(9,"null");
  190. dbc.setString(11,"null");
  191. }
  192. else{
  193. dbc.setString(9,actCome);
  194. dbc.setString(11,actCome);
  195. }
  196. dbc.setBytes(10,comeFrom.getBytes());
  197. dbc.executeUpdate();
  198. dbc.clearParameters();
  199. }
  200. }
  201. catch(Exception e){
  202. if(!onlineSign){
  203. sql="insert into bbs.online (id,username,userclass,ip,startime,lastimebk,browser,stats,actforip,ComeFrom,actCome) values(?,?,?,?,?,?,?,?,?,?,?)";
  204. dbc.prepareStatement(sql);
  205. dbc.setLong(1,statUserID);
  206. dbc.setString(2,"guest");
  207. dbc.setBytes(3,(new String("客人".getBytes("ISO-8859-1"),"GBK")).getBytes());
  208. dbc.setBytes(4,(new String(ip.getBytes("ISO-8859-1"),"GBK")).getBytes());
  209. dbc.setString(5,Format.getDateTime());
  210. dbc.setString(6,Format.getDateTime());
  211. dbc.setString(7,browser);
  212. dbc.setBytes(8,stats.getBytes());
  213. dbc.setString(9,actCome);
  214. dbc.setBytes(10,comeFrom.getBytes());
  215. dbc.setString(11,actCome);
  216. dbc.executeUpdate();
  217. dbc.clearParameters();
  218. }
  219. else{
  220. sql="update bbs.online set lastimebk=?,lastime=?,ComeFrom=?,actCome=?,stats=? where id=?";
  221. dbc.prepareStatement(sql);
  222. dbc.setString(1,Format.getDateTime());
  223. dbc.setString(2,Format.getStrDateTime());
  224. dbc.setBytes(3,comeFrom.getBytes());
  225. dbc.setString(4,actCome);
  226. dbc.setBytes(5,stats.getBytes());
  227. dbc.setLong(6,statUserID);
  228. dbc.executeUpdate();
  229. dbc.clearParameters();
  230. }
  231. }
  232. }
  233. sql="delete from bbs.online where "
  234. +" datepart(YYYY,getdate()-lastimebk)=0 and "
  235. +" datepart(MM,getdate()-lastimebk)=0 and "
  236. +" datepart(DD,getdate()-lastimebk)=0 and "
  237. +" datepart(HH,getdate()-lastimebk)=0 and "
  238. +" datepart(MI,getdate()-lastimebk)<20";
  239. dbc.executeUpdate(sql);
  240. sql="select Maxonline from bbs.config";
  241. rs=dbc.executeQuery(sql);
  242. rs.next();
  243. int oldMaxOnLine=rs.getInt(1);
  244. sql="select count(*) from bbs.online";
  245. ResultSet tmprs=dbc.executeQuery(sql);
  246. tmprs.next();
  247. int newMaxOnLine=tmprs.getInt(1);
  248. if(newMaxOnLine>oldMaxOnLine){
  249. sql="update bbs.config set Maxonline="+newMaxOnLine+",MaxonlineDate=getdate()";
  250. dbc.executeUpdate(sql);
  251. ForumPropertiesManager.resetManager();
  252. }
  253. dbc.close();
  254. }
  255. catch(Exception e){
  256. e.printStackTrace();
  257. }
  258. }
  259. public static String getUserClass(int userClass){
  260. String user_level="";
  261. switch(userClass){
  262. case 1:
  263. user_level="新手上路";
  264. break;
  265. case 2:
  266. user_level="论坛游民";
  267. break;
  268. case 3:
  269. user_level="论坛游侠";
  270. break;
  271. case 4:
  272. user_level="业余侠客";
  273. break;
  274. case 5:
  275. user_level="职业侠客";
  276. break;
  277. case 6:
  278. user_level="侠之大者";
  279. break;
  280. case 7:
  281. user_level="黑侠";
  282. break;
  283. case 8:
  284. user_level="蝙蝠侠";
  285. break;
  286. case 9:
  287. user_level="蜘蛛侠";
  288. break;
  289. case 10:
  290. user_level="青蜂侠";
  291. break;
  292. case 11:
  293. user_level="小飞侠";
  294. break;
  295. case 12:
  296. user_level="火箭侠";
  297. break;
  298. case 13:
  299. user_level="蒙面侠";
  300. break;
  301. case 14:
  302. user_level="城市猎人";
  303. break;
  304. case 15:
  305. user_level="罗宾汉";
  306. break;
  307. case 16:
  308. user_level="阿诺";
  309. break;
  310. case 17:
  311. user_level="侠圣";
  312. break;
  313. case 18:
  314. user_level="贵宾";
  315. break;
  316. case 19:
  317. user_level="版主";
  318. break;
  319. case 20:
  320. user_level="总版主";
  321. break;
  322. default:
  323. user_level="新手上路";
  324. break;
  325. }
  326. return user_level;
  327. }
  328. public static int getPoint(int p){
  329. int level_point=0;
  330. switch(p){
  331. case 1:
  332. level_point=0;
  333. break;
  334. case 2:
  335. level_point=100;
  336. break;
  337. case 3:
  338. level_point=200;
  339. break;
  340. case 4:
  341. level_point=300;
  342. break;
  343. case 5:
  344. level_point=400;
  345. break;
  346. case 6:
  347. level_point=500;
  348. break;
  349. case 7:
  350. level_point=600;
  351. break;
  352. case 8:
  353. level_point=800;
  354. break;
  355. case 9:
  356. level_point=1000;
  357. break;
  358. case 10:
  359. level_point=1200;
  360. break;
  361. case 11:
  362. level_point=1500;
  363. break;
  364. case 12:
  365. level_point=1800;
  366. break;
  367. case 13:
  368. level_point=2100;
  369. break;
  370. case 14:
  371. level_point=2500;
  372. break;
  373. case 15:
  374. level_point=3000;
  375. break;
  376. case 16:
  377. level_point=3500;
  378. break;
  379. case 17:
  380. level_point=4000;
  381. break;
  382. default:
  383. level_point=0;
  384. break;
  385. }
  386. return level_point;
  387. }
  388. public static Vector getTopList(HttpServletRequest request) throws Exception{
  389. int orders=ParamUtil.getInt(request,"orders",7);
  390. String sql="";
  391. switch(orders){
  392. case 1:
  393. sql="select username,useremail,userclass,oicq,homePage,article,addDate,userwealth as wealth ,userID from bbs.myuser order by article desc";
  394. break;
  395. case 2:
  396. sql="select  username,useremail,userclass,oicq,homePage,article,addDate,userwealth as wealth ,userID from bbs.myuser order by AddDate desc";
  397. break;
  398. case 7:
  399. sql="select username,useremail,userclass,oicq,homePage,article,addDate,userwealth as wealth ,userID from bbs.myuser order by AddDate desc ";
  400. break;
  401. default:
  402. sql="select  username,useremail,userclass,oicq,homePage,article,addDate,userwealth as wealth ,userID from bbs.myuser order by article desc";
  403. break;
  404. }
  405. DBConnect dbc=new DBConnect();
  406. ResultSet rs=dbc.executeQuery(sql);
  407. Vector userVector=new Vector();
  408. int i = 0 ;
  409. while(rs.next()){
  410. User tempUser=new User();
  411. tempUser.setUserName(rs.getString(1));
  412. tempUser.setUserEmail(rs.getString(2));
  413. tempUser.setUserClass(rs.getInt(3));
  414. tempUser.setOicq(rs.getString(4));
  415. tempUser.setHomePage(rs.getString(5));
  416. tempUser.setArticle(rs.getInt(6));
  417. tempUser.setAddDate(rs.getString(7));
  418. tempUser.setUserWealth(rs.getInt(8));
  419. tempUser.setUserID(rs.getInt(9));
  420. userVector.add(tempUser);
  421. i++;
  422. if(orders!=7)
  423. {
  424. if(i==10)break;
  425. }
  426. }
  427. return userVector;
  428. }
  429. }