📄 skinutil.java
字号:
package com.bcxy.bbs.forum;
/**
* Title:
* Description:
* Copyright:
* Company: www.liyunet.com
*
* @author lishujiang
* @version 1.0
*/
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import com.bcxy.bbs.util.BBSConst;
import com.bcxy.bbs.util.GCookie;
import com.bcxy.bbs.util.ParamUtil;
import com.bcxy.db.JdbcWrapper;
import com.bcxy.ip.IPLocalizer;
import com.bcxy.util.DateUtil;
import com.bcxy.util.StringUtil;
public class SkinUtil {
static Logger log = Logger.getLogger(SkinUtil.class);
public static int checkStyle(HttpServletRequest request,
HttpServletResponse response) throws Exception {
int ret = 0;
int styleID = ParamUtil.getInt(request, "style", -1);
if (styleID != -1) {
GCookie.setCookie(response, "UJBBUSTYLE", String.valueOf(styleID),
-1);
}
String CStyle = GCookie.getCookieValue(request, "UJBBUSTYLE", "");
if (!"".equals(CStyle)) {
ret = StringUtil.parseInt(CStyle);
}else{
String sql = "select id from " + BBSConst.TABLE_FORUMSTYLE + " where flag=2";
ret = new JdbcWrapper().doIntSearch(sql, 0);
}
return ret;
}
public static User checkUser(HttpServletRequest request,
HttpServletResponse response, int loginSign)
throws UserNotFoundException, Exception {
String userName = GCookie.getCookieValue(request, "UJBBUName", "");
String userPassword = GCookie.getCookieValue(request, "UJBBUPSW", "");
User tempUser = null;
int forumID = ParamUtil.getInt(request, "forumID", 0);
int forumSkin = 0;
if(forumID != 0){//避免查询数据库
forumSkin = ForumFactory.getForum(forumID).getForumSkin();
}
switch (forumSkin) {
case 0:
tempUser = new User(userName, userPassword, loginSign);
break;
case 1:
// 常规
tempUser = new User(userName, userPassword, loginSign);
break;
case 2:
// 开放,不需要检验用户
break;
case 3:
// 评论,只会员回复
tempUser = new User(userName, userPassword, loginSign);
if (loginSign == 2 && tempUser.getUserClass() < 19) {
throw new Exception("评论论坛坛主和版主允许发言,普通会员只允许回复!");
}
break;
case 4:
// 精华,版主可用
tempUser = new User(userName, userPassword, loginSign);
if (tempUser.getUserClass() < 19) {
throw new Exception("评论论坛只允许坛主和版主允许发言!");
}
break;
case 5:
// 认证
tempUser = new User(userName, userPassword, loginSign);
if (!(tempUser.getUserClass() > 18 || ForumFactory
.getForum(forumID).getForumUser().indexOf(userName) >= 0)) {
throw new Exception("您没有通过论坛管理员认证!");
}
break;
case 6:
// 正规
tempUser = new User(userName, userPassword, loginSign);
break;
}
return tempUser;
}
public static void userLogin(HttpServletRequest request,
HttpServletResponse response, int loginSign)
throws UserNotFoundException, Exception {
String userName = ParamUtil.getString(request, "userName", "");
String userPassword = ParamUtil.getString(request, "userPassword", "");
//
new User(userName, userPassword, loginSign);
//
int cookieDate = ParamUtil.getInt(request, "cookieDate", 1);
switch (cookieDate) {
case 1:
cookieDate = 3600 * 24;
break;
case 2:
cookieDate = 30 * 3600 * 24;
break;
case 3:
cookieDate = 365 * 30 * 3600 * 24;
break;
default:
cookieDate = 3600 * 24;
break;
}
GCookie.setCookie(response, "UJBBUName", userName,
cookieDate);
GCookie.setCookie(response, "UJBBUPSW", userPassword, cookieDate);
}
public static void userLogout(HttpServletResponse response,
HttpServletRequest request) throws Exception {
JdbcWrapper jw = new JdbcWrapper();
String userName = GCookie.getCookieValue(request, "UJBBUName", "");
String userPassword = GCookie.getCookieValue(request, "UJBBUPSW", "");
GCookie.setCookie(response, "UJBBUName", userName, 0);
GCookie.setCookie(response, "UJBBUPSW", userPassword, 0);
// 删除用户在线数据
String statUserID = request.getSession().getId();
String sql = "delete from " + BBSConst.TABLE_ONLINE + " where ID='"
+ statUserID + "'";
jw.executeUpdate(sql);
}
public static User userLogin(String userName, String userPassword,
int loginSign) throws UserNotFoundException, Exception {
User tempUser = new User(userName, userPassword, loginSign);
return tempUser;
}
public static void checkUserStats(HttpServletRequest request,
HttpServletResponse response) {
String stats;
if ((stats = request.getParameter("stats")) == null) {
stats = "论坛首页";
}
checkUserStats(request, response, stats);
}
public static boolean checkUserOnline(String userName) {
JdbcWrapper jw = new JdbcWrapper();
try {
return jw.isExists("select username from " + BBSConst.TABLE_ONLINE
+ " where username='" + userName + "'");
} catch (Exception e) {
return false;
}
}
public static void checkUserStats(HttpServletRequest request,
HttpServletResponse response, String stats) {
String userName = GCookie.getCookieValue(request, "UJBBUName", "");
String userPassword = GCookie.getCookieValue(request, "UJBBUPSW", "");
String ip = request.getRemoteAddr();
String[] addr = IPLocalizer.search(request);
String comeFrom = "";
for (int i = 0; i < addr.length; i++) {
comeFrom += addr[i];
}
//
String actCome = request.getHeader("X_FORWARDED_FOR");
// long statUserID = Long.parseLong(StringUtils.replace(ip, ".", ""));
String statUserID = request.getSession().getId();
boolean onlineSign = false;
String browser = request.getHeader("User-Agent");
JdbcWrapper jw = new JdbcWrapper();
try {
String sql = "";
jw.setAutoClose(false);
try {
sql = "select id from " + BBSConst.TABLE_ONLINE + " where id='"
+ statUserID + "'";
onlineSign = jw.isExists(sql);
} catch (Exception e) {
onlineSign = false;
}
if ("".equals(userName)) {
if (!onlineSign) {
sql = "insert into "
+ BBSConst.TABLE_ONLINE
+ " (id,username,userclass,ip,startime,lastimebk,browser,stats,actforip,ComeFrom,actCome) values(?,?,?,?,?,?,?,?,?,?,?)";
jw.prepareStatement(sql);
jw.setString(1, statUserID);
jw.setString(2, "guest");
jw.setString(3, "客人");
jw.setString(4, ip);
jw.setString(5, DateUtil.getLocalDate());
jw.setString(6, DateUtil.getLocalDate());
jw.setString(7, browser);
jw.setString(8, stats);
jw.setString(9, actCome);
jw.setString(10, comeFrom);
jw.setString(11, actCome);
jw.executeUpdate();
jw.clearParameters();
} else {
sql = "update "
+ BBSConst.TABLE_ONLINE
+ " set lastimebk=?,lastime=?,ComeFrom=?,actCome=?,stats=? where id=?";
jw.prepareStatement(sql);
jw.setString(1, DateUtil.getLocalDate());
jw.setString(2, DateUtil.getLocalDate());
jw.setString(3, comeFrom);
jw.setString(4, actCome);
jw.setString(5, stats);
jw.setString(6, statUserID);
jw.executeUpdate();
jw.clearParameters();
}
} else {
sql = "select id from " + BBSConst.TABLE_ONLINE
+ " where ID='" + statUserID + "' or username='"
+ userName + "'";
if (jw.isExists(sql)) {
onlineSign = true;
} else {
onlineSign = false;
}
try {
User theUser = new User(userName, userPassword, 4);
if (onlineSign) {
sql = "update "
+ BBSConst.TABLE_ONLINE
+ " set id=?,userName=?,userClass=?,lastimebk=?,lastime=?,ComeFrom=?,actCome=?,stats=? where id=? or username=?";
jw.prepareStatement(sql);
jw.setString(1, statUserID);
jw.setString(2, userName);
jw.setString(3, getUserClass(theUser.getUserClass()));
jw.setString(4, DateUtil.getLocalDate());
jw.setString(5, DateUtil.getLocalDate());
jw.setString(6, comeFrom);
jw.setString(7, actCome);
jw.setString(8, stats);
jw.setString(9, statUserID);
jw.setString(10, userName);
jw.executeUpdate();
jw.clearParameters();
} else {
sql = "insert into "
+ BBSConst.TABLE_ONLINE
+ "(id,username,userclass,ip,startime,lastimebk,browser,stats,actforip,ComeFrom,actCome) values(?,?,?,?,?,?,?,?,?,?,?)";
jw.prepareStatement(sql);
jw.setString(1, statUserID);// statUserID);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -