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

📄 usercheckmgr.java

📁 java阿里巴巴代码
💻 JAVA
字号:
package com.saas.biz.userMgr;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import com.saas.biz.dao.custDAO.CustomerExt;
import com.saas.biz.dao.tcustmerDAO.TcustmerExt;
import com.saas.biz.dao.userDAO.UserDAO;
import com.saas.biz.dao.userDAO.UserExt;
import com.saas.sys.buffer.Buffers;
import com.saas.sys.dbm.Dbtable;
import com.saas.sys.exp.SaasApplicationException;
import com.saas.sys.log.Logger;

/**
 * @author:LiuYang
 * @desc:用户登录
 * @2008-7-7
 */

public class UserCheckMgr {
	
	
	Dbtable tradeQuery;
	
	
	Logger log;
	
	
	Buffers inBuffer;
	
	
	Buffers outBuffer;
	
	
	
	public UserCheckMgr() {

		log = new Logger(this);
		tradeQuery = new Dbtable();
	}
	
	
	public void setTradeQuery(Dbtable tradeQuery) {

		this.tradeQuery = tradeQuery;
	}
	
	
	public Dbtable getTradeQuery() {

		return this.tradeQuery;
	}
	
	
	public void setOutBuffer(Buffers outBuffer) {

		this.outBuffer = outBuffer;
	}
	
	
	public Buffers getOutBuffer() {

		return this.outBuffer;
	}
	
	
	
	/**
	 * 校验用户登陆名称和密码
	 * 
	 * @param inbuffer
	 */
	public void CheckLogin(Buffers inbuffer) {

		log.LOG_INFO("进入CheckLogin方法...");
		this.outBuffer = inbuffer;
		this.inBuffer = inbuffer;
		int iResult = -1;
		String username = inbuffer.getString("USER_NAME").trim();
		String passwd = inbuffer.getString("PASSWD").trim();
		String userrand = inbuffer.getString("USERRAND").trim();
		String randomcode = inbuffer.getString("RANDOMCODE").trim();
		if (userrand.equalsIgnoreCase(randomcode)) {
			
			try {
				iResult = CheckLogin(username, passwd);
				
			}
			catch (SaasApplicationException e) {
				log.LOG_INFO(e.getMessage());
			}
		}
		else {
			iResult = -1;
			this.outBuffer.setString("RESULT_INFO", "校验码输入错误,请返回重新输入!");
		}
		if (iResult != 0) {
			this.outBuffer.setInt("RESULT_LOGIN_CODE", iResult);
			this.outBuffer.setInt("RESULT_CODE", -1);
		}
		else {
			this.outBuffer.setInt("RESULT_CODE", 0);
			this.outBuffer.setString("RESULT_INFO", "业务处理成功!");
		}
		log.LOG_INFO("退出CheckLogin方法...");
	}
	
	
	private int CheckLogin(String username, String passwd) throws SaasApplicationException {

		UserExt userExt = new UserExt();
		UserDAO userDao = new UserDAO();
		ArrayList itemsList = new ArrayList();
		ArrayList custList = new ArrayList();
		String user_id = "";
		String user_name = "";
		String cust_id = "";
		String web_login_tag = "";
		String user_state = "";
		String cust_class = "";
		String cust_name = "";
		String role_code = "";
		String user_type = "";
		String userpasswd = "";
		String depart_code = "";
		if (checktCustInfo(username, passwd) == 0) {
			// String msg = "<a href=/Newcregister.jsp?user_name="+username+">请填写详细企业资料</a>";
			this.outBuffer.setString("RESULT_INFO", username);
			return 10;
		}
		if (checktCustInfo(username, passwd) == -2) {
			String msg = "用户密码错误!";
			this.outBuffer.setString("RESULT_INFO", msg);
			return 11;
		}
		userExt.setParam(":VUSER_NAME", username);
		itemsList = userExt.selByList("SEL_BY_CHECK");
		if (itemsList == null || itemsList.isEmpty()) {
			this.outBuffer.setString("RESULT_INFO", "用户名不存在,请与管理员联系!");
			return 9;
		}
		else {
			Iterator it = itemsList.iterator();
			it.hasNext();
			HashMap itemsListMap = (HashMap) it.next();
			user_id = itemsListMap.get("user_id").toString();
			
			if (itemsListMap.get("rsrv_str3") != null) {
				role_code = itemsListMap.get("rsrv_str3").toString();
			}
			
			if (itemsListMap.get("user_type") != null) {
				user_type = itemsListMap.get("user_type").toString();
			}
			
			user_name = itemsListMap.get("user_name").toString();
			userpasswd = itemsListMap.get("passwd").toString();
			cust_id = itemsListMap.get("cust_id").toString();
			user_state = itemsListMap.get("user_state").toString();
			web_login_tag = itemsListMap.get("web_login_tag").toString();
			cust_class = itemsListMap.get("cust_class").toString();
			if (itemsListMap.get("depart_code") != null)
				depart_code = itemsListMap.get("depart_code").toString();
			custList = genSpecCustInfo(cust_id);
			if (custList != null) {
				Iterator cit = custList.iterator();
				cit.hasNext();
				HashMap cListMap = (HashMap) cit.next();
				cust_name = cListMap.get("cust_name").toString();
			}
		}
		if (userDao == null) {
			return 10;
		}
		if (!userpasswd.trim().equalsIgnoreCase(passwd)) {
			this.outBuffer.setString("RESULT_INFO", "用户密码错误!");
			return 11;
		}
		if (user_state.toString().equals("1")) {
			this.outBuffer.setString("RESULT_INFO", "用户当前状态不允许登录!");
			return 12;
		}
		if (user_state.toString().equals("2")) {
			this.outBuffer.setString("RESULT_INFO", "用户当前状态不允许登录!");
			return 13;
		}
		if (web_login_tag.toString().equals("0")) {
			this.outBuffer.setString("RESULT_INFO", "您的帐号还没有激活,不允许登录,请到注册时候填写的邮箱里收取激活邮件!");
			return 14;
		}
		
		this.outBuffer.setString("SESSION_USER_ID", user_id);
		this.outBuffer.setString("SESSION_CUST_ID", cust_id);
		this.outBuffer.setString("SESSION_USER_NAME", username);
		this.outBuffer.setString("SESSION_CUST_CLASS", cust_class);
		this.outBuffer.setString("DEPART_CODE", depart_code);
		this.outBuffer.setString("SESSION_ROLE_CODE", role_code);
		this.outBuffer.setString("SESSION_USER_TYPE", user_type);
		this.outBuffer.setString("SESSION_CUST_NAME", URLEncoder.encode(cust_name));
		
		this.outBuffer.setSessionField("SESSION_USER_ID");
		this.outBuffer.setSessionField("SESSION_CUST_ID");
		this.outBuffer.setSessionField("SESSION_USER_NAME");
		this.outBuffer.setSessionField("SESSION_CUST_CLASS");
		this.outBuffer.setSessionField("DEPART_CODE");
		this.outBuffer.setSessionField("SESSION_CUST_NAME");
		this.outBuffer.setSessionField("SESSION_ROLE_CODE");
		this.outBuffer.setSessionField("SESSION_USER_TYPE");
		return 0;
	}
	
	
	
