@@ -40,6 +40,15 @@ To make it shorter, the getter and setter methods for each have been removed to
40
40
focus on the most important methods that come from the
41
41
:class: `Symfony\\ Component\\ Security\\ Core\\ User\\ UserInterface `.
42
42
43
+ .. tip ::
44
+
45
+ You can :ref: `generate the missing getter and setters<book-doctrine-generating-getters-and-setters> `
46
+ by running:
47
+
48
+ .. code-block :: bash
49
+
50
+ $ php app/console doctrine:generate:entities Acme/UserBundle/Entity/User
51
+
43
52
.. code-block :: php
44
53
45
54
// src/Acme/UserBundle/Entity/User.php
@@ -154,6 +163,15 @@ focus on the most important methods that come from the
154
163
}
155
164
}
156
165
166
+ .. tip ::
167
+
168
+ :ref: `Generate the database table<book-doctrine-creating-the-database-tables-schema> `
169
+ for your ``User `` entity by running:
170
+
171
+ .. code-block :: bash
172
+
173
+ $ php app/console doctrine:schema:update --force
174
+
157
175
In order to use an instance of the ``AcmeUserBundle:User `` class in the Symfony
158
176
security layer, the entity class must implement the
159
177
:class: `Symfony\\ Component\\ Security\\ Core\\ User\\ UserInterface `. This
@@ -197,15 +215,9 @@ For more details on each of these, see :class:`Symfony\\Component\\Security\\Cor
197
215
because the :method: `Symfony\\ Bridge\\ Doctrine\\ Security\\ User\\ EntityUserProvider::refreshUser `
198
216
method reloads the user on each request by using the ``id ``.
199
217
200
- .. tip ::
201
-
202
- To generate missing setters and getters for your ``User `` entity, you
203
- can use ``php app/console doctrine:generate:entities Acme/UserBundle/Entity/User ``.
204
- For more details, see Doctrine's :ref: `book-doctrine-generating-getters-and-setters `.
205
-
206
- Below is an export of my ``User `` table from MySQL with user `admin `
207
- and password `admin `. For details on how to create user records and
208
- encode their password, see :ref: `book-security-encoding-user-password `.
218
+ Below is an export of the ``User `` table from MySQL with user ``admin `` and
219
+ password ``admin `` (which has been encoded). For details on how to create
220
+ user records and encode their password, see :ref: `book-security-encoding-user-password `.
209
221
210
222
.. code-block :: bash
211
223
@@ -216,12 +228,6 @@ encode their password, see :ref:`book-security-encoding-user-password`.
216
228
| 1 | admin | | d033e22ae348aeb5660fc2140aec35850c4da997 | admin@example.com | 1 |
217
229
+----+----------+------+------------------------------------------+--------------------+-----------+
218
230
219
- .. tip::
220
-
221
- To generate database table from your ` ` User` ` entity, you can run
222
- ` ` php app/console doctrine:schema:update --force` ` .
223
- For mor details, see Doctrine' s :ref:`book-doctrine-creating-the-database-tables-schema`.
224
-
225
231
The next part will focus on how to authenticate one of these users
226
232
thanks to the Doctrine entity user provider and a couple of lines of
227
233
configuration.
@@ -337,13 +343,15 @@ entity user provider to load User entity objects from the database by using
337
343
the ``username`` unique field. In other words, this tells Symfony how to
338
344
fetch the user from the database before checking the password validity.
339
345
340
- This code is not enough to secure the application for ** active ** users.
341
- The next section explains how to forbid non active users.
346
+ Forbid Inactive Users
347
+ ---------------------
342
348
343
- Forbid non Active Users
344
- -----------------------
349
+ If a User' s ` ` isActive` ` property is set to ` ` false` ` (i.e. ` ` is_active` `
350
+ is 0 in the database), the user will still be able to login access the site
351
+ normally. To prevent " inactive" users from logging in, you' ll need to do a
352
+ little more work.
345
353
346
- The easiest way to exclude non active users is to implement the
354
+ The easiest way to exclude inactive users is to implement the
347
355
:class:`Symfony\\Component\\Security\\Core\\User\\AdvancedUserInterface`
348
356
interface that takes care of checking the user' s account status.
349
357
The :class:` Symfony\\ Component\\ Security\\ Core\\ User\\ AdvancedUserInterface`
@@ -396,6 +404,9 @@ For this example, the first three methods will return ``true`` whereas the
396
404
}
397
405
}
398
406
407
+ Now, if you try to authenticate as a user who' s ``is_active`` database field
408
+ is set to 0, you won' t be allowed.
409
+
399
410
The next session will focus on how to write a custom entity provider
400
411
to authenticate a user with his username or his email address.
401
412
0 commit comments