📄 usercheck.java
字号:
package com.laoer.bbscs.web.servlet;
import javax.servlet.http.*;
import org.apache.commons.logging.*;
import com.laoer.bbscs.bean.*;
import com.laoer.bbscs.business.*;
import com.laoer.bbscs.business.service.*;
import com.laoer.bbscs.sys.*;
import com.laoer.comm.util.*;
/**
* <p>Title: TianYi BBS</p>
* <p>Description: TianYi BBS System</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: LAOER.COM/TIANYISOFT.NET</p>
* @author laoer
* @version 6.0
*/
public class UserCheck {
private static final Log logger = LogFactory.getLog(UserCheck.class);
private static final String PASS_USERNAME_KEY = "PASS_USERNAME";
private static final String PASS_USERNAME_DES_KEY = "PASS_USERNAME_DES";
private static final String BBSCS_USERNAME_KEY = "BBSCS_USERNAME";
private static final String BBSCS_USERNAME_DES_KEY = "BBSCS_USERNAME_DES";
private static final String BBSCS_NICKNAME_KEY = "NK";
private static final String BBSCS_ID_KEY = "ID";
private static final String BBSCS_ACTTIME_KEY = "AT";
private static final String BBSCS_SPUERADMIN_KEY = "SA";
private static final String BBSCS_MANAGER_KEY = "M";
private static final String BBSCS_BOARD_KEY = "B";
private static final String BBSCS_BOARDMASTER_KEY = "BM";
private static final String BBSCS_BULLETIN_KEY = "BU";
private static final String BBSCS_USERADMIN_KEY = "UA";
private static final String BBSCS_GUEST_KEY = "GU";
private static final String BBSCS_HPOWER_KEY = "H";
private static final String BBSCS_FORUMPERNUM_KEY = "FN";
private static final String BBSCS_POSTPERNUM_KEY = "PN";
private static final String BBSCS_TIMEZONE_KEY = "TZ";
private static final String BBSCS_AI_KEY = "AI";
private SysInfo si;
private Boards bs;
private IBoardsService ibs;
//private WebApplicationContext wac;
private HttpServletRequest request;
private HttpServletResponse response;
private String username = "";
private String usernamedes = "";
private String nickname = "";
private long id = 0;
private long activeTime = 0;
private short superAdmin = 0;
private short manager = 0;
private short board = 0;
private short boardMaster = 0;
private short bulletin = 0;
private short userAdmin = 0;
private short guest = 1;
private DES des;
private short power = 0;
private boolean mainMaster = false;
private boolean assiMaster = false;
private boolean hideMaster = false;
private int formPerNum = 20;
private int postPerNum = 10;
private long bid = 0;
private boolean bmaster = false;
private String timeZone = "GMT+08:00";
private String authCode = "";
private String pusername = "";
private String pusernamedes = "";
//UserInfo userInfo = null;
public UserCheck() {
}
/*
public UserCheck(HttpServletRequest request, HttpServletResponse response) {
this.request = request;
this.response = response;
}*/
public UserCheck(HttpServletRequest request, HttpServletResponse response) {
this.request = request;
this.response = response;
this.si = SysInfo.getInstance();
try {
des = new DES(DES._DESede);
}
catch (Exception ex) {
logger.error(
"UserCheck(HttpServletRequest request, HttpServletResponse response," +
" ServletContext sc)" + ex);
}
getCookies(request, response);
}
public UserCheck(HttpServletRequest request, HttpServletResponse response,
long bid) {
this.request = request;
this.response = response;
this.si = SysInfo.getInstance();
this.bid = bid;
try {
des = new DES(DES._DESede);
}
catch (Exception ex) {
logger.error(
"UserCheck(HttpServletRequest request, HttpServletResponse response," +
"ServletContext sc, long bid):" + ex);
}
getCookies(request, response);
BoardList boardList = (BoardList) AppContext.getInstance().getAppContext().
getBean("boradList");
this.bs = (Boards) boardList.getBoardsHm().get(new Long(bid));
if (!this.isGuest()) {
if (this.bs != null) {
this.ibs = (IBoardsService) AppContext.getInstance().getAppContext().
getBean("boardsService");
this.bmaster = (this.bs.getBoard().getBmaster().equals(this.username));
this.mainMaster = this.ibs.isMainMaster(this.bs, this.username);
this.assiMaster = this.ibs.isAssiMaster(this.bs, this.username);
this.hideMaster = this.ibs.isHideMaster(this.bs, this.username);
}
}
}
/*
public UserCheck(HttpServletRequest request, HttpServletResponse response,
ServletContext sc) {
this.request = request;
this.response = response;
this.wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
//this.si = (SysInfo)this.wac.getBean("sysInfo");
this.si = SysInfo.getInstance();
try {
des = new DES(DES._DESede);
}
catch (Exception ex) {
logger.error(
"UserCheck(HttpServletRequest request, HttpServletResponse response," +
" ServletContext sc)" + ex);
}
getCookies(request, response);
}
public UserCheck(HttpServletRequest request, HttpServletResponse response,
WebApplicationContext wac) {
this.request = request;
this.response = response;
this.wac = wac;
//this.si = (SysInfo) wac.getBean("sysInfo");
this.si = SysInfo.getInstance();
try {
des = new DES(DES._DESede);
}
catch (Exception ex) {
logger.error(
"UserCheck(HttpServletRequest request, HttpServletResponse response," +
"WebApplicationContext wac)" + ex);
}
getCookies(request, response);
}
public UserCheck(HttpServletRequest request, HttpServletResponse response,
ServletContext sc, long bid) {
this.request = request;
this.response = response;
this.wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
//this.si = (SysInfo) wac.getBean("sysInfo");
this.si = SysInfo.getInstance();
this.bid = bid;
try {
des = new DES(DES._DESede);
}
catch (Exception ex) {
logger.error(
"UserCheck(HttpServletRequest request, HttpServletResponse response," +
"ServletContext sc, long bid):" + ex);
}
getCookies(request, response);
BoardList boardList = (BoardList) wac.getBean("boradList");
this.bs = (Boards) boardList.getBoardsHm().get(new Long(bid));
if (!this.isGuest()) {
if (this.bs != null) {
this.ibs = (IBoardsService) wac.getBean("boardsService");
this.bmaster = (this.bs.getBoard().getBmaster().equals(this.username));
this.mainMaster = this.ibs.isMainMaster(this.bs, this.username);
this.assiMaster = this.ibs.isAssiMaster(this.bs, this.username);
this.hideMaster = this.ibs.isHideMaster(this.bs, this.username);
}
}
}
public UserCheck(HttpServletRequest request, HttpServletResponse response,
WebApplicationContext wac, long bid) {
this.request = request;
this.response = response;
this.wac = wac;
//this.si = (SysInfo) wac.getBean("sysInfo");
this.si = SysInfo.getInstance();
this.bid = bid;
try {
des = new DES(DES._DESede);
}
catch (Exception ex) {
logger.error(
"UserCheck(HttpServletRequest request, HttpServletResponse response," +
"WebApplicationContext wac, long bid):" + ex);
}
getCookies(request, response);
BoardList boardList = (BoardList) wac.getBean("boradList");
this.bs = (Boards) boardList.getBoardsHm().get(new Long(bid));
if (!this.isGuest()) {
if (this.bs != null) {
this.ibs = (IBoardsService) wac.getBean("boardsService");
this.bmaster = (this.bs.getBoard().getBmaster().equals(this.username));
this.mainMaster = this.ibs.isMainMaster(this.bs, this.username);
this.assiMaster = this.ibs.isAssiMaster(this.bs, this.username);
this.hideMaster = this.ibs.isHideMaster(this.bs, this.username);
}
}
}*/
public void getCookies(HttpServletRequest request,
HttpServletResponse response) {
Cookie cookies[] = request.getCookies();
Cookie sCookie = null;
byte[] buf;
try {
//DES des = new DES(DES._DESede);
if (cookies != null && cookies.length > 0) {
//System.out.println(cookies.length);
for (int i = 0; i < cookies.length; i++) {
sCookie = cookies[i];
if (si.getUsepass().equals("y")) {
if (sCookie.getName().equals(PASS_USERNAME_KEY)) {
this.username = sCookie.getValue();
this.pusername = sCookie.getValue();
//System.out.println("pass username:" + username);
}
if (sCookie.getName().equals(PASS_USERNAME_DES_KEY)) {
if (!Util.nullOrBlank(sCookie.getValue())) {
buf = Util.base64decodebyte(sCookie.getValue());
byte[] dec = des.decode(buf,
Util.base64decodebyte(si.getCookiekey()));
this.usernamedes = new String(dec);
this.pusernamedes = usernamedes;
//System.out.println("pass usernamedes:" + usernamedes);
}
}
}
else {
if (sCookie.getName().equals(BBSCS_USERNAME_KEY)) {
this.username = sCookie.getValue();
//System.out.println("-username-:" + username);
}
if (sCookie.getName().equals(BBSCS_USERNAME_DES_KEY)) {
buf = Util.base64decodebyte(sCookie.getValue());
byte[] dec = des.decode(buf,
Util.base64decodebyte(si.getCookiekey()));
this.usernamedes = new String(dec);
//System.out.println("-usernamedes-:" + usernamedes);
}
}
if (sCookie.getName().equals(BBSCS_ID_KEY)) {
buf = Util.base64decodebyte(sCookie.getValue());
byte[] dec = des.decode(buf, Util.base64decodebyte(si.getCookiekey()));
this.id = Long.parseLong(new String(dec));
//System.out.println("id" + id);
}
if (sCookie.getName().equals(BBSCS_NICKNAME_KEY)) {
this.nickname = Util.base64decode(sCookie.getValue());
//System.out.println("nickname " + nickname);
}
if (sCookie.getName().equals(BBSCS_ACTTIME_KEY)) {
this.activeTime = Long.parseLong(sCookie.getValue());
//System.out.println("activeTime " + activeTime);
}
if (sCookie.getName().equals(BBSCS_SPUERADMIN_KEY)) {
buf = Util.base64decodebyte(sCookie.getValue());
byte[] dec = des.decode(buf, Util.base64decodebyte(si.getCookiekey()));
this.superAdmin = SysUtil.getCookieValue(new String(dec),
Constant.PERFIX[0], (short) 0);
//System.out.println("superAdmin " + superAdmin);
}
if (sCookie.getName().equals(BBSCS_MANAGER_KEY)) {
buf = Util.base64decodebyte(sCookie.getValue());
byte[] dec = des.decode(buf, Util.base64decodebyte(si.getCookiekey()));
this.manager = SysUtil.getCookieValue(new String(dec),
Constant.PERFIX[1], (short) 0);
//System.out.println("manager " + manager);
}
if (sCookie.getName().equals(BBSCS_BOARD_KEY)) {
buf = Util.base64decodebyte(sCookie.getValue());
byte[] dec = des.decode(buf, Util.base64decodebyte(si.getCookiekey()));
this.board = SysUtil.getCookieValue(new String(dec),
Constant.PERFIX[2], (short) 0);
//System.out.println("board " + board);
}
if (sCookie.getName().equals(BBSCS_BOARDMASTER_KEY)) {
buf = Util.base64decodebyte(sCookie.getValue());
byte[] dec = des.decode(buf, Util.base64decodebyte(si.getCookiekey()));
this.boardMaster = SysUtil.getCookieValue(new String(dec),
Constant.PERFIX[3], (short) 0);
//System.out.println("boardMaster " + boardMaster);
}
if (sCookie.getName().equals(BBSCS_BULLETIN_KEY)) {
buf = Util.base64decodebyte(sCookie.getValue());
byte[] dec = des.decode(buf, Util.base64decodebyte(si.getCookiekey()));
this.bulletin = SysUtil.getCookieValue(new String(dec),
Constant.PERFIX[4], (short) 0);
//System.out.println("bulletin " + bulletin);
}
if (sCookie.getName().equals(BBSCS_USERADMIN_KEY)) {
buf = Util.base64decodebyte(sCookie.getValue());
byte[] dec = des.decode(buf, Util.base64decodebyte(si.getCookiekey()));
this.userAdmin = SysUtil.getCookieValue(new String(dec),
Constant.PERFIX[5], (short) 0);
//System.out.println("userAdmin " + userAdmin);
}
if (sCookie.getName().equals(BBSCS_GUEST_KEY)) {
buf = Util.base64decodebyte(sCookie.getValue());
byte[] dec = des.decode(buf, Util.base64decodebyte(si.getCookiekey()));
this.guest = SysUtil.getCookieValue(new String(dec),
Constant.PERFIX[6], (short) 1);
//this.guest = SysUtil.getGuestCookieValue(new String(dec),Constant.PERFIX[6]);
//System.out.println("guest" + guest);
}
if (sCookie.getName().equals(BBSCS_HPOWER_KEY)) {
buf = Util.base64decodebyte(sCookie.getValue());
byte[] dec = des.decode(buf, Util.base64decodebyte(si.getCookiekey()));
this.power = SysUtil.getCookieValue(new String(dec),
Constant.PERFIX[7], (short) 0);
//System.out.println(this.power);
//System.out.println("hpower " + hpower);
}
if (sCookie.getName().equals(BBSCS_FORUMPERNUM_KEY)) {
this.formPerNum = Integer.parseInt(sCookie.getValue());
//System.out.println("this.formPerNum "+this.formPerNum);
}
if (sCookie.getName().equals(BBSCS_POSTPERNUM_KEY)) {
this.postPerNum = Integer.parseInt(sCookie.getValue());
}
if (sCookie.getName().equals(BBSCS_TIMEZONE_KEY)) {
this.timeZone = Util.base64decode(sCookie.getValue());
}
if (sCookie.getName().equals(BBSCS_AI_KEY)) {
this.authCode = sCookie.getValue();
}
}
if (si.getUsepass().equals("y")) {
//-------------------------------------------
//通行证退出
if (Util.nullOrBlank(this.username) &&
Util.nullOrBlank(this.usernamedes)) {
for (int i = 0; i < cookies.length; i++) {
sCookie = cookies[i];
if (sCookie.getName().equals(BBSCS_USERNAME_KEY)) {
this.username = sCookie.getValue();
//System.out.println("+username+:" + username);
}
if (sCookie.getName().equals(BBSCS_USERNAME_DES_KEY)) {
buf = Util.base64decodebyte(sCookie.getValue());
byte[] dec = des.decode(buf,
Util.base64decodebyte(si.getCookiekey()));
this.usernamedes = new String(dec);
//System.out.println("+usernamedes+:" + usernamedes);
}
}
}
//-------------------------------------------
//通行证重新登录,但社区仍为游客
if (!Util.nullOrBlank(this.username) &&
!Util.nullOrBlank(this.usernamedes) && this.guest == 1) {
for (int i = 0; i < cookies.length; i++) {
sCookie = cookies[i];
if (sCookie.getName().equals(BBSCS_USERNAME_KEY)) {
this.username = sCookie.getValue();
//System.out.println("++-username-++:" + username);
}
}
}
}
}
if (this.guest == -1) {
this.guest = 1;
}
}
catch (Exception e) {
this.username = "";
this.usernamedes = "";
//e.printStackTrace();
logger.error(
"getCookies(HttpServletRequest request,HttpServletResponse response)" +
e);
}
}
public void addUCookies(String username, String nickname, short guest) {
this.username = username;
addC(BBSCS_USERNAME_KEY, username);
//this.usernamedes = username;
//addDES(BBSCS_USERNAME_DES_KEY, username);
this.nickname = nickname;
addC(BBSCS_NICKNAME_KEY, Util.base64Encode(nickname));
this.guest = guest;
addDES(BBSCS_GUEST_KEY, Constant.PERFIX[6] + guest);
this.activeTime = SysUtil.getLongTime();
addC(BBSCS_ACTTIME_KEY, String.valueOf(activeTime));
}
public void addUCookies(String username, String nickname, short guest,
int maxage) {
this.username = username;
addC(BBSCS_USERNAME_KEY, username, maxage);
//this.usernamedes = username;
//addDES(BBSCS_USERNAME_DES_KEY, username);
this.nickname = nickname;
addC(BBSCS_NICKNAME_KEY, Util.base64Encode(nickname), maxage);
this.guest = guest;
addDES(BBSCS_GUEST_KEY, Constant.PERFIX[6] + guest, maxage);
this.activeTime = SysUtil.getLongTime();
addC(BBSCS_ACTTIME_KEY, String.valueOf(activeTime), maxage);
}
public void addUCookiesActiveTime() {
this.activeTime = SysUtil.getLongTime();
addC(BBSCS_ACTTIME_KEY, String.valueOf(activeTime));
}
public void addAuthCode() {
this.authCode = Util.genNumPassword(4);
addC(BBSCS_AI_KEY, this.authCode);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -