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

    File:           idp_self_register.asp
    Description:    Voor als je via een IdP zelfregistratie wilt aanbieden
    Parameters:     redirect_uri
                    return_to
                    aud
                    state
    Context:        Vanuit een IdP
    Note:           Roept idp_self_register.asp twee keer aan
                    De eerste keer zonder token, die wordt aangemaakt en gemaild
                    De tweede keer met token, dan wordt de user (via een JWT) teruggeleid/aangemaakt
*/
ANONYMOUS_Allowed = 1;

%>
<!--#include file="../Shared/common.inc"-->
<!--#include file="../Shared/iface.inc"-->
<%
if (S("self_register") != 1)
   shared.simpel_page(L("lcl_no_auth"));

var transitParam = buildTransitParam(["redirect_uri", "return_to"]);
var email      = getQParam("prs_email", "");
%>

<html id="loginhtml">
  <head>
<%  FCLTHeader.Generate(); %>
    <script>
        function login_callback(json)
        {
            if (json.success && json.emailtokenprompt)
            {
                $("#langtoggle, .loginname, .loginpass, .remember").hide(); // Ingevulde usernaam/ wachtwoord laten we bewust staan
                $("tr.trmailtoken").show();            // en submitten we een tweede keer maar dan met mailtoken
                FcltMgr.resized();
                //$("tr.trmailtoken").find("label").html(json.emailtokenprompt);
            }
            else if (json.success && json.redirect_uri)
            {
                window.location.href = json.redirect_uri;
            }
            else
            {
                window.top.location.href = "<%=rooturl + "/"%>"; // ik geef het op
            }
        }

        async function self_submit()
        {
	 		if (!await validateForm("u2"))
	    	    return false;
            $.post($("form[name=u2]")[0].action, $("[name=u2]").serialize(), FcltCallbackAndThen(login_callback), "json");
        }
    </script>

  </head>

  <body class="fclt-modal" id="loginbody_sr">
    <% MODAL_START(); %>
      <form name="u2" method="post" action="idp_self_register_save.asp?x=x<%=transitParam%>">
<%
        MODAL_BLOCK_START("selfInput", L("lcl_self_needed_info"), { icon: "fa-address-card" });
        %><tr><td colspan="2"><%=L("lcl_self_register_header")%></td></tr><%
        RWFIELDTR("prs_naam",   "fld required", L("lcl_prs_person_name"),     "", {required: true, maxlength: 60});
        RWFIELDTR("prs_vrnaam", "fld",          L("lcl_prs_person_voornaam"), "", {maxlength: 30});
        RWFIELDTR("prs_email",  "fld required", L("lcl_prs_person_email"),    email);
        RWFIELDTR("prs_telnr", "fld required",  L("lcl_prs_person_phone"),    "", { required: true, maxlength: 20 });
        //RWFIELDTR("password1", "fld required",  L("lcl_ch_password_new"),     "", { required: true, html: " type=password" });
        //RWFIELDTR("password2", "fld required",  L("lcl_ch_password_con"),     "", { required: true, html: " type=password" });

%>
        <tr class='trmailtoken' style='display:none'>
            <td class="label">
                <label for="mailtoken"><%=L("lcl_vis_log_psw")%></label>
            </td>
            <td>
                <input type="text" maxlength="6" id="mailtoken" name="mailtoken" class="fld" autocomplete="off">
            </td>
        </tr>
<%
        MODAL_BLOCK_END();
        SIMPLE_BLOCK_START();
        var buttons =  [ {title: L("lcl_submit"), icon: "fa-fclt-save", action: "self_submit()", importance: 1 },
                         {title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "window.location.href = '" + rooturl + "/appl/aut/login_email.asp';", importance: 3 }];
        CreateButtons(buttons, { isModal: true });
        SIMPLE_BLOCK_END();

        IFACE.FORM_END();
%>

      </form>
    <div class="info" id="sfooter"><%=L("lcl_self_register_footer")%></div>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
