<commit_before><?php
session_start();
require_once('conn.php');
require_once('../libs/Bcrypt.php');

$bcrypt = new Bcrypt(15);

$action = $_POST['action'];

switch($action){
	case 'sign_up':
		$email 		= $_POST['email'];
		$password	= $_POST['pword'];
		
		$salt = $bcrypt->getSalt(); 
		$hash = $bcrypt->hash($password, $salt);
		
		if($query = $db->prepare("INSERT INTO tbl_users SET email = ?, hashed_password = ?, salt = ?")){
			$query->bind_param("sss", $email, $hash, $salt);
			$query->execute();
			$uid = $query->insert_id;
			
			$get_networks = $db->query("SELECT sid FROM tbl_settings");
			if($get_networks->num_rows > 0){
				
				while($row = $get_networks->fetch_object()){
					$sid = $row->sid;
					$db->query("INSERT INTO tbl_usersettings SET uid = '$uid', sid = '$sid', status = 0");
				}
			
			}
			echo $uid;
		}
	
	break;
	
	case 'login':
		$email 		= $db->real_escape_string($_POST['email']);
		$password	= $db->real_escape_string($_POST['pword']);
		
		$select_salt = $db->query("SELECT salt FROM tbl_users WHERE email = '$email'");
		if($select_salt->num_rows > 0){
			$row = $select_salt->fetch_object();
			$salt = $row->salt;
			
			$hash = $bcrypt->hash($password, $salt);
			
			$select_user = $db->query("SELECT uid FROM tbl_users WHERE email = '$email' AND hashed_password = '$hash'");
			if($select_user->num_rows > 0){
				$row = $select_user->fetch_object();
				$uid = $row->uid;
				$_SESSION['uid'] = $uid; 
				$_SESSION['email'] = $email;
				
				echo $uid;
			}
		}
		
	break;
	
	case 'set':
		$uid = $_SESSION['uid'];
		$sid = $_POST['sid'];
		$status = $_POST['status'];
		
		$db->query("UPDATE tbl_usersettings SET status = '$status' WHERE uid = '$uid' AND sid = '$sid'");
	break;
	
	case 'load_set':
		$uid = $_SESSION['uid'];
		$settings = [];
		$get_settings = $db->query("SELECT sid, status FROM tbl_usersettings WHERE uid = '$uid'");
		if($get_settings->num_rows > 0){
			while($row = $get_settings->fetch_object()){
				$sid = $row->sid;
				$status = $row->status;
				$settings[] = ['sid'=>$sid, 'status'=>$status];
			}
		}
		echo json_encode($settings);
	break;
	
	case 'get_uid':
		echo $_SESSION['uid'];
	break;
	
	case 'logout':
		session_destroy();
	break;
}

?><commit_msg>remove code for accessing user setting on database<commit_after><?php
session_start();
require_once('conn.php');
require_once('../libs/Bcrypt.php');

$bcrypt = new Bcrypt(15);

$action = $_POST['action'];

switch($action){
	case 'sign_up':
		$email 		= $_POST['email'];
		$password	= $_POST['pword'];
		
		$salt = $bcrypt->getSalt(); 
		$hash = $bcrypt->hash($password, $salt);
		
		if($query = $db->prepare("INSERT INTO tbl_users SET email = ?, hashed_password = ?, salt = ?")){
			$query->bind_param("sss", $email, $hash, $salt);
			$query->execute();
			$uid = $query->insert_id;
		
			echo $uid;
		}
	
	break;
	
	case 'login':
		$email 		= $db->real_escape_string($_POST['email']);
		$password	= $db->real_escape_string($_POST['pword']);
		
		$select_salt = $db->query("SELECT salt FROM tbl_users WHERE email = '$email'");
		if($select_salt->num_rows > 0){
			$row = $select_salt->fetch_object();
			$salt = $row->salt;
			
			$hash = $bcrypt->hash($password, $salt);
			
			$select_user = $db->query("SELECT uid FROM tbl_users WHERE email = '$email' AND hashed_password = '$hash'");
			if($select_user->num_rows > 0){
				$row = $select_user->fetch_object();
				$uid = $row->uid;
				$_SESSION['uid'] = $uid; 
				$_SESSION['email'] = $email;
				
				echo $uid;
			}
		}
		
	break;
	
	case 'get_uid':
		echo $_SESSION['uid'];
	break;
	
	case 'logout':
		session_destroy();
	break;
}

?>
{'fraction_non_alphanumeric': 0.2079316992564032, 'fraction_numerical': 0.003029468465987331, 'mean_word_length': 3.7477124183006536, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 58, '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': '7348188', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1301, 'n_words': 266}