	/**
	 * 校验用户登陆名称和密码
	 * 
	 * @前台用户进入后台
	 */
	public void beforeUserLoading(Buffers inbuffer) {

		log.LOG_INFO("进入beforeUserLoading方法...");
		this.outBuffer = inbuffer;
		this.inBuffer = inbuffer;
		int iResult = -1;
		String username = inbuffer.getString("USER_NAME").trim();
		String passwd = inbuffer.getString("PASSWD").trim();
		try {
			iResult = beforeUserLoading(username, passwd);
		}
		catch (SaasApplicationException e) {
			log.LOG_INFO(e.getMessage());
		}
		if (iResult != 0) {
			this.outBuffer.setInt("RESULT_LOGIN_CODE", iResult);
			this.outBuffer.setInt("RESULT_CODE", -1);
		}
		else {
			this.outBuffer.setInt("RESULT_CODE", 0);
			this.outBuffer.setString("RESULT_INFO", "业务处理成功!");
		}
		log.LOG_INFO("退出beforeUserLoading方法...");
	}
	
	
	private int beforeUserLoading(String username, String passwd) throws SaasApplicationException {

		UserExt userExt = new UserExt();
		UserDAO userDao = new UserDAO();
		ArrayList itemsList = new ArrayList();
		ArrayList custList = new ArrayList();
		String user_id = "";
		String cust_id = "";
		String web_login_tag = "";
		String user_state = "";
		String cust_class = "";
		String cust_name = "";
		String role_code = "";
		String user_type = "";
		String userpasswd = "";
		String depart_code = "";
		String user_name = "";
		if (checktCustInfo(username, passwd) == 0) {
			this.outBuffer.setString("RESULT_INFO", username);
			return 10;
		}
		if (checktCustInfo(username, passwd) == -2) {
			String msg = "用户密码错误!";
			this.outBuffer.setString("RESULT_INFO", msg);
			return 11;
		}
		userExt.setParam(":VUSER_NAME", username);
		itemsList = userExt.selByList("SEL_BY_CHECK");
		if (itemsList == null || itemsList.isEmpty()) {
			this.outBuffer.setString("RESULT_INFO", "用户名不存在,请与管理员联系!");
			return 9;
		}
		else {
			Iterator it = itemsList.iterator();
			it.hasNext();
			HashMap itemsListMap = (HashMap) it.next();
			user_id = itemsListMap.get("user_id").toString();
			
			if (itemsListMap.get("rsrv_str3") != null) {
				role_code = itemsListMap.get("rsrv_str3").toString();
			}
			
			if (itemsListMap.get("user_type") != null) {
				user_type = itemsListMap.get("user_type").toString();
			}
			
			user_name = itemsListMap.get("user_name").toString();
			userpasswd = itemsListMap.get("passwd").toString();
			cust_id = itemsListMap.get("cust_id").toString();
			user_state = itemsListMap.get("user_state").toString();
			web_login_tag = itemsListMap.get("web_login_tag").toString();
			cust_class = itemsListMap.get("cust_class").toString();
			if (itemsListMap.get("depart_code") != null)
				depart_code = itemsListMap.get("depart_code").toString();
			custList = genSpecCustInfo(cust_id);
			if (custList != null) {
				Iterator cit = custList.iterator();
				cit.hasNext();
				HashMap cListMap = (HashMap) cit.next();
				cust_name = cListMap.get("cust_name").toString();
			}
		}
		if (userDao == null) {
			return 10;
		}
		if (!userpasswd.trim().equalsIgnoreCase(passwd)) {
			this.outBuffer.setString("RESULT_INFO", "用户密码错误!");
			return 11;
		}
		if (user_state.toString().equals("1")) {
			this.outBuffer.setString("RESULT_INFO", "用户当前状态不允许登录!");
			return 12;
		}
		if (user_state.toString().equals("2")) {
			this.outBuffer.setString("RESULT_INFO", "用户当前状态不允许登录!");
			return 13;
		}
		if (web_login_tag.toString().equals("0")) {
			this.outBuffer.setString("RESULT_INFO", "您的帐号还没有激活,不允许登录,请到注册时候填写的邮箱里收取激活邮件!");
			return 14;
		}
		
		this.outBuffer.setString("SESSION_USER_ID", user_id);
		this.outBuffer.setString("SESSION_CUST_ID", cust_id);
		this.outBuffer.setString("SESSION_USER_NAME", username);
		this.outBuffer.setString("SESSION_CUST_CLASS", cust_class);
		this.outBuffer.setString("DEPART_CODE", depart_code);
		this.outBuffer.setString("SESSION_ROLE_CODE", role_code);
		this.outBuffer.setString("SESSION_USER_TYPE", user_type);
		this.outBuffer.setString("SESSION_CUST_NAME", URLEncoder.encode(cust_name));
		
		this.outBuffer.setSessionField("SESSION_USER_ID");
		this.outBuffer.setSessionField("SESSION_CUST_ID");
		this.outBuffer.setSessionField("SESSION_USER_NAME");
		this.outBuffer.setSessionField("SESSION_CUST_CLASS");
		this.outBuffer.setSessionField("DEPART_CODE");
		this.outBuffer.setSessionField("SESSION_CUST_NAME");
		this.outBuffer.setSessionField("SESSION_ROLE_CODE");
		this.outBuffer.setSessionField("SESSION_USER_TYPE");
		return 0;
		
	}
	
	
	
