Password smtcpass


Ir al artículo

Controller Code - Github

    /**
     * @Route("/userpassword", name="examples_userpassword")
     * @Template()
     */
    public function userPasswordAction(Request $request)
    {
        $this->loginByUsername('smtc');

        $user = $this->get('security.context')->getToken()->getUser();
        $form = $this->createForm(new PasswordType(), $user);

        if ($request->isMethod('POST')) {
            $form->bind($request);

            if ($form->isValid()) {

                // do amazing things

                $flashBag = $this->get('session')->getFlashBag();
                $flashBag->add('smtc_success', 'El password es correcto');

                return $this->redirect($this->generateUrl('examples_userpassword'));
            }
        }

        return array(
            'form' => $form->createView()
        );
    }

Template Code - Github

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

{% import 'MainBundle:Macros:breadcrumb.html.twig' as breadcrumb %}

{% set section = 'examples' %}

{% block breadcrumb %}
{{ breadcrumb.show_example('UserPassword Constraint') }}
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col-md-12">
            <form action="{{ path('examples_userpassword') }}" method="POST" novalidate>
                {{ form_row(form.oldPassword) }}
                {{ form_rest(form) }}
                <p><span class="label label-primary">Password</span> <strong>smtcpass</strong></p>
                <button type="submit" class="btn btn-success">
                    Guardar
                </button>
            </form>
        </div>
    </div>
{% endblock %}


{% set article_link = 'http://showmethecode.es/php/symfony/userpassword-constraint/' %}

Fork me on GitHub