<?php
	//secret kod ve qr oluşturulur, Uygulamadan gelen kod ile giriş yapar
	include '../deppo/tools/script/GoogleAuthenticator.php';
	$ga = new PHPGangsta_GoogleAuthenticator();
	$data 	= file_get_contents('https://cdn.'.$cdnurl.'/data');
	$ws 		= json_decode($data);
	foreach ($ws->data as $item){
		if($item->type=="settings"){
			$secret = $item->secret;
		}
	}
	//$secret = $ga->createSecret();
	//$qrCodeUrl = $ga->getQRCodeGoogleUrl('CrmPlus', $secret);
	$qrCodeUrl = qrCode("".$weburl."/login/".date("Ymd")."",175);
	echo "<center><img src=\"".$qrCodeUrl."\" class=\"auth_qr\" style=\"display:none;\"></center>";
	$qrCodeUrl = $ga->getQRCodeGoogleUrl('CrmPlus', $secret);
	if($_GET["code"]<>""){
		$checkResult = $ga->verifyCode($secret, $_GET["code"], 2);    // 2 = 2*30sec clock tolerance
		if ($checkResult){
			echo "<script>jQuery(document).ready(function(){hide('.authenticator'); AjaxPResult('login_ajx.php?islem=giris','#flogin','#result','505');return false;});</script>";
		} else {
			echo '<?php echo ctranslate("Doğrulama Başarısız");?>';
		}
	}else{
?>
<script>
	jQuery(document).keyup(function(e) {
		if(event.shiftKey && event.which === 81 ) {toggle('.auth_qr');} 
	});
</script>
	<div class="authenticator" style="text-align:center;">
		<input type="number" class="form-control digi" oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);" type = "number" maxlength = "6" id="iaut" data-status="" placeholder="Authenticator" autocomplete="off">
		<div id="result_auth" class=""></div>
	</div>
<?php }?>