<commit_before><?php

require_once APPPATH.'classes/usersession.php';
require_once APPPATH.'classes/user.php';

class AuthStatus
{
	const TRUSTREQUIRED = 0;
	const NOACCESS = 1;
	const GPASSWRONG = 2;

	const ACCEPTED = 3;

	//igb state default state/not logged in
	const APILOGINREQUIRED = 4;

	//bad key or api errored
	const APILOGININVALID = 5;

	//nuff said
	const APILOGINNOTENABLED = 6;

	//api char has no access/group
	const APILOGINNOACCESS = 7;
	
	const BLACKLISTED = 9;
	
	const GUEST = 8;
}


class Auth
{
	const LOGIN_INVALID = 1;
	const LOGIN_PASSFAIL = 2;
	const LOGIN_SUCCESS = 3;

	private static $hashKey = "<KEY>";
	
	public static $session = null;
	
	public static $user = null;
	public static $authStatus = AuthStatus::NOACCESS;
	
	public static function initialize()
	{
		self::$user = new User();
		self::$session = new UserSession();
	}
	
	public static function authenticate()
	{
		if( !self::$session->charID  )
		{
			self::$authStatus = AuthStatus::GUEST;
			return self::$authStatus;
		}
		
		if( miscUtils::isIGB() )
		{
			if( !miscUtils::getTrust() )
			{
				self::$authStatus = AuthStatus::TRUSTREQUIRED;
				return self::$authStatus;
			}
		}
		
		$success = TRUE;
		if( self::loggedIn() )
		{
			$success = self::$user->validateCorpChar();
		}
		
		if( !$success || !self::$session->charID || !self::$session->corpID )
		{
			self::$authStatus = AuthStatus::NOACCESS;
			return self::$authStatus;
		}
		
		if( self::$session->groupID )
		{
			if( self::$session->accessData['api_login_required'] && !self::loggedIn() )
			{
				self::$authStatus = AuthStatus::APILOGINREQUIRED;
			}
			else if( isset( self::$session->accessData['character_blacklist'] ) && 
						array_key_exists( self::$session->charID, self::$session->accessData['character_blacklist'] ) )
			{
				self::$authStatus = AuthStatus::BLACKLISTED;
			}
			else if( self::$session->accessData['group_password_required'] )	//group password only?
			{
				$groupID = intval(self::$session->accessData['groupID']);
				$authPassword = '';
				
				if( self::loggedIn() )
				{
					$authPassword = self::$user->getSavedPassword( $groupID );
				}
				else<commit_msg>Temp fix the fact that groupID in the user data will cause issues when the group has no members but you access the siggy main page. Need to probably split the groupID for access from management groupID as two columns.<commit_after><?php

require_once APPPATH.'classes/usersession.php';
require_once APPPATH.'classes/user.php';

class AuthStatus
{
	const TRUSTREQUIRED = 0;
	const NOACCESS = 1;
	const GPASSWRONG = 2;

	const ACCEPTED = 3;

	//igb state default state/not logged in
	const APILOGINREQUIRED = 4;

	//bad key or api errored
	const APILOGININVALID = 5;

	//nuff said
	const APILOGINNOTENABLED = 6;

	//api char has no access/group
	const APILOGINNOACCESS = 7;
	
	const BLACKLISTED = 9;
	
	const GUEST = 8;
}


class Auth
{
	const LOGIN_INVALID = 1;
	const LOGIN_PASSFAIL = 2;
	const LOGIN_SUCCESS = 3;

	private static $hashKey = "<KEY>";
	
	public static $session = null;
	
	public static $user = null;
	public static $authStatus = AuthStatus::NOACCESS;
	
	public static function initialize()
	{
		self::$user = new User();
		self::$session = new UserSession();
	}
	
	public static function authenticate()
	{
		if( !self::$session->charID  )
		{
			self::$authStatus = AuthStatus::GUEST;
			return self::$authStatus;
		}
		
		if( miscUtils::isIGB() )
		{
			if( !miscUtils::getTrust() )
			{
				self::$authStatus = AuthStatus::TRUSTREQUIRED;
				return self::$authStatus;
			}
		}
		
		$success = TRUE;
		if( self::loggedIn() )
		{
			$success = self::$user->validateCorpChar();
		}
		
		if( !$success || !self::$session->charID || !self::$session->corpID || empty(self::$session->accessData) )
		{
			self::$authStatus = AuthStatus::NOACCESS;
			return self::$authStatus;
		}
		
		if( self::$session->groupID )
		{
			if( self::$session->accessData['api_login_required'] && !self::loggedIn() )
			{
				self::$authStatus = AuthStatus::APILOGINREQUIRED;
			}
			else if( isset( self::$session->accessData['character_blacklist'] ) && 
						array_key_exists( self::$session->charID, self::$session->accessData['character_blacklist'] ) )
			{
				self::$authStatus = AuthStatus::BLACKLISTED;
			}
			else if( self::$session->accessData['group_password_required'] )	//group password only?
			{
				$groupID = intval(self::$session->accessData['groupID']);
				$authPassword = '';
				
				if( self::loggedIn() )
				{
					$authPassword = self::$user->getSavedPassword( $groupID );
				}
				else
{'fraction_non_alphanumeric': 0.14541876230045922, 'fraction_numerical': 0.005685545593702165, 'mean_word_length': 3.7895287958115182, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 30, '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': '3281103', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1573, 'n_words': 349}