<commit_before>/**
 * 
 */
package org.bidtime.session;

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

import org.apache.log4j.Logger;
import org.bidtime.memcache.MemcacheManage;
import org.bidtime.memcachesession.SessionMemcache;
import org.bidtime.memcachesession.SessionOnlineMemcache;
import org.bidtime.session.bean.SessionUserBase;

/**
 * @author Administrator
 * 
 */
public class UserSessionMemcache {

	private static final Logger logger = Logger
			.getLogger(UserSessionMemcache.class);
	
	public static String getSessionId(HttpServletRequest req, boolean newSession) {
		return RequestSessionUtils.getSessionId(req, newSession);
	}
	
	public static String getSessionId(HttpServletRequest req) {
		return RequestSessionUtils.getSessionId(req);
	}
	
	public static SessionLoginState getSessionLoginState(HttpServletRequest request) {
		return getSessionLoginState(request, false);
	}
	
	public static SessionLoginState getSessionLoginState(HttpServletRequest request, boolean force) {
		String sessionId = UserSessionMemcache.getSessionId(request, force);
	    // 0:未登陆, 1:正常登陆, 2:被其它用户踢, 3: 没有权限 4: 游客访问商城
	    SessionLoginState sessionLogin = UserSessionMemcache
	            .user_getSessionLoginState(sessionId); // 0:未登陆, 1:正常登陆,2:被其它用户踢
	    return sessionLogin;
	}
	
	public static SessionLoginState getSessionTokenState(HttpServletRequest request, MemcacheManage mm) {
		String token = RequestSessionUtils.getToken(request);
		if (token != null && !token.isEmpty()) {
			String sessionId = (String)SessionOnlineMemcache.getInstance().get(token);
			if (sessionId != null) {
				mm.replace(token, sessionId);
			}
			SessionLoginState sessionLogin = UserSessionMemcache.user_getSessionLoginState(sessionId);
			if (sessionLogin == null) {
				sessionLogin = new SessionLoginState(null, 5);	// 5:token 重新登陆
			}
			return sessionLogin;
		} else {
			return null;
		}
	}
	
	public static void setTokenToSession(HttpServletResponse res, String token, MemcacheManage mm) {
		mm.set("token", token);
		RequestSessionUtils.setToken(res, token, mm.getDefaultTm());
	}
	
	// httpSession_removeAttr
	public static void httpSession_destroyAttr(HttpSession session) {
		httpSession_destroy(session, true);
	}

	// request_logout
	public static void request_logout(HttpServletRequest request) {<commit_msg>UserSessionMemcache<commit_after>/**
 * 
 */
package org.bidtime.session;

import java.util.UUID;

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

import org.apache.log4j.Logger;
import org.bidtime.memcache.MemcacheManage;
import org.bidtime.memcachesession.SessionMemcache;
import org.bidtime.memcachesession.SessionOnlineMemcache;
import org.bidtime.session.bean.SessionUserBase;

/**
 * @author Administrator
 * 
 */
public class UserSessionMemcache {

	private static final Logger logger = Logger
			.getLogger(UserSessionMemcache.class);
	
	public static String getSessionId(HttpServletRequest req, boolean newSession) {
		return RequestSessionUtils.getSessionId(req, newSession);
	}
	
	public static String getSessionId(HttpServletRequest req) {
		return RequestSessionUtils.getSessionId(req);
	}
	
	public static SessionLoginState getSessionLoginState(HttpServletRequest request) {
		return getSessionLoginState(request, false);
	}
	
	public static SessionLoginState getSessionLoginState(HttpServletRequest request, boolean force) {
		String sessionId = UserSessionMemcache.getSessionId(request, force);
	    // 0:未登陆, 1:正常登陆, 2:被其它用户踢, 3: 没有权限 4: 游客访问商城
	    SessionLoginState sessionLogin = UserSessionMemcache
	            .user_getSessionLoginState(sessionId); // 0:未登陆, 1:正常登陆,2:被其它用户踢
	    return sessionLogin;
	}
	
	public static SessionLoginState getSessionTokenState(HttpServletRequest request, MemcacheManage mm) {
		String token = RequestSessionUtils.getToken(request);
		if (token != null && !token.isEmpty()) {
			String sessionId = (String)SessionOnlineMemcache.getInstance().get(token);
			if (sessionId != null) {
				mm.replace(token, sessionId);
			}
			SessionLoginState sessionLogin = UserSessionMemcache.user_getSessionLoginState(sessionId);
			if (sessionLogin == null) {
				sessionLogin = new SessionLoginState(null, 5);	// 5:token 重新登陆
			}
			return sessionLogin;
		} else {
			return null;
		}
	}
	
	public static void setTokenToSession(HttpServletRequest request, HttpServletResponse res, MemcacheManage mm) {
		String token = UUID.randomUUID().toString();
		String sessionId = UserSessionMemcache.getSessionId(request, true);
		mm.set("token", sessionId);
		RequestSessionUtils.setToken(res, token, mm.getDefaultTm());
	}
	
	// httpSession_removeAttr
	public static void httpSession_destroyAttr(HttpSession session) {
		httpSession_destroy(session, true);
	}

	// request_logout
	public static void request_logout(HttpServletRequest request) {
{'fraction_non_alphanumeric': 0.09329034857948822, 'fraction_numerical': 0.004432802740278058, 'mean_word_length': 5.364102564102564, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4737905', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1517, 'n_words': 307}