viernes, 25 de octubre de 2013

FOSUserBundle - Parte V - Overriding Profile y Change Password

Ahora vamos a sustituir las plantillas del perfil y de cambiar la contraseña:

mkdir src/Peteramas/MyFOSUserBundle/Resources/views/Profile/

cp vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/views/Profile/show_content.html.twig src/Peteramas/MyFOSUserBundle/Resources/views/Profile/


y luego cambiamos su contenido de:

{% trans_default_domain 'FOSUserBundle' %}

<div class="fos_user_user_show">
    <p>{{ 'profile.show.username'|trans }}: {{ user.username }}</p>
    <p>{{ 'profile.show.email'|trans }}: {{ user.email }}</p>
</div>

a:

{% extends 'PetramasMainBundle::layout.html.twig' %}

{% block content -%}
{% trans_default_domain 'FOSUserBundle' %}
<form class="form-horizontal" role="form">
    <div class="form-group">
        <label class="col-sm-2 control-label">{{ 'profile.show.username'|trans }}</label>
        <div class="col-sm-10">
            <p class="form-control-static">{{ user.username }}</p>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">{{ 'profile.show.email'|trans }}</label>
        <div class="col-sm-10">
            <p class="form-control-static">{{ user.email }}</p>
        </div>
    </div>
</form>
<a class="btn btn-primary" href="{{ path('fos_user_profile_edit') }}">Editar</a>
<a class="btn btn-primary" href="{{ path('fos_user_change_password') }}">Cambiar contraseña</a>
{% endblock %}

hacemos lo mismo con edit_content.html.twig

cp vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/views/Profile/edit_content.html.twig src/Peteramas/MyFOSUserBundle/Resources/views/Profile/

y cambiamos su contenido de esto:

{% trans_default_domain 'FOSUserBundle' %}

<form action="{{ path('fos_user_profile_edit') }}" {{ form_enctype(form) }} method="POST" class="fos_user_profile_edit">
    {{ form_widget(form) }}
    <div>
        <input type="submit" value="{{ 'profile.edit.submit'|trans }}" />
    </div>
</form>

a esto:

{% extends 'PetramasMainBundle::layout.html.twig' %}

{% block content -%}
{{ form_start(form, {'attr': {'class': 'form-horizontal fos_user_profile_edit', 'role': 'form'}}) }}
    {{ form_errors(form) }}
    <div class="form-group{% if form.username.vars.errors[0].message is defined %} has-error{% endif %}">
        {{ form_label(form.username, null, {'label_attr': {'class': 'col-sm-2 control-label'}}) }}
        <div class="col-sm-10">
            {{ form_widget(form.username, {'attr': {'class': 'form-control'}}) }}
            {% if form.username.vars.errors[0].message is defined %}
            <span class="help-block">
                {{ form.username.vars.errors[0].message }}
            </span>
            {% endif %}
        </div>
    </div>
    <div class="form-group{% if form.email.vars.errors[0].message is defined %} has-error{% endif %}">
        {{ form_label(form.email, null, {'label_attr': {'class': 'col-sm-2 control-label'}}) }}
        <div class="col-sm-10">
            {{ form_widget(form.email, {'attr': {'class': 'form-control'}}) }}
            {% if form.email.vars.errors[0].message is defined %}
            <span class="help-block">
                {{ form.email.vars.errors[0].message }}
            </span>
            {% endif %}
        </div>
    </div>
    <div class="form-group{% if form.current_password.vars.errors[0].message is defined %} has-error{% endif %}">
        {{ form_label(form.current_password, null, {'label_attr': {'class': 'col-sm-2 control-label'}}) }}
        <div class="col-sm-10">
            {{ form_widget(form.current_password, {'attr': {'class': 'form-control'}}) }}
            {% if form.current_password.vars.errors[0].message is defined %}
            <span class="help-block">
                {{ form.current_password.vars.errors[0].message }}
            </span>
            {% endif %}
        </div>
    </div>
    <button class="btn btn-primary" type="submit">{{ 'profile.edit.submit'|trans({}, 'FOSUserBundle') }}</button>
{{ form_end(form) }}
{% endblock %}

Ahora cambiar de contraseña:

mkdir src/Peteramas/MainBundle/Resources/views/ChangePassword/

cp vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/views/ChangePassword/changePassword_content.html.twig src/Peteramas/MyFOSUserBundle/Resources/views/ChangePassword/

acambiar su contenido de esto:

{% trans_default_domain 'FOSUserBundle' %}

<form action="{{ path('fos_user_change_password') }}" {{ form_enctype(form) }} method="POST" class="fos_user_change_password">
    {{ form_widget(form) }}
    <div>
        <input type="submit" value="{{ 'change_password.submit'|trans }}" />
    </div>
</form>

a esto:

{% extends 'PetramasMainBundle::layout.html.twig' %}

{% block content -%}
{{ form_start(form, {'attr': {'class': 'form-horizontal fos_user_change_password', 'role': 'form'}}) }}
    {{ form_errors(form) }}
    <div class="form-group{% if form.current_password.vars.errors[0].message is defined %} has-error{% endif %}">
        {{ form_label(form.current_password, null, {'label_attr': {'class': 'col-sm-2 control-label'}}) }}
        <div class="col-sm-10">
            {{ form_widget(form.current_password, {'attr': {'class': 'form-control'}}) }}
            {% if form.current_password.vars.errors[0].message is defined %}
            <span class="help-block">
                {{ form.current_password.vars.errors[0].message }}
            </span>
            {% endif %}
        </div>
    </div>
    <div class="form-group{% if form.plainPassword.first.vars.errors[0].message is defined %} has-error{% endif %}">
        {{ form_label(form.plainPassword.first, null, {'label_attr': {'class': 'col-sm-2 control-label'}}) }}
        <div class="col-sm-10">
            {{ form_widget(form.plainPassword.first, {'attr': {'class': 'form-control'}}) }}
            {% if form.plainPassword.first.vars.errors[0].message is defined %}
            <span class="help-block">
                {{ form.plainPassword.first.vars.errors[0].message }}
            </span>
            {% endif %}
        </div>
    </div>
    <div class="form-group{% if form.plainPassword.second.vars.errors[0].message is defined %} has-error{% endif %}">
        {{ form_label(form.plainPassword.second, null, {'label_attr': {'class': 'col-sm-2 control-label'}}) }}
        <div class="col-sm-10">
            {{ form_widget(form.plainPassword.second, {'attr': {'class': 'form-control'}}) }}
            {% if form.plainPassword.second.vars.errors[0].message is defined %}
            <span class="help-block">
                {{ form.plainPassword.second.vars.errors[0].message }}
            </span>
            {% endif %}
        </div>
    </div>
    <button class="btn btn-primary" type="submit">{{ 'change_password.submit'|trans({}, 'FOSUserBundle') }}</button>
{{ form_end(form) }}
{% endblock %}

No hay comentarios.:

Publicar un comentario

Puedes comentar como te gustaría que comenten de ti.