<?php

	include("../M6/2FAS_Authenticator.php");

	include("../M0/session_start.php") ;
	
	if ( ! empty( $_POST['TOTP_CODE'] ) ) {
		
		$TOTP_code = $_POST['TOTP_CODE'];
		
		$TOTP_is_valid = Authenticator::verifyCode($USER_2FAS_SECRET, $TOTP_code);

		if ( $TOTP_is_valid ) {
			
			$_SESSION['code_2FA_msg']		= "";
			$_SESSION['2FA_code_erreur']	= 22 ;
			$_SESSION['admin_2FA']			= true ;
			log_string( "AQCM05", "NOTICE ---> " . "accès aux menus d'administration pour : " . $_SESSION['login'] . " : succès... #22" ) ;
			$_SESSION['admin_menus']		= true ;
			header('Location: ./index.php');
			exit();
		}
		else {
			$_SESSION['code_2FA_msg'] = "code $TOTP_code incorrect !!!";
			$_SESSION['2FA_code_erreur'] 	= 24 ;
			$_SESSION['admin_2FA'] 			= false ;
			log_string( "AQCM05", "NOTICE ---> " . "accès aux menus d'administration pour : " . $_SESSION['login'] . " : échec !!! #24" ) ;
			$_SESSION['admin_menus']		= false ;
			header('Location: ./index.php');
			exit();
		}
			
	}
	else {
		$_SESSION['code_2FA_msg'] = "veuillez saisir un code à 6 chiffres !";
		$_SESSION['2FA_code_erreur'] 	= 25 ;
		$_SESSION['admin_2FA'] 			= false ;
		log_string( "AQCM05", "NOTICE ---> " . "accès aux menus d'administration pour : " . $_SESSION['login'] . " : échec !!! #25" ) ;
		$_SESSION['admin_menus']		= false ;
		header('Location: ./index.php');
		exit();
	}
	
?>
	

	
