<?php

	// Check nonce
	PHPCUS_PARAM::CUS_REQUIRES_NONCE();
	
	// Check Array Input
	PHPCUS_PARAM::CUS_DOES_NOT_SUPPORT_ARRAY();
	
	// Check already authenticated
	if(PHPCUS_PARAM::CUS_IS_AUTHENTICATED() === True)
	{
		// PHPCUS_PARAM::CUS_JSON_ERROR('Already authenticated. Please sign-out first before switching between user.');
	}
	
	// Process request
	if
	(
			PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
			(
					[
							'PARAM_ACCOUNT_USERNAME',
							'PARAM_ACCOUNT_PASSWORD'
					], True
			)
	)
	{
		Try
		{

			
			// Read params
			// ------------------------------------------------------------------
			$PARAM_ACCOUNT_USERNAME = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ACCOUNT_USERNAME');
			$PARAM_ACCOUNT_PASSWORD = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ACCOUNT_PASSWORD');
			// ------------------------------------------------------------------
					
			// Execute Stored Procedure
			$DATA_SET = PHPCUS_Account_Member::CUS_LOGIN
						(
								$PARAM_ACCOUNT_USERNAME, 
								$PARAM_ACCOUNT_PASSWORD
						);
						
			// Return JSON response
			if(empty($DATA_SET) === False && $DATA_SET === True)
			{
				PHPCUS_PARAM::CUS_JSON_SUCCESS('');	
			}
			else
			{
				PHPCUS_PARAM::CUS_JSON_ERROR('Invalid username or password.');
			}
			
		}
		Catch(Exception $ERR)
		{
			PHPVC_LOG::VAR_REPORT_ERROR($ERR, 0);
			PHPCUS_PARAM::CUS_JSON_ERROR($ERR->getMessage());
		}
	}
	else
	{
		PHPCUS_PARAM::CUS_JSON_ERROR('Missing parameters');
	}

?>