File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ from django .conf import settings
2+ from django_otp import user_has_device
3+
4+
5+ def user_needs_to_verify_otp (user ):
6+ """
7+ This method checks if the device verification is required due to imported
8+ middleware in the application settings.
9+
10+ Return True as default, to maintain the current behavior as specified in the
11+ otp middleware.
12+
13+ Returns:
14+ bool: True if otp verification is required for the user, False otherwise.
15+ """
16+
17+ if (
18+ "hidp.otp.middleware.OTPRequiredMiddleware"
19+ ) in settings .MIDDLEWARE :
20+ return True
21+
22+ if (
23+ "hidp.otp.middleware.OTPSetupRequiredIfStaffUserMiddleware"
24+ ) in settings .MIDDLEWARE :
25+ return user .is_staff
26+
27+ if (
28+ "hidp.otp.middleware.OTPVerificationRequiredIfConfiguredMiddleware"
29+ ) in settings .MIDDLEWARE :
30+ return user_has_device (user )
31+
32+ return True
You can’t perform that action at this time.
0 commit comments