Changes between Version 9 and Version 10 of CookBookIPAccessMiddleware
- Timestamp:
- Dec 22, 2006, 3:44:43 AM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CookBookIPAccessMiddleware
v9 v10 3 3 == The idea == 4 4 5 Controling IP access in your web app. The idea provided in this cookbook let you define specific ip addresses, and controlling accessing from those ips. If an user access from a certain IP, automatically authenticates with a defined user.5 The idea of this recipe is to provide automatic user authentication based on specified IP addresses for some client computers. 6 6 7 7 == IPAccess Model == 8 8 9 You must define a model that permits defining a tuple (ip addr, user): ip from browser that connect, and users thatauthenticated.9 You must define a model that allows defining tuples of type (IP addr, user): IP of the client computer with the web browser, user to be authenticated. 10 10 11 This is the model proposed (it would be in a file like''myproj/myapp/models.py''):11 This is the proposed model (suppose ''myproj/myapp/models.py''): 12 12 13 13 {{{ … … 34 34 == IPAccess Middleware == 35 35 36 Middleware mission is authenticate automatically with an user defined in models, '''only if''' the browser remote ip address exists in''IPAccess'' table.36 The mission of this middleware is to authenticate automatically with an user defined in models, '''only if''' the browser's remote IP address exists in the ''IPAccess'' table. 37 37 38 38 This is the code (in file ''myproj/myapp/middleware.py''): … … 58 58 == Settings == 59 59 60 The middleware installation requires you insert ''IPAccessMiddleware'' into ''MIDDLEWARE_CLASSES''. Obviusly, it also requires the installation of ''!AuthenticationMiddleware''.60 For the middleware to work, you have to insert a line with ''IPAccessMiddleware'' into ''MIDDLEWARE_CLASSES'' of the settings.py file. Obviously, it also requires the installation of ''!AuthenticationMiddleware''. 61 61 62 The code would be like that:62 The code should be something like this: 63 63 64 64 {{{ … … 69 69 'django.contrib.auth.middleware.AuthenticationMiddleware', 70 70 'django.middleware.doc.XViewMiddleware', 71 ' aceprensa.apps.news.middleware.IPAccessMiddleware',71 'yourproject.apps.news.middleware.IPAccessMiddleware', 72 72 ) 73 73 74 74 }}} 75 75 76 == Complete Application ==76 == A Complete Application == 77 77 78 I also developed [attachment:ipaccess.tgz ipaccess a pplication] which offers this functionality. For installing you have to untar compressed application and put in ''apps'' directory in your project. Then, you have to ''update'' import statements and add to applications installed settings:78 I also developed [attachment:ipaccess.tgz ipaccess an application] which offers this functionality. To install it, just untar the files in this archive and put it in ''apps'' directory in your project, then ''change'' the import statements and add a two lines to the settings.py file: 79 79 80 80 {{{ … … 92 92 93 93 }}} 94 95 96 Have fun.