⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bbsuseraction.java

📁 简易java框架开源论坛系统,简 易java框架开源论坛系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.easyjf.bbs.action;

import java.util.Date;
import com.easyjf.util.CommUtil;
import com.easyjf.util.MD5;
import com.easyjf.web.ActionContext;
import com.easyjf.web.Module;
import com.easyjf.web.Page;
import com.easyjf.web.WebForm;
import com.easyjf.web.tools.AbstractCmdAction;
import com.easyjf.web.tools.IPageList;
import com.easyjf.bbs.business.*;
import com.easyjf.bbs.business.util.*;


/**
 * <p>
 * Title:BBS用户处理Action
 * </p>
 * <p>
 * Description: 处理BBS用户对象相关操作的Action,包括用户注册、用户增加、用户设置、用户修改、用户删除等! <br>
 * 通过继承com.easyjf.web.tools.AbstractCmdAction,实现简单的命令式Action处理,去除了复杂烦锁的if else语句
 * </p>*
 * <p>
 * Copyright: Copyright (c) 2006
 * </p>
 * <p>
 * Company: www.easyjf.com
 * </p>
 * 
 * @author 蔡世友
 * @version 1.0
 */
public class BBSUserAction extends AbstractCmdAction {

	public Page doInit(WebForm form, Module module) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 查询所有用户
	 * 
	 * @param form
	 * @param module
	 * @return 用户列表Page
	 */
	public Page doList(WebForm form, Module module) {
		if (!BBSRights.checkRights(new UserInfo(), "list", getCurrentUser()))
			return new Page("popedomError", "/bbs/norights.htm", "page");
		return doQuery(form, module);
	}

	/**
	 * 设置个人用户信息
	 * 
	 * @param form
	 * @param module
	 * @return 返回编辑用户Page
	 */
	public Page doSetting(WebForm form, Module module) {
		ActiveUser user = getCurrentUser();
		if (user == null) {
			form.addResult("msg", "请先登录!");
			return module.findPage("login");
		}
		return doEdit(form, module);
	}

	public Page doNew(WebForm form, Module module) {
		return module.findPage("edit");
	}

	/**
	 * 注销用户,清除session,并跳转到相应的页面
	 * 
	 * @param form
	 * @param module
	 * @return
	 */
	public Page doLogout(WebForm form, Module module) {
		ActiveUserUtil.remove(this.getCurrentUser());
		ActionContext.getContext().getSession().removeAttribute("bbsuser");
		form.addResult("url", "/bbs/");
		return new Page("clientforward", "/bbs/forward.html", "template");
	}

	/**
	 * 查询在线用户,这里只是一个模拟
	 * 
	 * @param form
	 * @param module
	 * @return 返回在线用户列表Page
	 */
	/*
	 * 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("totalOnlineNum",new Integer(0)); form.addResult("memberNum",new Integer(0));
	 * form.addResult("otherNum",new Integer(0)); return module.findPage("onlineList"); }
	 */
	/**
	 * 用户登录验证,通过客户端用户的登录信息验证用户输入
	 * 
	 * @param form
	 * @param module
	 * @return 根据用户输入的情况返回相应的Page
	 */
	public Page doLogin(WebForm form, Module module) {
		ActionContext.getContext().getSession().removeAttribute("bbsuser");
		Page page = null;
		String randomCode = (String) ActionContext.getContext().getSession()
				.getAttribute("rand");
		if (!randomCode.equals((String) form.get("randomCode"))) {
			form.addResult("msg", "验证码不正确,请重新输入!");
			return module.findPage("login");
		}
		ActiveUser user = BBSUtil.login(CommUtil.null2String(form
				.get("userName")), MD5.encode(CommUtil.null2String(form.get("password"))),
				CommUtil.null2String(form.get("cktime")), ActionContext
						.getContext().getRequest().getRemoteAddr());
		if (user != null) {
			System.out.println("login in success");
			ActionContext.getContext().getSession().setAttribute("bbsuser",
					user);// 登录标志
			page = module.findPage("loginSuccess");
		} else {
			form.addResult("msg", "用户名或者密码不正确,请重新输入!");
			page = module.findPage("login");
		}
		return page;
	}

	/**
	 * 用户注册
	 * 
	 * @param form
	 * @param module
	 * @return 直接跳转到用户注册Page
	 */
	public Page doReg(WebForm form, Module module) {
		return module.findPage("reg");
	}

	public Page doShowChangePass(WebForm form,Module module)
	{
		ActiveUser user=getCurrentUser();
		if(user==null)
		{
			form.addResult("msg","请先登录!");
			return module.findPage("login");
		}
		return module.findPage("changePass");
	}
	/**
	 * 修改用户信息
	 * @param form
	 * @param module
	 * @return 添加成功,若当前用户为系统管理员,则返回列表Page,否则返回个人信息设置Page,失败则返回编辑Page.
	 */
	public Page doChangePass(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");
			String password=CommUtil.null2String(form.get("password"));
			String oldPassword=CommUtil.null2String(form.get("oldPassword"));
			if(obj.getPassword().equals(MD5.encode(oldPassword)))
			{
			obj.setPassword(MD5.encode(password));
			obj.update();
			form.addResult("msg","密码修改成功!");
			}
			else
			{
				form.addResult("msg","旧密码输入不正确!");
			}
		}
		else
		{
			form.addResult("msg","你所修改的用户不存在!");
		}
		
		return module.findPage("changePass");
	}

	
	public Page doControlPan(WebForm form,Module module)
	{
		ActiveUser user=getCurrentUser();
		if(user==null)
		{
			form.addResult("msg","请先登录!");
			return module.findPage("login");
		}
		UserInfo obj=null;
		obj=UserInfo.readByUserName(user.getUserName());	
		form.addResult("user",obj);
		form.addResult("messageNum",obj.messageNum());
		form.addResult("replyMessageNum",obj.replyNum());
		form.addResult("eliteMessageNum",obj.eliteMessageNum());
		return module.findPage("controlPan");
	}

	/**
	 * 用户注册码->保存用户注册信息
	 * 
	 * @param form
	 * @param module
	 * @return 注册成功则返回登录Page,失败则返回注册Page
	 */
	public Page doRegSave(WebForm form, Module module) {
		String userName = CommUtil.null2String(form.get("userName"));
		String password = CommUtil.null2String(form.get("password"));
		String password1 = CommUtil.null2String(form.get("password1"));
		if (userName.equals("") || password.equals("")) {
			form.addResult("msg", "用户名及密码不能为空!");
			return module.findPage("reg");
		}
		if (!password.equals(password1)) {
			form.addResult("msg", "两次输入的密码不相同!");
			return module.findPage("reg");
		}
		UserInfo userInfo = new UserInfo();
		userInfo.setUserName(userName);
		userInfo.setPassword(MD5.encode(CommUtil.null2String(form.get("password"))));
		userInfo.setEmail(CommUtil.null2String(form.get("email")));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -