{% extends "website/w_base.html" %}

{% block content %}
{% if with_shop_header %}
    {% include "shop/connect_header.html" %}
{% elif COMPANY_LOGO %}
    <div style="width:100%; text-align: center">
      <img src="{{COMPANY_LOGO}}" alt="{{COMPANY_NAME}}" width=250 />
    </div>
{% endif %}
<div id="connect_form_template" style="text-align:center;">
        <form method="POST">
            <p><input type="text" name="login" placeholder="Email" /></p>
            <p>
                <input type="password" name="password" placeholder="{{password_placeholder}}" />
                {% if password_notice %}
                    <br/>
                    <span style="font-size: small;font-style: italic;">{{password_notice}}</span>
                {% endif %}
                {% if reset_password_available %}
                    <br/>
                    {% include "website/change_password_availibility.html" %}
                {% endif %}
                
            </p>
            {% csrf_token %}
            <input type="hidden" name="fp" value="" />
            <p><button type="submit">Connexion</button></p>
        </form>
        <p style="color:red;">{{msg}}</p>
        {% if permanent_message %}
        <div id="permanent_message">
            {{permanent_message}}
        </div>
        {% endif %}
        <!--<p><a href="oubli_pass">Mot de passe oublié</a></p>-->
        <script>
            try {
                window.addEventListener("DOMContentLoaded", (event) => {
                    var fp = document.getElementsByName('fp')
                    if (fp.length == 1)
                        fp[0].value = new Fingerprint({canvas: true}).get()
                })
            } catch (e) {
                var msg = 'Ce navigateur ne permet pas de vous identifier. Merci de signaler l\'erreur suivante:\n'
                msg += JSON.stringify(e)
                alert(msg)
            }
        </script>
</div>

<script>
    // For the members space, reset url to home when accessing connect page
    const is_member_space = '{{is_member_space}}',
        external_msg = '{{external_msg}}';


    if (is_member_space === "True") {
        var app_env = '{{app_env}}';
        var base_location = (app_env === 'dev') ? '/members_space/' : '/';
        if (window.location.pathname === base_location) {
            history.pushState({}, '', 'home');
        } else {
            history.replaceState({}, '', 'home');
        }
    }
    if (external_msg == "successful_reset_password") {
        alert("Changement de mot de passe réussi.")
    }
</script>
{% endblock %}
