<commit_before><?php

require_once PUMPCMS_SYSTEM_PATH . '/util.php';

class User_Model extends PC_Model {
    
    const TEMP_ENABLE_TIME = 3600; // 60 * 60 * 10
    
    var $_user_data;
    var $_check_password = true;
    var $_check_email = true;

	function __construct() {
		$this->table_name = 'user_user';
	}
	
	function register($user) {

		$db = PC_DBSet::get();

		$sql = 'INSERT INTO ' . $db->prefix($this->table_name);
		$sql .= " (site_id, name, password, email, type, reg_time ) VALUES ";
	        $sql .= " ( ";
	    $sql .= intval(SiteInfo::get_site_id()) . ', ';
		$sql .= " " . $db->escape($user['name']) . ", ";
		$sql .= " " . $db->escape(@$user['password']). ", ";
		$sql .= " " . $db->escape(@$user['email']) . ", ";
		$sql .= " '" . intval(@$user['type']) . "', ";
		$sql .= " " . time(). " ";
	        $sql .= " ) ";

		return $db->query($sql);
		
	}
	
	function login() {
	
		$error = $this->login_validate();
		
		if (count($error) == 0) {
			$this->update_last_login_time($this->_user_data['id']);
			$_SESSION['pump_'. PC_Config::get('site_id')]['user'] = $this->_user_data;
			PC_Notification::set(_MD_USER_LOGINED);
			ActionLog::log(ActionLog::LOGIN);

			$this->load_rel_user($this->_user_data['id']);
			
			if (empty($_SESSION['from_url'])) {
				PC_Util::redirect_top();
			} else {
				PC_Util::redirect_top();
				//PC_Util::redirect(PC_Config::url() . $_SESSION['from_url']);
			}
		} else {
			return $error;
		}
	}
	
	function logout() {
		ActionLog::log(ActionLog::LOGOUT);
		unset($_SESSION['pump_'. PC_Config::get('site_id')]);
		PC_Notification::set(_MD_USER_LOGOUT);
		PC_Util::redirect_top();
	}

	function load_rel_user($user_id) {
		$user_rel_ormap = PumpORMAP_Util::get('user', 'user_rel');
		$list = $user_rel_ormap->get_list('user_id1 = ' . intval($user_id) . ' OR user_id2 = ' . intval($user_id), 0, 10);

		$rel_user_list = array();
		foreach ($list as $item) {
			if ($item['user_id1'] == $user_id) {
				$tmp_id = $item['user_id2'];
			} else {
				$tmp_id = $item['user_id1'];
			}

			array_push($rel_user_list, $this->get_user_by_id($tmp_id));
		}

		UserInfo::set('rel_user_list', $rel_user_list);

		return $rel_list;
	}

