{% extends "base.html" %}
{% block title %}{{ title }}{% endblock %}
{% block content %}

<div class="user_profile" style="min-height:10em;">
    <div class="right">
{% if g.ldap['username'] == user['sAMAccountName'] or admin %}
        <p style="text-align: right;"><a href="{{ url_for('user_changepw', username=user['sAMAccountName']) }}" class="button">Change password</a></p>
{% endif %}
{% if admin %}
        <p style="text-align: right;"><a href="{{ url_for('user_edit_profile', username=user['sAMAccountName']) }}" class="button">Edit user</a></p>
        <p style="text-align: right;"><a href="{{ url_for('user_delete', username=user['sAMAccountName']) }}" class="button">Delete user</a></p>
{% endif %}
    </div>
    <h2>Profile</h2>

    <table style='width:auto;'>
{% for key, title in identity_fields %}
{% if key in user %}
        <tr>
            <th style='padding-right:10px;'>{{ title }}</td>
{% if key == "___primary_group" %}
            <td><a href="{{ url_for('group_overview', groupname=user[key]) }}">{{ user[key] }}</a></td>
{% else %}
            <td>{{ user[key] }}</td>
{% endif %}
        </tr>
{% endif %}
{% endfor %}
{% if 'userAccountControl' in user %}
        <tr>
            <th style='padding-right:10px;'>Account flags</th>
            <td>
                <ul>
{% for key, value in uac_values.items() %}
{% if user['userAccountControl'].__and__(key) %}
                    <li>{{ value[0] }}</li>
{% endif %}
{% endfor %}
                </ul>
            </td>
        </tr>
{% endif %}
    </table>
</div>

{% if 'sshPublicKey' in user or admin %}
<div class="user_access">
{% if admin %}
    <div class="right">
        {% if 'sshPublicKey' in user %}
        <p style="text-align: right;"><a href="{{ url_for('user_edit_ssh', username=user['sAMAccountName']) }}" class="button">Edit SSH keys</a></p>
        {% else %}
        <p style="text-align: right;"><a href="{{ url_for('user_edit_ssh', username=user['sAMAccountName']) }}" class="button">Add SSH keys</a></p>
        {% endif %}
    </div>
{% endif %}
    <h2>Machine access</h2>

    <table style='width:auto;'>
{% for key in user['sshPublicKey']: %}
        <tr>
            <th style='padding-right:10px;'>SSH key:</td>
            <td>{{ key.split(' ')[-1] }} ({{ key.split(' ')[0] }})</div></td>
        </tr>
{% endfor %}
    </table>
</div>
{% endif %}


{% if groups %}
<h2>Group membership</h2>
<table>
    <tr>
{% for key, title in group_fields %}
        <th>{{ title }}</th>
{% endfor %}
    </tr>

{% for entry in groups %}
    <tr>
{% for key, title in group_fields %}
{% if key == "sAMAccountName" and key in entry %}
        <td style='padding-right:10px;white-space:nowrap;'><a href="{{ url_for('group_overview', groupname=entry['sAMAccountName']) }}">{{ entry[key] }}</a></td>
{% elif key in entry %}
        <td>{{ entry[key] }}</td>
{% else %}
        <td>&nbsp;</td>
{% endif %}
{% endfor %}
    </tr>
{% endfor %}
</table>
{% endif %}

{% endblock %}
