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

    File:           prs_perslid_otp_new_save.asp.asp
    Description:    Verifieert een temp otp-code en maakt hem eventueel definitief
    Parameters:
    Context:        Vanuit prs_perslid_otp_new.asp
    Note:
*/
var JSON_Result = true;
%>

<!--#include file="../Shared/common.inc"-->
<!--#include file="../Shared/login.inc"-->
<!-- #include file="../Shared/json2.js" -->
<%
protectRequest.validateToken();

var otp_code = getFParam("otp_code");
var otp_secret = Session("otp_secret_temp");
var otp_counter = -1;

if (!verify_otp(otp_code, otp_secret , -1))
    abort_with_warning(L("lcl_otp_wrong"));

var sql = "UPDATE prs_perslid"
        + "   SET prs_perslid_otpsecret = " + safe.quoted_sql(otp_secret)
        + "     , prs_perslid_otpcounter = " + otp_counter
        + " WHERE prs_perslid_key = " + user_key;
Oracle.Execute(sql);

var result = { success: user_key > 0, message: L("lcl_otp_saved") };

Response.Write(JSON.stringify(result));
Response.End;
%>
