📄 userservice.java
字号:
package com.redmoon.forum.person;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/
import cn.js.fan.security.*;
import javax.servlet.http.*;
import cn.js.fan.util.*;
import org.apache.log4j.Logger;
import com.redmoon.forum.ForumDb;
import com.redmoon.forum.OnlineUserDb;
import com.redmoon.forum.Privilege;
import com.redmoon.forum.plugin.ScoreMgr;
import com.redmoon.forum.plugin.ScoreUnit;
import com.redmoon.forum.plugin.base.IPluginScore;
import java.util.Iterator;
import java.util.Vector;
import com.redmoon.forum.security.IPMonitor;
import java.util.TimeZone;
import com.redmoon.forum.Authorization;
import cn.js.fan.web.SkinUtil;
import java.util.Locale;
import cn.js.fan.web.Global;
import com.redmoon.forum.RegConfig;
import com.redmoon.forum.message.MessageDb;
import com.redmoon.forum.Config;
import cn.js.fan.mail.SendMail;
public class userservice {
Logger logger = Logger.getLogger(userservice.class.getName());
public final String KEY = "bluewindBlueWindBLUEWIND";
public userservice() {
}
public boolean AddFriend(HttpServletRequest request) throws ErrMsgException {
Privilege pvg = new Privilege();
if (!pvg.isUserLogin(request))
throw new ErrMsgException(SkinUtil.LoadString(request, "err_not_login"));
String name = pvg.getUser(request);
String friend = ParamUtil.get(request, "friend");
if (friend == null)
throw new ErrMsgException(SkinUtil.LoadString(request, "res.forum.person.userservice", "err_need_friend"));
if (name.equals(friend))
throw new ErrMsgException(SkinUtil.LoadString(request, "res.forum.person.userservice", "err_add_self"));
// throw new ErrMsgException("您不能把自己加为好友!");
UserFriendDb ufd = new UserFriendDb();
ufd.setName(name);
ufd.setFriend(friend);
boolean re = false;
try {
re = ufd.create();
}
catch (ResKeyException e) {
throw new ErrMsgException(e.getMessage(request));
}
return re;
}
public void setStayTime(HttpServletRequest req, HttpServletResponse res) throws
ErrMsgException {
HttpSession session = req.getSession(true);
Authorization auth = (Authorization)session.getAttribute(Privilege.SESSION_CWBBS_AUTH);
if (auth==null)
return;
auth.setStayTime(System.currentTimeMillis());
session.setAttribute(Privilege.SESSION_CWBBS_AUTH, auth);
OnlineUserDb ou = new OnlineUserDb();
ou = ou.getOnlineUserDb(auth.getName());
ou.setStayTime(new java.util.Date());
// 如果用户在线
if (ou.isLoaded()) {
ou.save();
} else {
// 如果不在线,即超时被刷新掉了,则再加入在线列表
int isguest = 0;
if (Privilege.isGuest(req))
isguest = 1;
ou.setName(auth.getName());
ou.setIp(req.getRemoteAddr());
ou.setGuest(isguest == 1 ? true : false);
ou.create();
// logger.info("setStayTime: create " + username + " isguest=" + isguest);
}
}
public long getStayTime(HttpServletRequest req) {
long st = 0;
Privilege pvg = new Privilege();
Authorization auth = pvg.getAuthorization(req);
if (auth!=null) {
st = auth.getStayTime();
}
return st;
}
public void refreshStayTime(HttpServletRequest req, HttpServletResponse res) throws
ErrMsgException {
long staytime = System.currentTimeMillis();
long t = (staytime - getStayTime(req)) / 300000; // (1000 * 60 * 5);
if (t > 5) {
// 大于5分钟则刷新
setStayTime(req, res);
}
}
public boolean isRegNameExist(HttpServletRequest req, String regName) throws
ErrMsgException {
if (regName == null || regName.trim().equals(""))
// throw new ErrMsgException("用户名不能为空!");
throw new ErrMsgException(SkinUtil.LoadString(req, "res.forum.person.userservice", "err_need_name"));
UserDb user = new UserDb();
user = user.getUserDbByNick(regName);
if (user!=null && user.isLoaded())
return true;
else
return false;
}
public boolean regist(HttpServletRequest req, HttpServletResponse res) throws
ErrMsgException {
ParamConfig pc = new ParamConfig("form_rule.xml");
ParamChecker pck = new ParamChecker(req);
try {
pck.doCheck(pc.getFormRule("regist"));
} catch (CheckErrException e) {
// 如果onError=exit,则会抛出异常
throw new ErrMsgException(e.getMessage());
}
String RegName = pck.getString("RegName");
if (RegName == null || RegName.trim().equals("")) {
throw new ErrMsgException(SkinUtil.LoadString(req, "res.forum.person.userservice", "err_need_name"));
}
if (isRegNameExist(req, RegName)) {
throw new ErrMsgException(SkinUtil.LoadString(req, "res.label.forum.user", "user_name_exist"));
}
String Password = pck.getString("Password").trim();
String Password2 = pck.getString("Password2").trim();
try {
Password = SecurityUtil.MD5(Password);
} catch (Exception e) {
logger.error("regist:" + e.getMessage());
}
String Question = pck.getString("Question");
String Answer = pck.getString("Answer");
String RealName = pck.getString("RealName");
String Career = pck.getString("Career");
String Gender = pck.getString("Gender");
String Job = pck.getString("Job");
String BirthYear = pck.getString("BirthYear");
String BirthMonth = pck.getString("BirthMonth");
String BirthDay = pck.getString("BirthDay");
String Birthday = BirthYear + "-" + BirthMonth + "-" + BirthDay;
int Marriage = pck.getInt("Marriage");
String Phone = pck.getString("Phone");
String Mobile = pck.getString("Mobile");
String State = pck.getString("State");
String City = pck.getString("City");
String Address = pck.getString("Address");
String PostCode = pck.getString("PostCode");
String IDCard = pck.getString("IDCard");
String RealPic = pck.getString("RealPic");
String Hobbies = pck.getString("Hobbies");
String Email = pck.getString("Email");
RegConfig rcfg = new RegConfig();
boolean allowERegUser = true;
allowERegUser = rcfg.getBooleanProperty("allowERegUser");
if(!allowERegUser){
UserDb ud = new UserDb();
if (!ud.validEmailOnly(Email)) {
throw new ErrMsgException(SkinUtil.LoadString(req,
"res.label.forum.user", "allowereguser"));
}
}
String[] EAllowAddress = null;
String[] EForbidAddress = null;
String temp = "";
EAllowAddress = rcfg.getStringArrProperty("EAllowAddress");
EForbidAddress = rcfg.getStringArrProperty("EForbidAddress");
temp = Email.trim().substring(Email.trim().indexOf("@"));
// logger.info("EAllowAddress.length=" + EAllowAddress.length);
if (EAllowAddress == null) {
if(EForbidAddress != null) {
for (int i = 0; i < EForbidAddress.length; i++) {
if (temp.equals(EForbidAddress[i].trim())) {
throw new ErrMsgException(SkinUtil.LoadString(req,
"res.label.forum.user", "eforbidaddress"));
}
}
}
} else {
for (int i = 0; i < EAllowAddress.length; i++) {
if (!temp.equals(EAllowAddress[i].trim())) {
throw new ErrMsgException(SkinUtil.LoadString(req,
"res.label.forum.user", "eallowaddress"));
}
}
}
String OICQ = pck.getString("OICQ");
String sign = pck.getString("Content");
String ip = pck.getString("ip");
boolean secret = pck.getBoolean("isSecret");
String home = pck.getString("home");
String msn = pck.getString("msn");
String locale = pck.getString("locale");
String tzID = pck.getString("timeZone");
TimeZone tz = TimeZone.getTimeZone(tzID);
IPMonitor im = new IPMonitor();
if (!im.isValid(req, ip)) {
throw new ErrMsgException(im.getMessage());
}
ForumDb fd = new ForumDb();
fd = fd.getForumDb();
fd.FilterUserName(req, RegName);
UserDb user = new UserDb();
user.setNick(RegName);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -