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

{% block content %}
  {% include "security/_messages.html" %}
  <h1>{{ _fsdomain("Sign In") }}</h1>
  <form action="{{ url_for_security('us_signin') }}{{ prop_next() }}" method="post" name="us_signin_form">
    {{ us_signin_form.hidden_tag() }}
    {{ render_form_errors(us_signin_form) }}
    {{ render_field_with_errors(us_signin_form.identity) }}
    {{ render_field_with_errors(us_signin_form.passcode) }}
    {{ render_field_with_errors(us_signin_form.remember) }}
    {{ render_field(us_signin_form.submit) }}
    {% if code_methods %}
      <h4>{{ _fsdomain("Request one-time code be sent") }}</h4>
      {% for subfield in us_signin_form.chosen_method %}
        {% if subfield.data in code_methods %}{{ render_field_with_errors(subfield) }}{% endif %}
      {% endfor %}
      {{ render_field_errors(us_signin_form.chosen_method) }}
      {{ render_field(us_signin_form.submit_send_code, formaction=url_for_security('us_signin_send_code')) }}
    {% endif %}
  </form>
  {% if security.webauthn %}
    <hr class="fs-gap">
    <h2>{{ _fsdomain("Use WebAuthn to Sign In") }}</h2>
    <div class="fs-gap">
      <form method="get" id="wan-signin-form" name="wan_signin_form">
        <input id="wan_signin" name="wan_signin" type="submit" value="{{ _fsdomain('Sign in with WebAuthn') }}" formaction="{{ url_for_security('wan_signin') }}{{ prop_next() }}">
      </form>
    </div>
  {% endif %}
  {% if security.oauthglue %}
    <hr class="fs-gap">
    <h2>{{ _fsdomain("Use Social Oauth to Sign In") }}</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('Sign in with %(provider)s', provider=provider) }}" formaction="{{ url_for_security('oauthstart', 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 %}