	// 判断用户名是否存在
	public boolean Exists(String username) {

		UserExt userExt = new UserExt();
		
		userExt.setParam(":VUSER_NAME", username);
		ArrayList list = userExt.selByList("SEL_BY_CHECK");
		
		if (list != null && list.size() != 0)
			return false;
		else
			return true;
	}
	
	
	public HashMap Exists(String username, String password) throws SaasApplicationException {

		UserExt userExt = new UserExt();
		HashMap map = new HashMap();
		userExt.setParam(":VUSER_NAME", username);
		ArrayList list = userExt.selByList("SEL_BY_CHECK");
		if (list != null && list.size() > 0) {
			map = (HashMap) list.get(0);
		}
		return map;
	}
	
	
	public ArrayList genSpecCustInfo(String cust_id) throws SaasApplicationException {

		ArrayList itemsList = new ArrayList();
		CustomerExt customerExt = new CustomerExt();
		customerExt.setParam(":VCUST_ID", cust_id);
		itemsList = customerExt.selByList("SEL_SPEC_CUST");
		return itemsList;
	}
	
	
	public int checktCustInfo(String user_name, String pwd) throws SaasApplicationException {

		ArrayList itemsList = new ArrayList();
		String userpasswd = "";
		TcustmerExt tcustomerExt = new TcustmerExt();
		tcustomerExt.setParam(":VUSER_NAME", user_name);
		tcustomerExt.setParam(":VCUST_STATE", '0');
		itemsList = tcustomerExt.selByList("SEL_BY_USER");
		if (itemsList != null && itemsList.size() != 0) {
			Iterator it = itemsList.iterator();
			it.hasNext();
			HashMap itemsListMap = (HashMap) it.next();
			
			userpasswd = itemsListMap.get("password").toString();
			if (!userpasswd.equals(pwd)) {
				return -2;
			}
			else {
				return 0;
			}
		}
		else {
			
			return -1;
		}
	}
}

⌨️ 快捷键说明

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