<%@language = "javascript" %>
<% /*
    $Revision$
    $Id$

    File:           prs_perslid_otp_new.asp
    Description:    Genereert en toont de persoonlijke QR voor de Google Authenticator
    Parameters:
    Context:
    Note:           Vooralsnog niet bedoeld voor het grote publiek
*/ %>

<!--#include file="../Shared/common.inc"-->
<!--#include file="../Shared/iface.inc"-->
<!--#include file="../Shared/login.inc"-->
<!--#include file="../Shared/encoding.inc" -->
<%
var raw = shared.random(20);
var newsecret = '';
for (var i = 0; i < raw.length; i++)
{
    var chr = raw.charCodeAt(i);
    if (i < 16)
        newsecret += "0";
    newsecret += i.toString(16);
}
Session("otp_secret_temp") = '1$30$6$0$' + newsecret;
//__Log("newsecret: " + newsecret);
%>
<html>
  <head>
<%  FCLTHeader.Generate();
 %>
    <script type='text/javascript'>
        function otp_accept()
        {
            var otp_code = $("#otpcode").val();
            if (otp_code)
            {
                var data = { otp_code: otp_code };
                <% protectRequest.dataToken("data"); %>
                $.post("prs_perslid_otp_new_save.asp", data, FcltCallbackClose, "json");
            }

        }
    </script>
  </head>

  <body class="modal" id="mod_authQR">
<%
    BLOCK_START("", L("lcl_otp_authenticatie_activate"));

    var secret32 = binary_to_base32(hex_to_binary(newsecret));
%>
    <div id="myQRheader"><%=L("lcl_otp_auth_header").format(secret32)%></div>
        <center><img class="QRC" src='./qrcodeotp.asp?size=4&temp=1'></center>
    <div id="myQRfooter"><%=L("lcl_otp_auth_footer")%></div>
    <br>
    <label for='otpcode'><%=L("lcl_otp_auth_verification")%></label>
    <br><input id='otpcode' name='otpcode' type='text'>
<%

    BLOCK_END();
    var buttons =  [ {title: L("lcl_submit"), icon: "opslaan.png", action: "otp_accept()", singlepress: true, id: "btn_accept_submit"  },
                     {title: L("lcl_cancel"), icon: "cancel.png", action: "gen_cancel()" } ];
    CreateButtons(buttons);

    IFACE.FORM_END();

%>
  </body>
</html>
