Skip to content

Commit 9e2bbd7

Browse files
aseem-hegshetyedopry
authored andcommitted
feat: Redirect admin users to setup TOTP
When TOTP is required on an admin view and a user does not have a TOTP device configured, redirect them to the TOTP setup view.
1 parent 4bd592c commit 9e2bbd7

File tree

10 files changed

+301
-87
lines changed

10 files changed

+301
-87
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ example/settings_private.py
1010
.eggs/
1111

1212
.idea/
13+
14+
venv/

CHANGELOG.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
# Change Log
12
## Unreleased
23

34
### Added
45
- Enforcing a redirect to setup of otp device when none available for user [#550](https://github.com/jazzband/django-two-factor-auth/pull/500)
6+
7+
### Changed
8+
- [Breaking] Remove admin monkey patching, now you will need to explicitly use the alternate AdminSite or include the Mixin in your custom admin site implementation.
9+
510

611
## 1.14.0
712

813
### Added
14+
915
- Python 3.10 support
1016
- The setup view got a new `secret_key` context variable to be able to display
1117
that key elsewhere than in the QR code.
@@ -15,6 +21,7 @@
1521
and used to communicate the second factor token by email.
1622

1723
### Changed
24+
1825
- BREAKING: The phone capability moved to a plugins folder, so if you use that
1926
capability and want to keep it, you should add `two_factor.plugins.phonenumber`
2027
line in your `INSTALLED_APPS` setting. Additionally, as the `two_factor`
@@ -30,167 +37,213 @@
3037
with a dark theme.
3138

3239
### Removed
40+
3341
- Python 3.5 and 3.6 support
3442

3543
## 1.13.2
3644

3745
### Added
46+
3847
- Translations for new languages: Hausa, Japanese, Vietnamese
3948
- Django 4.0 support
4049

4150
### Changed
51+
4252
- Suppressed default_app_config warning on Django 3.2+
4353
- qrcode dependency limit upped to 7.99 and django-phonenumber-field to 7
4454
- When validating a TOTP after scanning the QR code, allow a time drift of +/-1 instead of just -1
4555

4656
## 1.13.1
4757

4858
### Add
59+
4960
- Support Twilio Messaging Service SID
5061
- Add autofocus, autocomplete one-time-code and inputmode numeric to token input fields
5162

5263
### Changed
64+
5365
- Change "Back to Profile" to "Back to Account Security"
5466

5567
## 1.13.0
5668

5769
### Added
70+
5871
- User can request that two-factor authentication be skipped the next time they
5972
log in on that particular device
6073
- Django 3.1 support
6174
- SMS message can now be customised by using a template
6275

6376
### Changed
77+
6478
- Simplified `re_path()` to `path()` in URLConf
6579
- Templates are now based on Bootstrap 4.
6680
- `DisableView` now checks user has verified before disabling two-factor on
6781
their account
6882
- Inline CSS has been replaced to allow stricter Content Security Policies.
6983

7084
### Removed
85+
7186
- Upper limit on django-otp dependency
7287
- Obsolete IE<9 workarounds
7388
- Workarounds for older versions of django-otp
7489

7590
## 1.12.1 - 2020-07-08
7691

77-
*No code changes for this version*
92+
_No code changes for this version_
7893

7994
## 1.12 - 2020-07-08
95+
8096
### Added
97+
8198
- It is possible to set a timeout between a user authenticiating in the
8299
`LoginView` and them needing to re-authenticate. By default this is 10
83100
minutes.
84101

85102
### Removed
103+
86104
- The final step in the `LoginView` no longer re-validates a user's credentials.
87105
- Django 1.11 support.
88106

89107
### Changed
108+
90109
- Security Fix: `LoginView` no longer stores credentials in plaintext in the
91110
session store.
92111

93112
## 1.11.0 - 2020-03-13
113+
94114
### Added
95115

96-
*Nothing has been added for this version*
116+
_Nothing has been added for this version_
97117

98118
### Removed
119+
99120
- MiddlewareMixin
100121
- Python 3.4 support
101122
- Django 2.1 support
102123
- `mock` dependency
103124

104125
### Changed
126+
105127
- `extra_requires` are now listed in lowercase. This is to workaround a bug in `pip`.
106128
- Use `trimmed` option on `blocktrans` to avoid garbage newlines in translations.
107129
- `random_hex` from `django_otp` 0.8.0 will always return a `str`, don't try to decode it.
108130

109131
## 1.10.0 - 2019-12-13
132+
110133
### Added
134+
111135
- Support for Django 3.0.
112136
- Optionally install full or light phonenumbers library.
113137

114138
### Removed
139+
115140
- Python 2 support.
116141

117142
### Changed
143+
118144
- Updated translations.
119145

120146
## 1.9.1 - 2019-07-07
147+
121148
### Changed
149+
122150
- 1.9.0 got pushed with incorrect changelog, no other changes.
123151

124152
## 1.9.0 - 2019-07-07
153+
125154
### Added
155+
126156
- Support for Django 2.2.
127157
- Ability to create `PhoneDevice` from Django admin.
128158
- Support for Python 3.7.
129159

130160
## 1.8.0 - 2018-08-03
161+
131162
### Added
163+
132164
- Support for Django 2.1.
133165
- Support for QRcode library up to 6.
134166
- Translation: Romanian.
135167

136168
### Changed
169+
137170
- Replace `ValidationError` with `SuspiciousOperation` in views.
138171
- Change the wording in 2FA disable template.
139172
- Updated translations.
140173

141174
## 1.7.0 - 2017-12-19
175+
142176
### Added
177+
143178
- Support for Django 2.0.
144179

145180
### Removed
181+
146182
- Django <1.11 support.
147183

148184
### Changed
185+
149186
- Do not list phone method if it is not supported (#225).
150187
- Pass request kwarg to authentication form (#227).
151188

152189
## 1.6.2 - 2017-07-29
190+
153191
### Fixed
192+
154193
- Twilio client 6.0 usage (#211).
155194

156195
### Changed
196+
157197
- Updated translation: Russian.
158198

159199
## 1.6.1 - 2017-05-11
200+
160201
### Added
202+
161203
- Support Twilio client 6.0 (#203).
162204

163205
### Fixed
206+
164207
- `redirect_to` after successful login (#204)
165208

166209
### Changed
210+
167211
- Updated translation: Norwegian Bokmål
168212

169213
## 1.6.0 - 2017-04-08
214+
170215
### Added
216+
171217
- Support for Django 1.11 (#188).
172218

173219
### Removed
220+
174221
- Django 1.9 support.
175222

176223
### Fixed
224+
177225
- Allow setting `LOGIN_REDIRECT_URL` to a URL (#192).
178226
- `DisableView` should also take `success_url` parameter (#187).
179227

180228
## 1.5.0 - 2017-01-04
229+
181230
### Added
231+
182232
- Django 1.10’s MIDDLEWARE support.
183233
- Allow `success_url` overrides from `urls.py`.
184234
- Autofocus token input during authentication.
185235
- Translations: Polish, Italian, Hungarian, Finnish and Danish.
186236

187237
### Removed
238+
188239
- Dropped Python 3.2 and 3.3 support.
189240

190241
### Changed
242+
191243
- Renamed `redirect_url` properties to `success_url` to be consistent with Django.
192244

193245
### Fixed
246+
194247
- Allow Firefox users to enter backup tokens (#177).
195248
- Allow multiple requests for QR code (#99).
196249
- Don't add phone number without gateway (#92).

docs/class-reference.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Class Reference
33

44
Admin Site
55
----------
6-
.. autoclass:: two_factor.admin.AdminSiteOTPRequired
7-
.. autoclass:: two_factor.admin.AdminSiteOTPRequiredMixin
6+
.. autoclass:: two_factor.admin.TwoFactorAdminSite
7+
.. autoclass:: two_factor.admin.TwoFactorAdminSiteMixin
88

99
Decorators
1010
----------

docs/installation.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ Add the routes to your project url configuration:
6666
.. code-block:: python
6767
6868
from two_factor.urls import urlpatterns as tf_urls
69+
from two_factor.admin import TwoFactorAdminSite
6970
urlpatterns = [
7071
path('', include(tf_urls)),
71-
...
72+
path('admin', TwoFactorAdminSite().urls)
7273
]
7374
7475
.. warning::

example/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from django.conf import settings
2-
from django.contrib import admin
32
from django.contrib.auth.views import LogoutView
43
from django.urls import include, path
54

5+
from two_factor.admin import TwoFactorAdminSite
66
from two_factor.gateways.twilio.urls import urlpatterns as tf_twilio_urls
77
from two_factor.urls import urlpatterns as tf_urls
88

@@ -39,7 +39,7 @@
3939
path('', include(tf_urls)),
4040
path('', include(tf_twilio_urls)),
4141
path('', include('user_sessions.urls', 'user_sessions')),
42-
path('admin/', admin.site.urls),
42+
path('admin/', TwoFactorAdminSite().urls),
4343
]
4444

4545
if settings.DEBUG:

requirements_dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ django-bootstrap-form
1414
django-user-sessions
1515

1616
# Testing
17-
1817
coverage
1918
flake8
2019
tox

0 commit comments

Comments
 (0)