Skip to content

Commit 2cf0994

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 54170a4 commit 2cf0994

File tree

11 files changed

+324
-90
lines changed

11 files changed

+324
-90
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: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
# Change Log
2+
13
## Unreleased
24

35
### Added
6+
47
- Python 3.10 support
8+
- If a user tries to access the Admin Site without an OTP Device setup, then the user will be redirected to the OTP
9+
setup page.
510

611
### Changed
12+
713
- default_device utility function now caches the found device on the given user object
814
- The phone capability moved to a plugins folder, so if you use that capability
915
and want to keep it, you should add `two_factor.plugins.phonenumber` line in
@@ -12,167 +18,213 @@
1218
`phonenumber`.
1319

1420
### Removed
21+
1522
- Python 3.5 and 3.6 support
1623

1724
## 1.13.2
1825

1926
### Added
27+
2028
- Translations for new languages: Hausa, Japanese, Vietnamese
2129
- Django 4.0 support
2230

2331
### Changed
32+
2433
- Suppressed default_app_config warning on Django 3.2+
2534
- qrcode dependency limit upped to 7.99 and django-phonenumber-field to 7
2635
- When validating a TOTP after scanning the QR code, allow a time drift of +/-1 instead of just -1
2736

2837
## 1.13.1
2938

3039
### Add
40+
3141
- Support Twilio Messaging Service SID
3242
- Add autofocus, autocomplete one-time-code and inputmode numeric to token input fields
3343

3444
### Changed
45+
3546
- Change "Back to Profile" to "Back to Account Security"
3647

3748
## 1.13.0
3849

3950
### Added
51+
4052
- User can request that two-factor authentication be skipped the next time they
4153
log in on that particular device
4254
- Django 3.1 support
4355
- SMS message can now be customised by using a template
4456

4557
### Changed
58+
4659
- Simplified `re_path()` to `path()` in URLConf
4760
- Templates are now based on Bootstrap 4.
4861
- `DisableView` now checks user has verified before disabling two-factor on
4962
their account
5063
- Inline CSS has been replaced to allow stricter Content Security Policies.
5164

5265
### Removed
66+
5367
- Upper limit on django-otp dependency
5468
- Obsolete IE<9 workarounds
5569
- Workarounds for older versions of django-otp
5670

5771
## 1.12.1 - 2020-07-08
5872

59-
*No code changes for this version*
73+
_No code changes for this version_
6074

6175
## 1.12 - 2020-07-08
76+
6277
### Added
78+
6379
- It is possible to set a timeout between a user authenticiating in the
6480
`LoginView` and them needing to re-authenticate. By default this is 10
6581
minutes.
6682

6783
### Removed
84+
6885
- The final step in the `LoginView` no longer re-validates a user's credentials.
6986
- Django 1.11 support.
7087

7188
### Changed
89+
7290
- Security Fix: `LoginView` no longer stores credentials in plaintext in the
7391
session store.
7492

7593
## 1.11.0 - 2020-03-13
94+
7695
### Added
7796

78-
*Nothing has been added for this version*
97+
_Nothing has been added for this version_
7998

8099
### Removed
100+
81101
- MiddlewareMixin
82102
- Python 3.4 support
83103
- Django 2.1 support
84104
- `mock` dependency
85105

86106
### Changed
107+
87108
- `extra_requires` are now listed in lowercase. This is to workaround a bug in `pip`.
88109
- Use `trimmed` option on `blocktrans` to avoid garbage newlines in translations.
89110
- `random_hex` from `django_otp` 0.8.0 will always return a `str`, don't try to decode it.
90111

91112
## 1.10.0 - 2019-12-13
113+
92114
### Added
115+
93116
- Support for Django 3.0.
94117
- Optionally install full or light phonenumbers library.
95118

96119
### Removed
120+
97121
- Python 2 support.
98122

99123
### Changed
124+
100125
- Updated translations.
101126

102127
## 1.9.1 - 2019-07-07
128+
103129
### Changed
130+
104131
- 1.9.0 got pushed with incorrect changelog, no other changes.
105132

106133
## 1.9.0 - 2019-07-07
134+
107135
### Added
136+
108137
- Support for Django 2.2.
109138
- Ability to create `PhoneDevice` from Django admin.
110139
- Support for Python 3.7.
111140

112141
## 1.8.0 - 2018-08-03
142+
113143
### Added
144+
114145
- Support for Django 2.1.
115146
- Support for QRcode library up to 6.
116147
- Translation: Romanian.
117148

118149
### Changed
150+
119151
- Replace `ValidationError` with `SuspiciousOperation` in views.
120152
- Change the wording in 2FA disable template.
121153
- Updated translations.
122154

123155
## 1.7.0 - 2017-12-19
156+
124157
### Added
158+
125159
- Support for Django 2.0.
126160

127161
### Removed
162+
128163
- Django <1.11 support.
129164

130165
### Changed
166+
131167
- Do not list phone method if it is not supported (#225).
132168
- Pass request kwarg to authentication form (#227).
133169

134170
## 1.6.2 - 2017-07-29
171+
135172
### Fixed
173+
136174
- Twilio client 6.0 usage (#211).
137175

138176
### Changed
177+
139178
- Updated translation: Russian.
140179

141180
## 1.6.1 - 2017-05-11
181+
142182
### Added
183+
143184
- Support Twilio client 6.0 (#203).
144185

145186
### Fixed
187+
146188
- `redirect_to` after successful login (#204)
147189

148190
### Changed
191+
149192
- Updated translation: Norwegian Bokmål
150193

151194
## 1.6.0 - 2017-04-08
195+
152196
### Added
197+
153198
- Support for Django 1.11 (#188).
154199

155200
### Removed
201+
156202
- Django 1.9 support.
157203

158204
### Fixed
205+
159206
- Allow setting `LOGIN_REDIRECT_URL` to a URL (#192).
160207
- `DisableView` should also take `success_url` parameter (#187).
161208

162209
## 1.5.0 - 2017-01-04
210+
163211
### Added
212+
164213
- Django 1.10’s MIDDLEWARE support.
165214
- Allow `success_url` overrides from `urls.py`.
166215
- Autofocus token input during authentication.
167216
- Translations: Polish, Italian, Hungarian, Finnish and Danish.
168217

169218
### Removed
219+
170220
- Dropped Python 3.2 and 3.3 support.
171221

172222
### Changed
223+
173224
- Renamed `redirect_url` properties to `success_url` to be consistent with Django.
174225

175226
### Fixed
227+
176228
- Allow Firefox users to enter backup tokens (#177).
177229
- Allow multiple requests for QR code (#99).
178230
- 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
@@ -64,9 +64,10 @@ Add the routes to your project url configuration:
6464
.. code-block:: python
6565
6666
from two_factor.urls import urlpatterns as tf_urls
67+
from two_factor.admin import TwoFactorAdminSite
6768
urlpatterns = [
6869
path('', include(tf_urls)),
69-
...
70+
path('admin', TwoFactorAdminSite().urls)
7071
]
7172
7273
.. 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)