<script type="application/javascript">
    function send_totp() {
        $.ajax({"url":"{% url 'totp_recheck' %}", method:"POST",dataType:"JSON",
            data:{"csrfmiddlewaretoken":"{{ csrf_token }}","otp":$("#otp").val()},
         success:function (data) {
                            if (data["recheck"])
                                mfa_success_function();
                            else {
                                mfa_failed_function();
                            }
                        }
        })

    }
</script>
<div class="row">

<div class="col-sm-10 col-sm-offset-1 col-xs-12 col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
<div class="panel panel-default">
      <div class="panel-heading">
	      <strong> Email One Time Password </strong>
      </div>
      <div class="panel-body">

      <FORM METHOD="POST" ACTION="{% url 'email_auth' %}" Id="formLogin" onSubmit="" name="FrontPage_Form1">


      {% csrf_token %}
          {%  if invalid %}
          <div class="alert alert-danger">
              Sorry, The provided token is not valid.
          </div>
          {% endif %}
      {% if quota %}
          <div class="alert alert-warning">
              {{ quota }}
          </div>
      {% endif %}
      <fieldset>
      <div class="row">
      <div class="col-sm-12 col-md-12">
        <p>Enter the 6-digits sent to your email.</p>
      </div>
      </div>

      <div class="row">
	  <div class="col-sm-12 col-md-12">
	    <div class="form-group">
	      <div class="input-group">
		<span class="input-group-addon">
		<i class="glyphicon glyphicon-lock"></i>
		</span>
		<input class="form-control" size="6" MaxLength="6" value="" placeholder="e.g 55552" name="otp" type="text" id="otp" autofocus>

	      </div>
	    </div>

          <div class="form-group">

	      <input type="{% if mode == "auth" %}submit{% elif mode == 'recheck'  %}button{% endif %}" {% if mode == "recheck" %}onclick="send_totp()" {% endif %} class="btn btn-lg btn-success btn-block" value="Sign in">
	      </div>
      </div>
      </fieldset>
      </FORM>
      </div>
        <div class="row">
        <div class="col-md-6" style="padding-left: 25px">
            {% if request.session.mfa_methods|length > 1 %}
                <a href="{%  url 'mfa_methods_list' %}">Select Another Method</a>
            {% endif %}
        </div>
        </div>
	      </div>
              </div>
	      </div>
	      </div>
