{% extends "SsoBackendBundle:Token:base.html.twig" %}
{% block title %}User Show{% endblock %}

{% block body %}
    <div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h2>Do you really want to delete this user?</h2>
                </div>
                <div class="modal-body">
                    <p>You are about to delete one token, this procedure is irreversible.</p>
                    <p>Do you want to proceed?</p>
                    <p>We hope that you know what you do!</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <a href="#" class="btn btn-danger danger">Delete</a>
                </div>
            </div>
        </div>
    </div>
    <h2>User View</h2>
    <ul class="list-group">
        <li class="list-group-item">
            <div class="labelview">Id</div>
            {{ entity.id }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">Guid</div>
            {{ entity.Guid }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">Email</div>
            {{ entity.Email }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">Username</div>
            {{ entity.Username }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">Firstname</div>
            {{ entity.Firstname }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">Lastname</div>
            {{ entity.Lastname }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">Lower Username</div>
            {{ entity.Lowerusername }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">Lower Email</div>
            {{ entity.Loweremail }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">Active</div>
            {{ entity.Active }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">Deleted</div>
            {{ entity.Deleted ? 1 : 0 }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">AuthId</div>
            {{ entity.AuthId }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">LdapSearchAttributes</div>
            {{ entity.LdapSearchAttributes }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">LdapSearchValue</div>
            {{ entity.LdapSearchValue }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">Password Encrypt Type</div>
            {{ entity.passwordEncryptType }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">Password Token</div>
            {{ entity.Passwordtoken }}&nbsp;
        </li>
        {% if entity.Passwordtokenexpire %}
            <li class="list-group-item">
                <div class="labelview">Password Token Expire</div>
                {{ entity.Passwordtokenexpire|date("Y-m-d H:i:s") }}&nbsp;
            </li>
        {% endif %}
        <li class="list-group-item">
            <div class="labelview">Activation Token</div>
            {{ entity.ActivateToken }}&nbsp;
        </li>
        {% if entity.ActivateTokenExpire %}
            <li class="list-group-item">
                <div class="labelview">Activation Token Expire</div>
                {{ entity.ActivateTokenExpire|date("Y-m-d H:i:s") }}&nbsp;
            </li>
        {% endif %}
        {% if entity.createdAt %}
            <li class="list-group-item">
                <div class="labelview">createdAt</div>
                {{ entity.createdAt|date('Y-m-d H:i:s') }}&nbsp;
            </li>
        {% endif %}
        {% if entity.updatedAt %}
            <li class="list-group-item">
                <div class="labelview">updatedAt</div>
                {{ entity.updatedAt|date('Y-m-d H:i:s') }}&nbsp;
            </li>
        {% endif %}
        {% if entity.deleted and entity.deletedAt %}
            <li class="list-group-item">
                <div class="labelview">deletedAt</div>
                {{ entity.updatedAt|date('Y-m-d H:i:s') }}&nbsp;
            </li>
        {% endif %}
        {% if entity.updatedReferencesAt %}
            <li class="list-group-item">
                <div class="labelview">updatedReferencesAt</div>
                {{ entity.updatedReferencesAt|date('Y-m-d H:i:s') }}&nbsp;
            </li>
        {% endif %}
        <li class="list-group-item">
            <div class="labelview">MfaEnabled</div>
            {{ entity.mfaEnabled ? 1 : 0 }}&nbsp;
        </li>
        {% if entity.mfaEnabled %}
            <li class="list-group-item">
                <div class="labelview">MfaCreatedAt</div>
                {{ entity.MfaCreatedAt|date('Y-m-d H:i:s') }}&nbsp;
            </li>
            <li class="list-group-item">
                <div class="labelview">MfaUpdatedAt</div>
                {{ entity.MfaUpdatedAt|date('Y-m-d H:i:s') }}&nbsp;
            </li>
        {% endif %}
        {#additional security informations#}
        <li class="list-group-item list-group-item-danger">
            <div class="labelview">LoginFails</div>
            {{ entity.LoginFails|default(0) }}&nbsp;
        </li>
        {% if entity.loginFailedFirstAt %}
            <li class="list-group-item list-group-item-danger">
                <div class="labelview">loginFailedFirstAt</div>
                {{ entity.loginFailedFirstAt|date('Y-m-d H:i:s') }}&nbsp;
            </li>
        {% endif %}
        {% if entity.loginFailedLastAt %}
            <li class="list-group-item list-group-item-danger">
                <div class="labelview">loginFailedLastAt</div>
                {{ entity.loginFailedLastAt|date('Y-m-d H:i:s') }}&nbsp;
            </li>
        {% endif %}
        {% if entity.passwordPolicy %}
            <li class="list-group-item list-group-item-info">
                <div class="labelview">passwordPolicy</div>

                <a target="_blank" href="{{ path('_admin_backend_passwordpolicy_show', {'policyId': entity.passwordPolicy}) }}">{{ entity.passwordPolicy }}&nbsp;</a>
            </li>
        {% endif %}
        {% if entity.lastPasswordChange %}
            <li class="list-group-item list-group-item-info">
                <div class="labelview">lastPasswordChange</div>
                {{ entity.lastPasswordChange|date('Y-m-d H:i:s') }}&nbsp;
            </li>
        {% endif %}
        {% if entity.passwordExpired %}
            <li class="list-group-item list-group-item-info">
                <div class="labelview">passwordExpired</div>
                {{ entity.passwordExpired}}&nbsp;
            </li>
        {% endif %}
        {% if entity.resetPasswordToken %}
            <li class="list-group-item list-group-item-info">
                <div class="labelview">resetPasswordToken</div>
                {{ entity.resetPasswordToken}}&nbsp;
            </li>
        {% endif %}
        {% if entity.resetPasswordTokenExpire %}
            <li class="list-group-item list-group-item-info">
                <div class="labelview">resetPasswordTokenExpire</div>
                {{ entity.resetPasswordTokenExpire|date('Y-m-d H:i:s')}}&nbsp;
            </li>
        {% endif %}
        <li class="list-group-item list-group-item-info">
            <div class="labelview">User Groups</div>
            {{ entity.userGroups|map(p => "#{p.name}")|join(', ') }}&nbsp;
        </li>
    </ul>
    {% if app.debug and entity.mfaEnabled %}
        <h3>MFA configuration only available in testing environments!</h3>
        <p>Twig-Extension for qr-code currently dead.</p>
        {#<img src="{{ qrcode_data_uri(qrMessage, { size: 200, padding: 10 }) }}" />#}
        <hr/>
    {% endif %}
    <ul class="record_actions clearfix">
        <li>
            <a class="btn btn-success" href="{{ path('_admin_backend_webservice_user') }}">
                Back to the list
            </a>
        </li>
        {% if not showApplications %}
            <li>
                <a class="btn btn-success show-applications" data-toggle="button" data-hide-text="Hide Applications"
                   href="{{ path('_admin_backend_webservice_user_application_application_show', { 'userId': entity.id }) }}">
                    Show Applications
                </a>
            </li>
        {% endif %}
        <li>
            <a class="btn btn-primary"
               href="{{ path('_admin_backend_webservice_user_edit', { 'userId': entity.id }) }}">
                Edit User
            </a>
        </li>
        <li>
            <a class="btn btn-danger" data-toggle="modal" data-target="#confirm-delete"
               data-href="{{ path('_admin_backend_webservice_user_delete', { 'userId': entity.id}) }}" href="#">Delete
                User</a>
            {#{ form(delete_form) }#}
        </li>
    </ul>

    <div style="clear:both" id="applicationContainer"
         data-url="{{ path('_admin_backend_webservice_user_application_application_show', { 'userId': entity.id }) }}">
        {% if showApplications %}
            {{ render(controller('SsoBackendBundle:WsUserApplication:applicationShow', { 'userId': entity.id })) }}
        {% endif %}
    </div>
    <style>
        .labelview {
            width: 220px;
        }
    </style>
    <script>
        $(function () {
            $(".show-applications").click(function () {
                var me = $(this),
                    container = $("#applicationContainer");
                if (me.hasClass("btn-pressed")) {
                    me.removeClass("btn-pressed").button("reset");
                    container.slideUp("slow", function () {
                        container.empty();
                    });
                } else {
                    me.addClass("btn-pressed").button("hide");
                    container.hide().load(me.attr("href"), function () {
                        container.slideDown();
                    });
                }
                return false;
            });
            $("body").prepend($('<div id="messageContainer" />'));
        });
        $('#confirm-delete').on('show.bs.modal', function (e) {
            $(this).find('.danger').attr('href', $(e.relatedTarget).data('href'));
            //$('.debug-url').html('Delete URL: <strong>' + $(this).find('.danger').attr('href') + '</strong>');
        });
    </script>
{% endblock %}
