Skip to content

Commit ee91b53

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 51b7fc2 commit ee91b53

File tree

11 files changed

+332
-90
lines changed

11 files changed

+332
-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: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
# Change Log
2+
3+
## Unreleased
4+
5+
### Added
6+
7+
- If a user tries to access the Admin Site without an OTP Device setup, then the user will be redirected to the OTP
8+
setup page.
9+
10+
### Changed
11+
12+
113
## 1.14.0
214

315
### Added
16+
417
- Python 3.10 support
518
- The setup view got a new `secret_key` context variable to be able to display
619
that key elsewhere than in the QR code.
@@ -10,6 +23,7 @@
1023
and used to communicate the second factor token by email.
1124

1225
### Changed
26+
1327
- BREAKING: The phone capability moved to a plugins folder, so if you use that
1428
capability and want to keep it, you should add `two_factor.plugins.phonenumber`
1529
line in your `INSTALLED_APPS` setting. Additionally, as the `two_factor`
@@ -25,167 +39,213 @@
2539
with a dark theme.
2640

2741
### Removed
42+
2843
- Python 3.5 and 3.6 support
2944

3045
## 1.13.2
3146

3247
### Added
48+
3349
- Translations for new languages: Hausa, Japanese, Vietnamese
3450
- Django 4.0 support
3551

3652
### Changed
53+
3754
- Suppressed default_app_config warning on Django 3.2+
3855
- qrcode dependency limit upped to 7.99 and django-phonenumber-field to 7
3956
- When validating a TOTP after scanning the QR code, allow a time drift of +/-1 instead of just -1
4057

4158
## 1.13.1
4259

4360
### Add
61+
4462
- Support Twilio Messaging Service SID
4563
- Add autofocus, autocomplete one-time-code and inputmode numeric to token input fields
4664

4765
### Changed
66+
4867
- Change "Back to Profile" to "Back to Account Security"
4968

5069
## 1.13.0
5170

5271
### Added
72+
5373
- User can request that two-factor authentication be skipped the next time they
5474
log in on that particular device
5575
- Django 3.1 support
5676
- SMS message can now be customised by using a template
5777

5878
### Changed
79+
5980
- Simplified `re_path()` to `path()` in URLConf
6081
- Templates are now based on Bootstrap 4.
6182
- `DisableView` now checks user has verified before disabling two-factor on
6283
their account
6384
- Inline CSS has been replaced to allow stricter Content Security Policies.
6485

6586
### Removed
87+
6688
- Upper limit on django-otp dependency
6789
- Obsolete IE<9 workarounds
6890
- Workarounds for older versions of django-otp
6991

7092
## 1.12.1 - 2020-07-08
7193

72-
*No code changes for this version*
94+
_No code changes for this version_
7395

7496
## 1.12 - 2020-07-08
97+
7598
### Added
99+
76100
- It is possible to set a timeout between a user authenticiating in the
77101
`LoginView` and them needing to re-authenticate. By default this is 10
78102
minutes.
79103

80104
### Removed
105+
81106
- The final step in the `LoginView` no longer re-validates a user's credentials.
82107
- Django 1.11 support.
83108

84109
### Changed
110+
85111
- Security Fix: `LoginView` no longer stores credentials in plaintext in the
86112
session store.
87113

88114
## 1.11.0 - 2020-03-13
115+
89116
### Added
90117

91-
*Nothing has been added for this version*
118+
_Nothing has been added for this version_
92119

93120
### Removed
121+
94122
- MiddlewareMixin
95123
- Python 3.4 support
96124
- Django 2.1 support
97125
- `mock` dependency
98126

99127
### Changed
128+
100129
- `extra_requires` are now listed in lowercase. This is to workaround a bug in `pip`.
101130
- Use `trimmed` option on `blocktrans` to avoid garbage newlines in translations.
102131
- `random_hex` from `django_otp` 0.8.0 will always return a `str`, don't try to decode it.
103132

104133
## 1.10.0 - 2019-12-13
134+
105135
### Added
136+
106137
- Support for Django 3.0.
107138
- Optionally install full or light phonenumbers library.
108139

109140
### Removed
141+
110142
- Python 2 support.
111143

112144
### Changed
145+
113146
- Updated translations.
114147

115148
## 1.9.1 - 2019-07-07
149+
116150
### Changed
151+
117152
- 1.9.0 got pushed with incorrect changelog, no other changes.
118153

119154
## 1.9.0 - 2019-07-07
155+
120156
### Added
157+
121158
- Support for Django 2.2.
122159
- Ability to create `PhoneDevice` from Django admin.
123160
- Support for Python 3.7.
124161

125162
## 1.8.0 - 2018-08-03
163+
126164
### Added
165+
127166
- Support for Django 2.1.
128167
- Support for QRcode library up to 6.
129168
- Translation: Romanian.
130169

131170
### Changed
171+
132172
- Replace `ValidationError` with `SuspiciousOperation` in views.
133173
- Change the wording in 2FA disable template.
134174
- Updated translations.
135175

136176
## 1.7.0 - 2017-12-19
177+
137178
### Added
179+
138180
- Support for Django 2.0.
139181

140182
### Removed
183+
141184
- Django <1.11 support.
142185

143186
### Changed
187+
144188
- Do not list phone method if it is not supported (#225).
145189
- Pass request kwarg to authentication form (#227).
146190

147191
## 1.6.2 - 2017-07-29
192+
148193
### Fixed
194+
149195
- Twilio client 6.0 usage (#211).
150196

151197
### Changed
198+
152199
- Updated translation: Russian.
153200

154201
## 1.6.1 - 2017-05-11
202+
155203
### Added
204+
156205
- Support Twilio client 6.0 (#203).
157206

158207
### Fixed
208+
159209
- `redirect_to` after successful login (#204)
160210

161211
### Changed
212+
162213
- Updated translation: Norwegian Bokmål
163214

164215
## 1.6.0 - 2017-04-08
216+
165217
### Added
218+
166219
- Support for Django 1.11 (#188).
167220

168221
### Removed
222+
169223
- Django 1.9 support.
170224

171225
### Fixed
226+
172227
- Allow setting `LOGIN_REDIRECT_URL` to a URL (#192).
173228
- `DisableView` should also take `success_url` parameter (#187).
174229

175230
## 1.5.0 - 2017-01-04
231+
176232
### Added
233+
177234
- Django 1.10’s MIDDLEWARE support.
178235
- Allow `success_url` overrides from `urls.py`.
179236
- Autofocus token input during authentication.
180237
- Translations: Polish, Italian, Hungarian, Finnish and Danish.
181238

182239
### Removed
240+
183241
- Dropped Python 3.2 and 3.3 support.
184242

185243
### Changed
244+
186245
- Renamed `redirect_url` properties to `success_url` to be consistent with Django.
187246

188247
### Fixed
248+
189249
- Allow Firefox users to enter backup tokens (#177).
190250
- Allow multiple requests for QR code (#99).
191251
- 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)