Debian Codegraph @

docs/account/configuration.rst

raw
1 Configuration
2 =============
3
4 Overall
5 *******
6
7 ``ACCOUNT_ADAPTER`` (default: ``"allauth.account.adapter.DefaultAccountAdapter"``)
8 Specifies the adapter class to use, allowing you to alter certain
9 default behaviour.
10
11 ``ACCOUNT_FORMS``
12 Used to override the builtin forms. Defaults to::
13
14 ACCOUNT_FORMS = {
15 'add_email': 'allauth.account.forms.AddEmailForm',
16 'change_password': 'allauth.account.forms.ChangePasswordForm',
17 'confirm_login_code': 'allauth.account.forms.ConfirmLoginCodeForm',
18 'login': 'allauth.account.forms.LoginForm',
19 'request_login_code': 'allauth.account.forms.RequestLoginCodeForm',
20 'reset_password': 'allauth.account.forms.ResetPasswordForm',
21 'reset_password_from_key': 'allauth.account.forms.ResetPasswordKeyForm',
22 'set_password': 'allauth.account.forms.SetPasswordForm',
23 'signup': 'allauth.account.forms.SignupForm',
24 'user_token': 'allauth.account.forms.UserTokenForm',
25 }
26
27 ``ACCOUNT_PREVENT_ENUMERATION`` (default: ``True``)
28 Controls whether or not information is revealed about whether or not a user
29 account exists. For example, by entering random email addresses in the
30 password reset form you can test whether or not those email addresses are
31 associated with an account. Enabling this setting prevents that, and an email
32 is always sent, regardless of whether or not the account exists. Note that
33 there is a slight usability tax to pay because there is no immediate feedback.
34
35 Whether or not enumeration can be prevented during signup depends on the email
36 verification method. In case of mandatory verification, enumeration can be
37 properly prevented because the case where an email address is already taken is
38 indistinguishable from the case where it is not. However, in case of optional
39 or disabled email verification, enumeration can only be prevented by allowing
40 the signup to go through, resulting in multiple accounts sharing same email
41 address (although only one of the accounts can ever have it verified). When
42 enumeration prevention is set to ``True``, email address uniqueness takes
43 precedence over enumeration prevention, and the issue of multiple accounts
44 having the same email address will be avoided, thus leaking information. Set
45 it to ``"strict"`` to allow for signups to go through.
46
47 ``ACCOUNT_RATE_LIMITS`` (default: ``{...}``)
48 In order to be secure out of the box various rate limits are in place.
49 See :doc:`Rate Limits <./rate_limits>` for details.
50
51 ``ACCOUNT_SESSION_REMEMBER`` (default: ``None``)
52 Controls the life time of the session. Set to ``None`` to ask the user
53 ("Remember me?"), ``False`` to not remember, and ``True`` to always
54 remember.
55
56 ``ACCOUNT_TEMPLATE_EXTENSION`` (default: ``"html"``)
57 A string defining the template extension to use, defaults to ``html``.
58
59
60 Signup
61 ******
62
63 ``ACCOUNT_SIGNUP_FIELDS`` (default: ``['username*', 'email', 'password1*', 'password2*']``)
64 The list of fields to complete in the signup form: ``username``, ``email``,
65 ``phone``, ``password1``, ``password2``.. Fields marked with an asterisk
66 (e.g. ``'username*'``) are required. To let the user type in their email
67 address twice to avoid typos, you can add ``'email2'``. The field
68 ``'password2'`` can be used let the user type in their password twice to avoid
69 typos.
70
71 ``ACCOUNT_SIGNUP_FORM_CLASS`` (default: ``None``)
72 A string pointing to a custom form class (e.g. ``'myapp.forms.SignupForm'``)
73 that is used during signup to ask the user for additional input (e.g. a
74 newsletter signup checkbox, or birth date). This class should derive from just
75 ``forms.Form`` and only list the additional fields you need. It must implement
76 a ``def signup(self, request, user)`` method, which is called during the
77 signup process. This method allows you to handle and store the submitted data
78 as needed.
79
80 ``ACCOUNT_SIGNUP_FORM_HONEYPOT_FIELD`` (default: ``None``)
81 A string value that will be used as the HTML 'name' property
82 on a honeypot input field on the sign up form. Honeypot fields are hidden
83 to normal users but might be filled out by naive spam bots. When the field
84 is filled out the app will not create a new user and attempt to fool
85 the bot with a fake successful response. We recommend setting this
86 to some believable value that your app does not actually collect
87 on signup e.g. 'phone_number' or 'address'. Honeypots are not
88 always successful for sophisticated bots so this should be
89 used as one layer in a suite of spam detection tools if your
90 site is having trouble with spam.
91
92
93 Login
94 *****
95
96 ``ACCOUNT_LOGIN_BY_CODE_ENABLED`` (default: ``False``)
97 "Login by email" offers an alternative method of logging in. Instead of
98 entering an email address and accompanying password, the user only enters the
99 email address. Then, a one-time code is sent to that email address which
100 allows the user to login. This method is often referred to as "Magic Code
101 Login". This setting controls whether or not this method of logging in is
102 enabled.
103
104 ``ACCOUNT_LOGIN_BY_CODE_TRUST_ENABLED`` (default: ``False``)
105 Indicates whether the MFA "Trust this browser?" functionality is to be enabled
106 for logging in by code. Note that this requires the MFA app to be installed.
107
108 ``ACCOUNT_LOGIN_BY_CODE_MAX_ATTEMPTS`` (default: ``3``)
109 This setting controls the maximum number of attempts the user has at inputting
110 a valid code.
111
112 ``ACCOUNT_LOGIN_BY_CODE_REQUIRED`` (default: ``False``)
113 When enabled (in case of ``True``), every user logging in is required to input
114 a login confirmation code sent by email. Alternatively, you can specify a set
115 of authentication methods (``"password"``, ``"mfa"``, or ``"socialaccount"``)
116 for which login codes are required.
117
118 ``ACCOUNT_LOGIN_BY_CODE_SUPPORTS_RESEND`` (default: ``False``)
119 Whether or not the user can request a new login code.
120
121 ``ACCOUNT_LOGIN_BY_CODE_TIMEOUT`` (default: ``180``)
122 The code that is emailed has a limited life span. It expires this many seconds after
123 which it was sent.
124
125 ``ACCOUNT_LOGIN_BY_CODE_FORMAT`` (default: ``settings.ALLAUTH_USER_CODE_FORMAT``)
126 Controls the format of the login code.
127
128 ``ACCOUNT_LOGIN_METHODS`` (default: ``{"username"}``, options: ``"email"`` or ``"username"``)
129 Specifies the login method to use -- whether the user logs in by entering
130 their username, email address, or either one of both. Note that the login methods need to
131 align with ``ACCOUNT_SIGNUP_FIELDS``, as specifying a login method that you cannot sign up with
132 typically points to a configuration error.
133
134 ``ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION`` (default: ``False``)
135 The default behavior is not log users in and to redirect them to
136 ``ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL``.
137
138 By changing this setting to ``True``, users will automatically be logged in once
139 they confirm their email address. Note however that this only works when
140 confirming the email address **immediately after signing up**, assuming users
141 didn't close their browser or used some sort of private browsing mode.
142
143 Note that this setting only affects email verification by link. It has no affect in
144 case you turn on code based verification
145 (``ACCOUNT_EMAIL_VERIFICATION_BY_CODE_ENABLED``).
146
147 ``ACCOUNT_LOGIN_ON_PASSWORD_RESET`` (default: ``False``)
148 By changing this setting to ``True``, users will automatically be logged in
149 once they have reset their password. By default they are redirected to the
150 password reset done page.
151
152 ``ACCOUNT_LOGIN_TIMEOUT`` (default: ``900``)
153 The maximum allowed time (in seconds) for a login to go through the
154 various login stages. This limits, for example, the time span that the
155 2FA stage remains available.
156
157
158 Logout
159 ******
160
161 ``ACCOUNT_LOGOUT_ON_GET`` (default: ``False``)
162 Determines whether or not the user is automatically logged out by a
163 GET request. `GET is not designed to modify the server state <http://programmers.stackexchange.com/questions/188860/>`_,
164 and in this case it can be dangerous. See `LogoutView in the
165 documentation <https://docs.allauth.org/en/latest/account/views.html#logout>`_
166 for details.
167
168 ``ACCOUNT_LOGOUT_ON_PASSWORD_CHANGE`` (default: ``False``)
169 Determines whether or not the user is automatically logged out after
170 changing or setting their password. See documentation for
171 `Django's session invalidation on password change <https://docs.djangoproject.com/en/stable/topics/auth/default/#session-invalidation-on-password-change>`_.
172
173
174 Password Reset
175 **************
176
177 ``ACCOUNT_PASSWORD_INPUT_RENDER_VALUE`` (default: ``False``)
178 ``render_value`` parameter as passed to ``PasswordInput`` fields.
179
180 ``ACCOUNT_PASSWORD_RESET_BY_CODE_ENABLED`` (default: ``False``)
181 Controls whether password reset is performed by means of following a link
182 in the email (``False``), or by entering a code (``True``).
183
184 ``ACCOUNT_PASSWORD_RESET_BY_CODE_FORMAT`` (default: ``settings.ALLAUTH_USER_CODE_FORMAT``)
185 Controls the format of the password reset code.
186
187 ``ACCOUNT_PASSWORD_RESET_BY_CODE_MAX_ATTEMPTS`` (default: ``3``)
188 This setting controls the maximum number of attempts the user has at inputting
189 a valid code.
190
191 ``ACCOUNT_PASSWORD_RESET_BY_CODE_TIMEOUT`` (default: ``180``)
192 The code that is emailed has a limited life span. It expires this many seconds after
193 which it was sent.
194
195 ``ACCOUNT_PASSWORD_RESET_TOKEN_GENERATOR`` (default: ``"allauth.account.forms.EmailAwarePasswordResetTokenGenerator"``)
196 A string pointing to a custom token generator
197 (e.g. 'myapp.auth.CustomTokenGenerator') for password resets. This class
198 should implement the same methods as
199 ``django.contrib.auth.tokens.PasswordResetTokenGenerator`` or subclass it.
200
201
202 Email Verification
203 ******************
204
205 ``ACCOUNT_CONFIRM_EMAIL_ON_GET`` (default: ``False``)
206 Determines whether or not an email address is automatically confirmed by
207 a GET request. `GET is not designed to modify the server state
208 <http://programmers.stackexchange.com/questions/188860/>`_, though it is
209 commonly used for email confirmation. To avoid requiring user interaction,
210 consider using POST via Javascript in your email confirmation template as
211 an alternative to setting this to True.
212
213 ``ACCOUNT_EMAIL_CONFIRMATION_HMAC`` (default: ``True``)
214 In order to verify an email address, a key is mailed identifying the
215 email address to be verified. In previous versions, a record was
216 stored in the database for each ongoing email confirmation, keeping
217 track of these keys. Current versions use HMAC based keys that do not
218 require server side state.
219
220 ``ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS`` (default: ``3``)
221 Determines the expiration date of email confirmation mails (# of days).
222
223 ``ACCOUNT_EMAIL_VERIFICATION`` (default: ``"optional"``)
224 Determines the email verification method during signup -- choose
225 one of ``"mandatory"``, ``"optional"``, or ``"none"``.
226
227 When set to ``"mandatory"`` the user is blocked from logging in until the email
228 address is verified. Choose ``"optional"`` or ``"none"`` to allow logins
229 with an unverified email address. In case of ``"optional"``, the email
230 verification mail is still sent, whereas in case of "none" no email
231 verification mails are sent.
232
233 Setting this to ``"mandatory"`` requires ``"email*"`` to be listed in
234 ``ACCOUNT_SIGNUP_FIELDS``.
235
236 ``ACCOUNT_EMAIL_VERIFICATION_BY_CODE_ENABLED`` (default: ``False``)
237 Controls whether email verification is performed by means of following a link
238 in the email (``False``), or by entering a code (``True``).
239
240 ``ACCOUNT_EMAIL_VERIFICATION_BY_CODE_FORMAT`` (default: ``settings.ALLAUTH_USER_CODE_FORMAT``)
241 Controls the format of the email verification code.
242
243 ``ACCOUNT_EMAIL_VERIFICATION_BY_CODE_MAX_ATTEMPTS`` (default: ``3``)
244 This setting controls the maximum number of attempts the user has at inputting
245 a valid code.
246
247 ``ACCOUNT_EMAIL_VERIFICATION_BY_CODE_TIMEOUT`` (default: ``900``)
248 The code that is emailed has a limited life span. It expires this many seconds after
249 which it was sent.
250
251 ``ACCOUNT_EMAIL_VERIFICATION_SUPPORTS_CHANGE`` (default: ``False``)
252 Whether or not the email can be changed after signup at the email verification
253 stage.
254
255 **Warning**: If enumeration prevention is turned on, no account is created
256 when a user signs up using an already existing email. If the user then were
257 able to change to a new email address that is not taken, we would have to
258 create an account as we did not do so yet. Currently, this is not
259 implemented. Changing email address in this scenario is simply not allowed,
260 and therefore, a user paying close attention can deduce that an account
261 already exists. This will be revisited in a future release.
262
263 ``ACCOUNT_EMAIL_VERIFICATION_SUPPORTS_RESEND`` (default: ``False``)
264 Whether or not the user can request a new email verification code.
265
266
267 Reauthentication
268 ****************
269
270 ``ACCOUNT_REAUTHENTICATION_TIMEOUT`` (default: ``300``)
271 Before asking the user to reauthenticate, we check if a successful
272 (re)authentication happened within the amount of seconds specified here, and
273 if that is the case, the new reauthentication flow is silently skipped.
274
275 ``ACCOUNT_REAUTHENTICATION_REQUIRED`` (default: ``False``)
276 Specifies whether or not reauthentication is required before the user can
277 alter his account.
278
279
280 Routing
281 *******
282
283 ``ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS`` (default: ``True``)
284 The default behaviour is to redirect authenticated users to
285 ``LOGIN_REDIRECT_URL`` when they try accessing login/signup pages.
286
287 By changing this setting to ``False``, logged in users will not be redirected when
288 they access login/signup pages.
289
290 ``ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL`` (default: ``settings.LOGIN_URL``)
291 The URL to redirect to after a successful email confirmation, in case no
292 user is logged in.
293
294 ``ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL`` (default: ``None``)
295 The URL to redirect to after a successful email confirmation, in
296 case of an authenticated user. Set to ``None`` to use
297 ``settings.LOGIN_REDIRECT_URL``.
298
299 ``ACCOUNT_LOGOUT_REDIRECT_URL`` (default: ``settings.LOGOUT_REDIRECT_URL or "/"``)
300 The URL (or URL name) to return to after the user logs out. Defaults to
301 Django's ``LOGOUT_REDIRECT_URL``, unless that is empty, then ``"/"`` is used.
302
303 ``ACCOUNT_SIGNUP_REDIRECT_URL`` (default: ``settings.LOGIN_REDIRECT_URL``)
304 The URL (or URL name) to redirect to directly after signing up. Note that
305 users are only redirected to this URL if the signup went through
306 uninterruptedly, for example, without any side steps due to email
307 verification. If your project requires the user to always pass through certain
308 onboarding views after signup, you will have to keep track of state indicating
309 whether or not the user successfully onboarded, and handle accordingly.
310
311
312 Sending Email
313 *************
314
315 ``ACCOUNT_EMAIL_SUBJECT_PREFIX`` (default: ``"[Site] "``)
316 Subject-line prefix to use for email messages sent. By default, the
317 name of the current ``Site`` (``django.contrib.sites``) is used.
318
319 ``ACCOUNT_EMAIL_UNKNOWN_ACCOUNTS`` (default: ``True``)
320 Configures whether password reset attempts for email addresses which do not
321 have an account result in sending an email.
322
323 ``ACCOUNT_EMAIL_NOTIFICATIONS`` (default: ``False``)
324 When enabled, account related security notifications, such as "Your password
325 was changed", including information on user agent / IP address from where the
326 change originated, will be emailed.
327
328
329 Email Addresses
330 ***************
331
332 ``ACCOUNT_CHANGE_EMAIL`` (default: ``False``)
333 When disabled (``False``), users can add one or more email addresses (up to a
334 maximum of ``ACCOUNT_MAX_EMAIL_ADDRESSES``) to their account and freely manage
335 those email addresses. When enabled (``True``), users are limited to having
336 exactly one email address that they can change by adding a temporary second
337 email address that, when verified, replaces the current email address.
338
339 ``ACCOUNT_EMAIL_MAX_LENGTH`` (default: ``254``)
340 Maximum length of the email field. You won't need to alter this unless using
341 MySQL with the InnoDB storage engine and the ``utf8mb4`` charset, and only in
342 versions lower than 5.7.7, because the default InnoDB settings don't allow
343 indexes bigger than 767 bytes. When using ``utf8mb4``, characters are 4-bytes
344 wide, so at maximum column indexes can be 191 characters long (767/4).
345 Unfortunately Django doesn't allow specifying index lengths, so the solution
346 is to reduce the length in characters of indexed text fields.
347 More information can be found at `MySQL's documentation on converting between
348 3-byte and 4-byte Unicode character sets
349 <https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-conversion.html>`_.
350
351 ``ACCOUNT_MAX_EMAIL_ADDRESSES`` (default: ``None``)
352 The maximum amount of email addresses a user can associate to his account. It
353 is safe to change this setting for an already running project -- it will not
354 negatively affect users that already exceed the allowed amount. Note that if
355 you set the maximum to 1, users will not be able to change their email
356 address.
357
358 ``ACCOUNT_UNIQUE_EMAIL`` (default: ``True``)
359 Enforce uniqueness of email addresses. On the database level, this implies
360 that only one user account can have an email address marked as verified.
361 Forms prevent a user from registering with or adding an additional email
362 address if that email address is in use by another account.
363
364
365 User Model
366 **********
367
368 ``ACCOUNT_PRESERVE_USERNAME_CASING`` (default: ``True``)
369 This setting determines whether the username is stored in lowercase
370 (``False``) or whether its casing is to be preserved (``True``). Note that when
371 casing is preserved, potentially expensive ``__iexact`` lookups are performed
372 when filter on username. For now, the default is set to ``True`` to maintain
373 backwards compatibility.
374
375 ``ACCOUNT_USERNAME_BLACKLIST`` (default: ``[]``)
376 A list of usernames that can't be used by user.
377
378 ``ACCOUNT_USER_DISPLAY`` (default: a callable returning ``user.username``)
379 A callable (or string of the form ``'some.module.callable_name'``)
380 that takes a user as its only argument and returns the display name
381 of the user. The default implementation returns ``user.username``.
382
383 ``ACCOUNT_USER_MODEL_EMAIL_FIELD`` (default: ``"email"``)
384 The name of the field containing the ``email``, if any. See custom
385 user models.
386
387 ``ACCOUNT_USER_MODEL_USERNAME_FIELD`` (default: ``"username"``)
388 The name of the field containing the ``username``, if any. See custom
389 user models.
390
391 ``ACCOUNT_USERNAME_MIN_LENGTH`` (default: ``1``)
392 An integer specifying the minimum allowed length of a username.
393
394 ``ACCOUNT_USERNAME_VALIDATORS`` (default: ``None``)
395 A path
396 (``'some.module.validators.custom_username_validators'``) to a list of
397 custom username validators. If left unset, the validators setup
398 within the user model username field are used.
399
400 Example::
401
402 # In validators.py
403
404 from django.contrib.auth.validators import ASCIIUsernameValidator
405
406 custom_username_validators = [ASCIIUsernameValidator()]
407
408 # In settings.py
409
410 ACCOUNT_USERNAME_VALIDATORS = 'some.module.validators.custom_username_validators'