@@ -46,35 +46,57 @@ After connecting the Django Forbid to your project, you can define the set of de
46
46
All you need is to set the ` DJANGO_FORBID ` variable in your project's settings. It should be a dictionary with the
47
47
following keys:
48
48
49
+ - ` DEVICES ` - list of devices to permit or forbid access to
49
50
- ` COUNTRIES ` - list of countries to permit or forbid access to
50
51
- ` TERRITORIES ` - list of territories to permit or forbid access to
51
52
- ` OPTIONS ` - a dictionary for additional settings
52
- - ` ACTION ` - whether to ` PERMIT ` or ` FORBID ` access to the listed zones (default is ` FORBID ` )
53
- - ` PERIOD ` - time in seconds to check for access again, 0 means on each request
54
- - ` VPN ` - use VPN detection and forbid access to VPN users
55
- - ` URL ` - set of URLs to redirect to when the user is located in a forbidden country or using a VPN
56
- - ` FORBIDDEN_LOC ` - the URL to redirect to when the user is located in a forbidden country
57
- - ` FORBIDDEN_VPN ` - the URL to redirect to when the user is using a VPN
53
+ - ` ACTION ` - whether to ` PERMIT ` or ` FORBID ` access to the listed zones (default is ` FORBID ` )
54
+ - ` PERIOD ` - time in seconds to check for access again, 0 means on each request
55
+ - ` VPN ` - use VPN detection and forbid access to VPN users
56
+ - ` URL ` - set of URLs to redirect to when the user is located in a forbidden country or using a VPN
57
+ - ` FORBIDDEN_LOC ` - the URL to redirect to when the user is located in a forbidden country
58
+ - ` FORBIDDEN_VPN ` - the URL to redirect to when the user is using a VPN
59
+ - ` FORBIDDEN_KIT ` - the URL to redirect to when the user is using a forbidden device
60
+
61
+ Unlike the ` COUNTRIES ` and ` TERRITORIES ` , where the middleware decides whether to permit or forbid access based on the
62
+ given ` ACTION ` value, the ` DEVICES ` list accepts device types where the names starting with ` ! ` are forbidden. This is
63
+ done to make it possible to make them all mix together.
64
+
65
+ ``` python
66
+ # Forbid access to all devices that have a small screen.
67
+ ' DEVICES' : [' !car' , ' !player' , ' !peripheral' , ' !camera' ]
68
+
69
+ # Allow access to all devices having regular or large screens.
70
+ ' DEVICES' : [' desktop' , ' smartphone' , ' console' , ' tablet' , ' tv' ]
71
+ ```
72
+
73
+ The available device types are: ` smartphone ` , ` peripheral ` - refers to all hardware components that are attached to a
74
+ computer, ` wearable ` - common types of wearable technology include smartwatches and smartglasses, ` phablet ` - a
75
+ smartphone having a larger screen, ` console ` - PlayStation, Xbox, etc., ` display ` , ` speaker ` - Google Assistant, Siri,
76
+ Alexa, etc., ` desktop ` , ` tablet ` , ` camera ` , ` player ` - iPod, Sony Walkman, Creative Zen, etc., ` phone ` , ` car ` - refers
77
+ to a car browser and ` tv ` - refers to TVs having internet access.
58
78
59
79
``` python
60
80
DJANGO_FORBID = {
81
+ ' DEVICES' : [' desktop' , ' smartphone' , ' console' , ' tablet' , ' tv' ],
61
82
' COUNTRIES' : [' US' , ' GB' ],
62
83
' TERRITORIES' : [' EU' ],
63
84
' OPTIONS' : {
64
85
' ACTION' : ' PERMIT' ,
65
86
' PERIOD' : 300 ,
66
87
' VPN' : True ,
67
88
' URL' : {
68
- ' FORBIDDEN_LOC' : ' forbidden_country ' ,
89
+ ' FORBIDDEN_LOC' : ' forbidden_location ' ,
69
90
' FORBIDDEN_VPN' : ' forbidden_network' ,
91
+ ' FORBIDDEN_KIT' : ' forbidden_device' ,
70
92
},
71
93
},
72
94
}
73
95
```
74
96
75
- The available ISO 3166 alpha-2 country codes are listed in [ here ] ( https://www.iban.com/country-codes ) . And the available
76
- ISO continent codes are: ` AF ` - Africa, ` AN ` - Antarctica, ` AS ` - Asia, ` EU ` - Europe, ` NA ` - North America, ` OC ` -
77
- Oceania and ` SA ` - South America.
97
+ The available country codes in the required ISO 3166 alpha-2 format are
98
+ listed [ here ] ( https://www.iban.com/country-codes ) . And the available continent codes (territories) are: ` AF ` -
99
+ Africa, ` AN ` - Antarctica, ` AS ` - Asia, ` EU ` - Europe, ` NA ` - North America, ` OC ` - Oceania and ` SA ` - South America.
78
100
79
101
_ None of the settings are required. If you don't specify any settings, the middleware will not do anything._
80
102
0 commit comments