📄 bbsuseraction.java
字号:
userInfo.setSex(CommUtil.null2String(form.get("sex")));
userInfo.setTel(CommUtil.null2String(form.get("tel")));
userInfo.setQq(CommUtil.null2String(form.get("qq")));
userInfo.setIntro(CommUtil.null2String(form.get("intro")));
userInfo.setInputTime(new Date());
userInfo.setStatus(new Integer(0));
if (UserInfo.readByUserName(userName) != null) {
form.addResult("msg", "用户名已经存在!");
return module.findPage("reg");
}
if (userInfo.save()) {
form.addResult("msg", "用户注册成功!");
ActiveUser user = BBSUtil.login(userName, MD5.encode(password), "0",
ActionContext.getContext().getRequest().getRemoteAddr());
MessageUtil.sendSystemMessage(WebMessage.WELCOMEMSG, userInfo
.getUserName());
if (user != null) {
ActionContext.getContext().getSession().setAttribute("bbsuser",
user);// 登录标志
return module.findPage("loginSuccess");
}
} else {
form.addResult("msg", "用户注册失败!");
return module.findPage("reg");
}
return module.findPage("reg");
}
/**
* 添加用户信息->系统管理员使用
*
* @param form
* @param module
* @return 添加成功则返回列表Page,失败则返回编辑Page
*/
public Page doAdd(WebForm form, Module module) {
String userName = CommUtil.null2String(form.get("userName"));
UserInfo userInfo = new UserInfo();
userInfo.setUserName(userName);
userInfo.setPassword(MD5.encode(CommUtil.null2String(form.get("password"))));
userInfo.setEmail(CommUtil.null2String(form.get("email")));
userInfo.setSex(CommUtil.null2String(form.get("sex")));
userInfo.setTel(CommUtil.null2String(form.get("tel")));
userInfo.setQq(CommUtil.null2String(form.get("qq")));
userInfo.setIntro(CommUtil.null2String(form.get("intro")));
userInfo.setPhoto(CommUtil.null2String(form.get("photo")));
userInfo.setStatus(new Integer(0));
if (UserInfo.readByUserName(userName) != null) {
form.addResult("msg", "用户名已经存在!");
return module.findPage("edit");
}
if (userInfo.save()) {
form.addResult("msg", "用户添加成功!");
} else {
form.addResult("msg", "用户添加失败!");
return module.findPage("edit");
}
return doQuery(form, module);
}
/**
* 修改用户信息
*
* @param form
* @param module
* @return 添加成功,若当前用户为系统管理员,则返回列表Page,否则返回个人信息设置Page,失败则返回编辑Page.
*/
public Page doUpdate(WebForm form, Module module) {
String cid = CommUtil.null2String(form.get("cid"));
ActiveUser user = getCurrentUser();
UserInfo obj = null;
if (!cid.equals("")) {
obj = UserInfo.read(cid);
} else if (user != null) {
obj = UserInfo.readByUserName(user.getUserName());
}
if (obj != null) {
// 在Action中检测权限
if (!BBSRights.checkRights(obj, "update", user))
return new Page("popedomError", "/bbs/norights.htm", "page");
obj.setPassword(MD5.encode(CommUtil.null2String(form.get("password"))));
obj.setEmail(CommUtil.null2String(form.get("email")));
obj.setSex(CommUtil.null2String(form.get("sex")));
obj.setTel(CommUtil.null2String(form.get("tel")));
obj.setQq(CommUtil.null2String(form.get("qq")));
obj.setIntro(CommUtil.null2String(form.get("intro")));
obj.setPhoto(CommUtil.null2String(form.get("photo")));
obj.update();
} else {
form.addResult("msg", "你所修改的用户不存在!");
}
if (!BBSRights.checkRights(obj, "isAdministrator", user)) {
return module.findPage("setting");
}
return doQuery(form, module);
}
/**
* 删除用户
*
* @param form
* @param module
* @return 返回列表Page
*/
public Page doDel(WebForm form, Module module) {
String cid = CommUtil.null2String(form.get("cid"));
ActiveUser user = getCurrentUser();
UserInfo obj = UserInfo.read(cid);
if (obj != null) {
if (!BBSRights.checkRights(obj, "del", user))
return new Page("popedomError", "/bbs/norights.htm", "page");
obj.del();
form.addResult("msg", "删除成功!");
}
return doQuery(form, module);
}
/**
* 编辑用户信息-从持久层读取数据显示到View中
*
* @param form
* @param module
* @return 返回编辑Page
*/
public Page doEdit(WebForm form, Module module) {
String cid = CommUtil.null2String(form.get("cid"));
ActiveUser user = getCurrentUser();
UserInfo obj = null;
if (!cid.equals("")) {
obj = UserInfo.read(cid);
} else if (user != null) {
obj = UserInfo.readByUserName(user.getUserName());
}
if (!BBSRights.checkRights(obj, "edit", user))
return new Page("popedomError", "/bbs/norights.htm", "page");
if (obj != null)
CommUtil.Obj2Map(obj, form.getTextElement());
return module.findPage("setting");
}
/**
* 显示用户信息
*
* @param form
* @param module
* @return 返回用户信息显示Page
*/
public Page doShow(WebForm form, Module module) {
String userName = CommUtil.toChinese(CommUtil.null2String(form
.get("user")), ActionContext.getContext().getRequest()
.getCharacterEncoding());
try {
UserInfo obj = null;
if (!userName.equals("")) {
obj = UserInfo.readByUserName(userName);
}
if (obj != null)
CommUtil.Obj2Map(obj, form.getTextElement());
} catch (Exception e) {
System.out.println("出现了字符转换错误!" + e);
}
return module.findPage("show");
}
/**
* 查询用户信息
*
* @param form
* @param module
* @return 返回用户列表
*/
public Page doQuery(WebForm form, Module module) {
if (!BBSRights.checkRights(new UserInfo(), "list", getCurrentUser()))
return new Page("popedomError", "/bbs/norights.htm", "page");
int currentPage = CommUtil.null2Int(form.get("page"));
int pageSize = CommUtil.null2Int(form.get("pageSize"));
if (currentPage < 1)
currentPage = 1;
if (pageSize < 1)
pageSize = 15;
IPageList pList = BBSUtil.queryUser("1=1", pageSize, currentPage);
if (pList != null) {
form.addResult("list", pList.getResult());
form.addResult("pages", new Integer(pList.getPages()));
form.addResult("rows", new Integer(pList.getRowCount()));
form.addResult("page", new Integer(pList.getCurrentPage()));
form.addResult("gotoPageHTML", CommUtil.showPageHtml(pList
.getCurrentPage(), pList.getPages()));
}
return module.findPage("list");
}
public Page doQueryByName(WebForm form, Module module) {
if (!BBSRights.checkRights(new UserInfo(), "list", getCurrentUser()))
return new Page("popedomError", "/bbs/norights.htm", "page");
int currentPage = CommUtil.null2Int(form.get("page"));
int pageSize = CommUtil.null2Int(form.get("pageSize"));
if (currentPage < 1)
currentPage = 1;
if (pageSize < 1)
pageSize = 15;
String name = CommUtil.null2String(form.get("name"));
IPageList pList = BBSUtil.queryUser("1=1 and userName='" + name + "'",
pageSize, currentPage);
if (pList != null) {
form.addResult("list", pList.getResult());
form.addResult("pages", new Integer(pList.getPages()));
form.addResult("rows", new Integer(pList.getRowCount()));
form.addResult("page", new Integer(pList.getCurrentPage()));
form.addResult("gotoPageHTML", CommUtil.showPageHtml(pList
.getCurrentPage(), pList.getPages()));
}
return module.findPage("list");
}
public Page doOnline(WebForm form,Module module){
form.addResult("ip",ActionContext.getContext().getRequest().getRemoteAddr());
String userAgent=ActionContext.getContext().getRequest().getHeader("User-Agent");
String browser =userAgent.split(";")[1].trim();
String os =userAgent.split(";")[2].trim();
form.addResult("os",os);
form.addResult("browser",browser);
form.addResult("admin",ActiveUserUtil.admin());
form.addResult("manager",ActiveUserUtil.manager());
form.addResult("user",ActiveUserUtil.users());
form.addResult("guest",ActiveUserUtil.guests());
form.addResult("total",ActiveUser.gettotal());
form.addResult("users",ActiveUserUtil.showAllUsers());
System.out.println(ActiveUserUtil.showAll().size());
return module.findPage("onlineList");
}
private ActiveUser getCurrentUser() {
ActiveUser user = (ActiveUser) ActionContext.getContext().getSession()
.getAttribute("bbsuser");
return user;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -