首页>代码>Jsp论坛系统(BBS)源码>/Jsp论坛源码/BBS/src/com/yxq/action/LogXAction.java
package com.yxq.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;

import com.yxq.actionform.UserForm;
import com.yxq.dao.OpDB;
import com.yxq.tools.Change;

public class LogXAction extends DispatchAction {
	
	/** 前台登录判断 */
	public ActionForward isUserLogin(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
		HttpSession session=request.getSession();
		Object loginer=session.getAttribute("logoner");
		if(loginer!=null&&(loginer instanceof UserForm)){			
			ActionMessages messages=new ActionMessages();
			messages.add("loginR",new ActionMessage("luntan.bbs.have.login"));
			saveErrors(request,messages);
			return mapping.findForward("FhaveLogin");
		}
		else{
			return mapping.findForward("noLogin");			
		}
	}
	/** 后台登录判断 */
	public ActionForward isAdminLogin(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
		ActionMessages messages=new ActionMessages();
		HttpSession session=request.getSession();
		Object obj=session.getAttribute("logoner");
		if(obj!=null&&(obj instanceof UserForm)){
			UserForm logoner=(UserForm)obj;
			String able=logoner.getUserAble();

			if(!able.equals("2")){				
				messages.add("loginR",new ActionMessage("luntan.bbs.loginBack.N"));
				saveErrors(request,messages);
				return mapping.findForward("noAble");				
			}
			else{
				return mapping.findForward("BhaveLogin");
			}
		}
		else{			
			messages.add("loginR",new ActionMessage("luntan.bbs.loginBack.E"));
			saveErrors(request,messages);
			return mapping.findForward("noLogin");			
		}
	}	
	/** 登录 */
	public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
		HttpSession session=request.getSession();
		UserForm logoner=(UserForm)form;
		String userName=Change.HTMLChange(logoner.getUserName());
		String userPassword=Change.HTMLChange(logoner.getUserPassword());
		
		String sql="select * from tb_user where user_name=? and user_password=?";
		Object[] params={userName,userPassword};
		
		ActionMessages messages=new ActionMessages();
		OpDB myOp=new OpDB();
		logoner=myOp.OpUserSingleShow(sql, params);
		if(logoner!=null){			
			session.setAttribute("logoner",logoner);
			return (mapping.findForward("success"));
		}
		else{			
			messages.add("loginR",new ActionMessage("luntan.bbs.login.E"));
			saveErrors(request,messages);
			return mapping.findForward("fault");
		}		
	}
	/** 注销 */
	public ActionForward logout(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
		HttpSession session=request.getSession();
		session.invalidate();
		return mapping.findForward("logout");
	}
	/** 用户注册 */
	public ActionForward userReg(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
		ActionMessages messages=new ActionMessages();
		HttpSession session=request.getSession();
		session.setAttribute("mainPage","../pages/userReg.jsp");
		
		String validate=request.getParameter("validate");
		if(validate==null||validate.equals("")||!validate.equals("yes")){
			return mapping.findForward("result");
		}
		else{			
			UserForm regForm=(UserForm)form;
			
			String pass1=regForm.getUserPassword();
			String pass2=regForm.getAginPassword();
			if(!pass1.equals(pass2)){
				System.out.println("两次输入的密码不一致!");
				messages.add("userPassword",new ActionMessage("luntan.user.reg.pass.noEquals"));
				saveErrors(request,messages);				
			}
			else{
				String userName=Change.HTMLChange(regForm.getUserName());
				
				Object[] params=null;
				String sql="";
				
				sql="select * from tb_user where user_name=?";
				params=new Object[1];
				params[0]=userName;
				
				OpDB myOp=new OpDB();
				UserForm user=myOp.OpUserSingleShow(sql, params);
				
				if(user!=null){
					System.out.println(userName+" 用户已经存在!");
					messages.add("userOpR",new ActionMessage("luntan.user.reg.exist",userName));
				}
				else{
					String userPassword=Change.HTMLChange(regForm.getUserPassword());
					String userFace=regForm.getUserFace();
					String userSex=regForm.getUserSex();
					String userPhone=regForm.getUserPhone();
					String userOICQ=regForm.getUserOICQ();
					String userEmail=regForm.getUserEmail();
					String userFrom=Change.HTMLChange(regForm.getUserFrom());
					String userAble="0";
					
					sql="insert into tb_user values(null,?,?,?,?,?,?,?,?,?)";
					params=new Object[9];
					params[0]=userName;
					params[1]=userPassword;
					params[2]=userFace;
					params[3]=userSex;
					params[4]=userPhone;
					params[5]=userOICQ;
					params[6]=userEmail;
					params[7]=userFrom;
					params[8]=userAble;
					
					int i=myOp.OpUpdate(sql, params);				
					if(i<=0){
						System.out.println("用户注册失败!");
						messages.add("userOpR",new ActionMessage("luntan.user.reg.E"));
					}
					else{
						System.out.println("用户注册成功!");
						regForm.clear();
						messages.add("userOpR",new ActionMessage("luntan.user.reg.S"));
					}				
					saveErrors(request,messages);		
				}				
			}			
			return mapping.findForward("result");		
		}
	}	
}
最近下载更多
lvhongquan  LV11 2023年12月31日
taoshen95  LV16 2023年12月28日
wubinbin  LV11 2023年4月14日
orenji  LV1 2022年9月19日
yazhiyjs  LV4 2022年8月30日
NCC7470597  LV1 2022年6月15日
yihongyuan  LV13 2022年5月7日
微信网友_5933062541053952  LV2 2022年4月27日
yangyangmei  LV1 2022年4月25日
3332hjjj  LV1 2022年4月15日
最近浏览更多
暂无贡献等级
ChanLain  LV2 3月3日
微信网友_7300409508155392 2024年12月17日
暂无贡献等级
短巷拥猫  LV12 2024年10月22日
Rinkia 2024年3月28日
暂无贡献等级
xiaopengzep  LV1 2024年3月25日
wttttts  LV2 2024年1月1日
shenfan  LV1 2024年1月1日
lvhongquan  LV11 2023年12月30日
taoshen95  LV16 2023年12月28日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友