从session中取 登陆用户

	/**
	 * 系统登录
	 * @param username
	 * @param password 此处为未经过md5加密的密码
	 * @return 返回登录成功的用户id
	 * @throws RuntimeException 登录失败抛出此异常,登录失败原因可通过getMessage()方法获取
	 */
	public int loginBySys(String username, String password) {
		String sql ="select * from adminuser where username=?";
		List<AdminUser> userList =  this.baseDaoSupport.queryForList(sql,AdminUser.class, username);
		if(userList == null || userList.size()==0){
			throw new RuntimeException("此用户不存在");
		}
		AdminUser user = userList.get(0);
		
		
		if(! password.equals(  user.getPassword() )){
			throw new RuntimeException("密码错误");
		}
		
		if(user.getState()==0){
			throw new RuntimeException("此用户已经被禁用");
		} 
		
		EopSite site  = EopContext.getContext().getCurrentSite(); 
		
		// 开启多站点功能
		if(site.getMulti_site()==1){
			if(user.getFounder()!=1){ //非超级管理员检测是否是站点管理员
				 MultiSite childSite = EopContext.getContext().getCurrentChildSite();
				 if(user.getSiteid()==null || childSite.getSiteid()!=user.getSiteid()){
					 throw new RuntimeException("非此站点管理员");
				 }
			}
		}
		
		//更新月登录次数和此站点的最后登录时间
		int logincount = site.getLogincount();
		long lastlogin  =( (long)site.getLastlogin() )* 1000;
		Date today = new Date();
		if(DateUtil.toString(new Date(lastlogin), "yyyy-MM").equals(DateUtil.toString(today, "yyyy-MM"))){//与上次登录在同一月内
			logincount++;
		}else{
			logincount = 1;
		}
		
		site.setLogincount(logincount);
		site.setLastlogin(DateUtil.getDateline());
		this.daoSupport.execute("update eop_site set logincount=?, lastlogin=? where id=?", logincount,site.getLastlogin(),site.getId());
		
		//记录session信息
		WebSessionContext  sessonContext = ThreadContextHolder
		.getSessionContext();			
		UserContext userContext = new UserContext(site.getUserid(),
				site.getId(), user.getUserid());
		sessonContext.setAttribute(UserContext.CONTEXT_KEY, userContext);
		sessonContext.setAttribute("admin_user_key", user);
		
		return user.getUserid();
	}	

取的时候加上这句话
	WebSessionContext<EopUser> sessonContext = ThreadContextHolder
		.getSessionContext();	
		

             sessonContext.getAttribute("admin_user_key");


你可能感兴趣的:(session)