Skip to content

[Reference] [UserPassword] Use the non-deprecated class for Symfony 2.2 #2297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 12, 2013
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions reference/constraints/UserPassword.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ UserPassword
.. versionadded:: 2.1
This constraint is new in version 2.1.

.. note::

The `UserPassword` constraint class is defined in the
`Symfony\Component\Security\Core\Validator\Constraints` namespace since
Symfony 2.2. The `UserPassword` defined in the
`Symfony\Component\Security\Core\Validator\Constraint` namespace is
deprecated and will be removed in Symfony 2.3.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to use something like:

Since Symfony 2.2, the `UserPassword*` classes in the 
``Symfony\Component\Security\Core\Validator\Constraint``
namespace is depecreated and will be removed in Symfony 2.3. 
Please use the `UserPassword*` classes in the 
``Symfony\Component\Security\Core\Validator\Constraints``
namespace instead.


This validates that an input value is equal to the current authenticated
user's password. This is useful in a form where a user can change his password,
but needs to enter his old password for security.
Expand All @@ -13,15 +21,15 @@ but needs to enter his old password for security.
This should **not** be used to validate a login form, since this is done
automatically by the security system.

+----------------+-------------------------------------------------------------------------------------------+
| Applies to | :ref:`property or method<validation-property-target>` |
+----------------+-------------------------------------------------------------------------------------------+
| Options | - `message`_ |
+----------------+-------------------------------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Security\\Core\\Validator\\Constraint\\UserPassword` |
+----------------+-------------------------------------------------------------------------------------------+
| Validator | :class:`Symfony\\Component\\Security\\Core\\Validator\\Constraint\\UserPasswordValidator` |
+----------------+-------------------------------------------------------------------------------------------+
+----------------+--------------------------------------------------------------------------------------------+
| Applies to | :ref:`property or method<validation-property-target>` |
+----------------+--------------------------------------------------------------------------------------------+
| Options | - `message`_ |
+----------------+--------------------------------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Security\\Core\\Validator\\Constraints\\UserPassword` |
+----------------+--------------------------------------------------------------------------------------------+
| Validator | :class:`Symfony\\Component\\Security\\Core\\Validator\\Constraints\\UserPasswordValidator` |
+----------------+--------------------------------------------------------------------------------------------+

Basic Usage
-----------
Expand All @@ -39,16 +47,16 @@ password:
Acme\UserBundle\Form\Model\ChangePassword:
properties:
oldPassword:
- Symfony\Component\Security\Core\Validator\Constraint\UserPassword:
- Symfony\Component\Security\Core\Validator\Constraints\UserPassword:
message: "Wrong value for your current password"

.. code-block:: php-annotations

// src/Acme/UserBundle/Form/Model/ChangePassword.php
namespace Acme\UserBundle\Form\Model;
use Symfony\Component\Security\Core\Validator\Constraint as SecurityAssert;

use Symfony\Component\Security\Core\Validator\Constraints as SecurityAssert;

class ChangePassword
{
/**
Expand All @@ -63,7 +71,7 @@ password:

<!-- src/UserBundle/Resources/config/validation.xml -->
<class name="Acme\UserBundle\Form\Model\ChangePassword">
<property name="Symfony\Component\Security\Core\Validator\Constraint\UserPassword">
<property name="Symfony\Component\Security\Core\Validator\Constraints\UserPassword">
<option name="message">Wrong value for your current password</option>
</property>
</class>
Expand All @@ -72,10 +80,10 @@ password:

// src/Acme/UserBundle/Form/Model/ChangePassword.php
namespace Acme\UserBundle\Form\Model;

use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Security\Core\Validator\Constraint as SecurityAssert;
use Symfony\Component\Security\Core\Validator\Constraints as SecurityAssert;

class ChangePassword
{
public static function loadValidatorData(ClassMetadata $metadata)
Expand Down