	function switch($to_user_id) {
		if (! UserInfo::is_logined()) {
			exit();
		}

		$user_rel_ormap = PumpORMAP_Util::get('user', 'user_rel');
		if (UserInfo::get_id() < $to_user_id) {
			$user_id1 = UserInfo::get_id();
			$user_id2 = $to_user_id;
		} else {
			$user_id1 = $to_user_id;
			$user_id2 = UserInfo::get_id();
		}
		$list = $user_rel_ormap->get_list('user_id1 = ' . intval($user_id1) . ' OR user_id2 = ' . intval($user_id2), 0, 1);

		if (empty($list)) {
			exit();
		}

		$user_id = $to_user_id;

		$user = $this->get_user_by_id($user_id);

		$this->update_last_login_time($user['id']);
		$_SESSION['pump_'. PC_Config::get('site_id')]['user'] = $user;
		PC_Notification::set(_MD_USER_SWITCH_USER);
		ActionLog::log(ActionLog::LOGIN);<commit_msg>bugfix<commit_after><?php

require_once PUMPCMS_SYSTEM_PATH . '/util.php';

class User_Model extends PC_Model {
    
    const TEMP_ENABLE_TIME = 3600; // 60 * 60 * 10
    
    var $_user_data;
    var $_check_password = true;
    var $_check_email = true;

	function __construct() {
		$this->table_name = 'user_user';
	}
	
	function register($user) {

		$db = PC_DBSet::get();

		$sql = 'INSERT INTO ' . $db->prefix($this->table_name);
		$sql .= " (site_id, name, password, email, type, reg_time ) VALUES ";
	        $sql .= " ( ";
	    $sql .= intval(SiteInfo::get_site_id()) . ', ';
		$sql .= " " . $db->escape($user['name']) . ", ";
		$sql .= " " . $db->escape(@$user['password']). ", ";
		$sql .= " " . $db->escape(@$user['email']) . ", ";
		$sql .= " '" . intval(@$user['type']) . "', ";
		$sql .= " " . time(). " ";
	        $sql .= " ) ";

		return $db->query($sql);
		
	}
	
	function login() {
	
		$error = $this->login_validate();
		
		if (count($error) == 0) {
			$this->update_last_login_time($this->_user_data['id']);
			$_SESSION['pump_'. PC_Config::get('site_id')]['user'] = $this->_user_data;
			PC_Notification::set(_MD_USER_LOGINED);
			ActionLog::log(ActionLog::LOGIN);

			$this->load_rel_user($this->_user_data['id']);
			
			if (empty($_SESSION['from_url'])) {
				PC_Util::redirect_top();
			} else {
				PC_Util::redirect_top();
				//PC_Util::redirect(PC_Config::url() . $_SESSION['from_url']);
			}
		} else {
			return $error;
		}
	}
	
	function logout() {
		ActionLog::log(ActionLog::LOGOUT);
		unset($_SESSION['pump_'. PC_Config::get('site_id')]);
		PC_Notification::set(_MD_USER_LOGOUT);
		PC_Util::redirect_top();
	}

	function load_rel_user($user_id) {
		$user_rel_ormap = PumpORMAP_Util::get('user', 'user_rel');
		$list = $user_rel_ormap->get_list('user_id1 = ' . intval($user_id) . ' OR user_id2 = ' . intval($user_id), 0, 10);

		$rel_user_list = array();
		foreach ($list as $item) {
			if ($item['user_id1'] == $user_id) {
				$tmp_id = $item['user_id2'];
			} else {
				$tmp_id = $item['user_id1'];
			}

			array_push($rel_user_list, $this->get_user_by_id($tmp_id));
		}

		UserInfo::set('rel_user_list', $rel_user_list);

		return $rel_user_list;
	}

	function switch($to_user_id) {
		if (! UserInfo::is_logined()) {
			exit();
		}

		$user_rel_ormap = PumpORMAP_Util::get('user', 'user_rel');
		if (UserInfo::get_id() < $to_user_id) {
			$user_id1 = UserInfo::get_id();
			$user_id2 = $to_user_id;
		} else {
			$user_id1 = $to_user_id;
			$user_id2 = UserInfo::get_id();
		}
		$list = $user_rel_ormap->get_list('user_id1 = ' . intval($user_id1) . ' OR user_id2 = ' . intval($user_id2), 0, 1);

		if (empty($list)) {
			exit();
		}

		$user_id = $to_user_id;

		$user = $this->get_user_by_id($user_id);

		$this->update_last_login_time($user['id']);
		$_SESSION['pump_'. PC_Config::get('site_id')]['user'] = $user;
		PC_Notification::set(_MD_USER_SWITCH_USER);
		ActionLog::log(ActionLog::LOGIN);
{'fraction_non_alphanumeric': 0.21292517006802722, 'fraction_numerical': 0.009863945578231292, 'mean_word_length': 3.872410936205468, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, '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': '4106298', 'n_tokens_mistral': 2616, 'n_tokens_neox': 2321, 'n_words': 325}