Skip to content

improve the serialization of custom user models #3307

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 1 commit into from
Dec 19, 2013
Merged
Changes from all 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
25 changes: 19 additions & 6 deletions cookbook/security/entity_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ focus on the most important methods that come from the
{
return serialize(array(
$this->id,
$this->username,
$this->salt,
$this->password,
));
}

Expand All @@ -159,10 +162,20 @@ focus on the most important methods that come from the
{
list (
$this->id,
$this->username,
$this->salt,
$this->password,
) = unserialize($serialized);
}
}

.. note::

When implementing the
:class:`Symfony\\Component\\Security\\Core\\User\\EquatableInterface`,
you determine yourself which properties need to be compared to distinguish
your user objects.

.. tip::

:ref:`Generate the database table <book-doctrine-creating-the-database-tables-schema>`
Expand Down Expand Up @@ -219,7 +232,7 @@ layer is a piece of cake. Everything resides in the configuration of the
:doc:`SecurityBundle </reference/configuration/security>` stored in the
``app/config/security.yml`` file.

Below is an example of configuration where the user will enter their
Below is an example of configuration where the user will enter their
username and password via HTTP basic authentication. That information will
then be checked against your User entity records in the database:

Expand Down Expand Up @@ -358,7 +371,7 @@ For this example, the first three methods will return ``true`` whereas the
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;

class User implements AdvancedUserInterface, \Serializable
class User implements AdvancedUserInterface, \Serializable
{
// ...

Expand Down Expand Up @@ -386,7 +399,7 @@ For this example, the first three methods will return ``true`` whereas the
Now, if you try to authenticate as a user who's ``is_active`` database field
is set to 0, you won't be allowed.

The next session will focus on how to write a custom entity provider
The next session will focus on how to write a custom entity provider
to authenticate a user with their username or email address.

Authenticating Someone with a Custom Entity Provider
Expand Down Expand Up @@ -552,7 +565,7 @@ methods have changed::
class User implements AdvancedUserInterface, \Serializable
{
// ...

/**
* @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
*
Expand All @@ -568,7 +581,7 @@ methods have changed::
{
return $this->roles->toArray();
}

// ...

}
Expand Down Expand Up @@ -625,7 +638,7 @@ of the application::
{
return $this->role;
}

// ... getters and setters for each property
}

Expand Down