{% set title = title|default(_fsdomain('Reauthenticate')) %}
{% extends "security/base.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field, render_field_errors, prop_next, render_csrf %}

{% block content %}
  {% include "security/_messages.html" %}
  <h1>{{ _fsdomain("Reauthenticate") }}</h1>
  <form action="{{ url_for_security('us_verify') }}{{ prop_next() }}" method="post" name="us_verify_form">
    {{ us_verify_form.hidden_tag() }}
    {{ render_field_with_errors(us_verify_form.passcode) }}
    {{ render_field(us_verify_form.submit) }}
    {% if code_methods %}
      <h4>{{ _fsdomain("Request one-time code be sent") }}</h4>
      {% for subfield in us_verify_form.chosen_method %}
        {% if subfield.data in code_methods %}{{ render_field_with_errors(subfield) }}{% endif %}
      {% endfor %}
      {{ render_field_errors(us_verify_form.chosen_method) }}
      {% if code_sent %}<p>{{ _fsdomain("Code has been sent") }}</p>{% endif %}
      <div class="fs-gap">
        {{ render_field(us_verify_form.submit_send_code, formaction=url_for_security("us_verify_send_code")~prop_next()) }}
      </div>
    {% endif %}
  </form>
  {% if has_webauthn_verify_credential %}
    <hr class="fs-gap">
    <h2>{{ _fsdomain("Use a Passkey to Reauthenticate") }}</h2>
    <form action="{{ url_for_security('wan_verify') }}{{ prop_next() }}" method="post" name="wan_verify_form">
      {# explicitly render csrf_token so we can change the ID so we don't get duplicates #}
      {{ render_csrf(wan_verify_form, "wan") }}
      {{ render_field(wan_verify_form.submit) }}
    </form>
  {% endif %}
  {% if security.oauthglue %}
    <hr class="fs-gap">
    <h2>{{ _fsdomain("Use Social Login to Reauthenticate") }}</h2>
    {% for provider in security.oauthglue.provider_names %}
      <div class="fs-gap">
        <form method="post" id="{{ provider }}_form" name="{{ provider }}_form">
          <input id="{{ provider }}" name="{{ provider }}" type="submit" value="{{ _fsdomain('Continue with %(provider)s', provider=provider) }}" formaction="{{ url_for_security('oauth_verify_start', name=provider) }}{{ prop_next() }}">
          {% if csrf_token is defined %}
            <input id="{{ provider }}_csrf_token" name="{{ provider }}_csrf_token" type="hidden" value="{{ csrf_token() }}">
          {% endif %}
        </form>
      </div>
    {% endfor %}
  {% endif %}
  {% include "security/_menu.html" %}
{% endblock content %}
