<div class="modal fade" id="askmodal" tabindex="-1" role="dialog" aria-labelledby="askmodalLabel" data-backdrop="static">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
            <h5 class="modal-title">
                <% if(user.is2faEnabled){ %>
                    Disable 2-Factor Authentication
                    <% }else{ %>
                    Enable 2-Factor Authentication
                    <% } %>
            </h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
        </div>

        <div class="modal-body text-center">
        <a href="#" onclick="enableDisable2fa()" class="btn btn-sm btn-info" data-dismiss="modal" >Yes</a>
        <a class="btn btn-sm btn-info " data-dismiss="modal">No</a> 
        </div>

      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->   

  <!-- ____data for ajax ____ -->
<p class="d-none" id="2faData"
data-userid="<%= user.user_id %>"
data-_2faroute="<% if(user.is2faEnabled){ %>deactivate2FA<% }else{ %>activate2FA<% } %>">
</p>

<div id="alertFor2fa"></div>

<script type="text/javascript">

    function enableDisable2fa() {
      let alertbox = document.getElementById("alertFor2fa");  
      let id = document.getElementById("2faData").dataset.userid;
      let _2faroute = document.getElementById("2faData").dataset._2faroute;
      let url =`http://127.0.0.1:3000/dashboard/${_2faroute}/${id}`;
      $.ajax({
          url: url,
          type: 'GET',
          crossDomain: true,
          dataType: 'json',
          headers: { 'Access-Control_Allow_Origin': '*' },
          success: function (res, data) {
              console.log("success done|2fa request is:", res);

              let alertmsg = `<a class="close" data-dismiss="alert" aria-label="close">&times</a><strong>Success: </strong>You have succesfully ${res} your 2-Factor Authentication` 
              alertbox.classList.add("_2faAlert", "alert", "alert-success");
              alertbox.innerHTML = alertmsg;

              function redirect() {
                window.location.href = window.location.href;
              }

              setTimeout(redirect, 2000)
          },
          error: function (xhr) {
              console.log(xhr);
          }
        })
    }
</script>

 