{% extends "karaage/common/profile_base.html" %}
{% load forms %}


{% block title %}SAML - My profile{% endblock %}
{% block profile_title %}SAML{% endblock %}


{% block profile_content %}
<div class="module">
    <h2>SAML Details</h2>

    {% if saml_session %}
        <p>You have an established SAML session.</p>
        <p>request.META values:</p>
        <div class="table-container">
            <table>
                {% for key,value in request.META.items %}
                <tr><td>{{ key }}</td><td>{{ value }}</td></tr>
                {% endfor %}
            </table>
        </div>
        <p>attrs values:</p>
        <div class="table-container">
            <table>
                {% for key,value in attrs.items %}
                <tr><td>{{ key }}</td><td>{{ value }}</td></tr>
                {% endfor %}
            </table>
        </div>
        <div id="saml_login_fields">
            <form method="post" action=".">{% csrf_token %}
                <input type="submit" name="logout" value="SAML Logout" />
            </form>
        </div>
    {% else %}
        <p>You do not have an established SAML session.</p>
    {% endif %}

    {% if person %}
        <p>You are logged in to Karaage as {{ person }}.</p>
    {% else %}
        <p>You are not logged in to Karaage.</p>
    {% endif %}

    {% if not saml_session and person and person.institute.saml_entityid %}
        <form method="post" action=".">{% csrf_token %}
            <input type="submit" name="login" value="SAML Login" class="button" />
        </form>
    {% endif %}

    {% if saml_session and person %}
    {% if not person.saml_id or person.saml_id != attrs.persistent_id %}
        <p>If you continue and click Register, then your details, including
        your email address, will be replaced by those above and you will be
        able to log in using SAML.</p>
        <form method="post" action=".">{% csrf_token %}
            <input type="submit" name="register" value="Register" class="button" />
        </form>
    {% endif %}
    {% endif %}
</div>
{% endblock %}
