{% extends "mails/base.html" %}

{% block subject %}{{ service_name }} Account Recovery{% endblock %}

{% block content %}
<p>Hello{% if users | length == 1 %} {{ users[0].name }}{% endif %},</p>
<p>we have received an account recovery request for {{email}}. If you did not initiate this account recovery request, you can simply ignore this email.</p>
{% if users | length == 1 %}
  {% with user = users[0] %}
  {% if user.authentication_methods | length == 0 %}
    <p>There is no way to sign in to your {{ service_name }} account <b>{{ user.name }}</b> at this time. Please <a href="mailto:{{ contact_email }}?subject=Account Recovery for {{ email }}">contact an administrator</a> to regain access to your account.</p>
  {% elif user.authentication_methods | length == 1 %}
    {% with authentication_method = user.authentication_methods[0] %}
    {% if authentication_method.type.name.lower() == 'ldap' %}
      <p>You can use the {{ ldap_name }} account <b>{{authentication_method.login['login']}}</b> to sign in to your {{ service_name }} account <b>{{ user.name }}</b>. To set a new password for your {{ ldap_name }} account, please <a href="mailto:{{ contact_email }}?subject=Account Recovery for {{ email }}">contact an administrator</a>.</p>
    {% elif authentication_method.type.name.lower() == 'email' %}
      <p>You can use the email address <b>{{authentication_method.login['login']}}</b> to sign in to your {{ service_name }} account <b>{{ user.name }}</b>. To set a new password, please <a href="{{ password_reset_urls[authentication_method] }}">click here</a>.</p>
    {% else %}
      <p>You can use the username <b>{{authentication_method.login['login']}}</b> to sign in to your {{ service_name }} account <b>{{ user.name }}</b>. To set a new password, please <a href="{{ password_reset_urls[authentication_method] }}">click here</a>.</p>
    {% endif %}
    {% endwith %}
  {% else %}
    <p>Your {{ service_name }} account <b>{{ user.name }}</b> has the following authentication methods:</p>
    <ul>
    {% for authentication_method in user.authentication_methods %}
      <li>
      {% if authentication_method.type.name.lower() == 'ldap' %}
        You can use the {{ ldap_name }} account <b>{{authentication_method.login['login']}}</b> to sign in to your {{ service_name }} account. To set a new password for your {{ ldap_name }} account, please <a href="mailto:{{ contact_email }}?subject=Account Recovery for {{ email }}">contact an administrator</a>.
      {% elif authentication_method.type.name.lower() == 'email' %}
        You can use the email address <b>{{authentication_method.login['login']}}</b> to sign in to your {{ service_name }} account. To set a new password, please <a href="{{ password_reset_urls[authentication_method] }}">click here</a>.
      {% else %}
        You can use the username <b>{{authentication_method.login['login']}}</b> to sign in to your {{ service_name }} account. To set a new password, please <a href="{{ password_reset_urls[authentication_method] }}">click here</a>.
      {% endif %}
      </li>
    {% endfor %}
    </ul>
  {% endif %}
  {% endwith %}
{% else %}
  <p>You have the following {{ service_name }} accounts:</p>
  {% for user in users %}
    <li><b>{{ user.name }}</b>:
      <ul>
      {% for authentication_method in user.authentication_methods %}
        <li>
        {% if authentication_method.type.name.lower() == 'ldap' %}
          You can use the {{ ldap_name }} account <b>{{authentication_method.login['login']}}</b> to sign in to this {{ service_name }} account. To set a new password for your {{ ldap_name }} account, please <a href="mailto:{{ contact_email }}?subject=Account Recovery for {{ email }}">contact an administrator</a>.
        {% elif authentication_method.type.name.lower() == 'email' %}
          You can use the email address <b>{{authentication_method.login['login']}}</b> to sign in to this {{ service_name }} account. To set a new password, please <a href="{{ password_reset_urls[authentication_method] }}">click here</a>.
        {% else %}
          You can use the username <b>{{authentication_method.login['login']}}</b> to sign in to this {{ service_name }} account. To set a new password, please <a href="{{ password_reset_urls[authentication_method] }}">click here</a>.
        {% endif %}
        </li>
      {% endfor %}
      </ul>
    </li>
  {% endfor %}
{% endif %}
{% endblock %}
