Andrés Reyes Monge avatar Andrés Reyes Monge committed f9765fa

- Ahora uso ssl para el admin

Comments (0)

Files changed (2)

armonge_info/middleware.py

+# -*- coding: utf-8 -*-
+
+from django.http import HttpResponsePermanentRedirect
+from django.conf import settings
+
+class SecureRequiredMiddleware(object):
+    def __init__(self):
+        self.paths = getattr(settings, 'SECURE_REQUIRED_PATHS')
+        self.enabled = self.paths and getattr(settings, 'HTTPS_SUPPORT')
+
+    def process_request(self, request):
+        if self.enabled and not request.is_secure():
+            for path in self.paths:
+                if request.get_full_path().startswith(path):
+                    request_url = request.build_absolute_uri(request.get_full_path())
+                    secure_url = request_url.replace('http://', 'https://')
+                    return HttpResponsePermanentRedirect(secure_url)
+        return None

armonge_info/settings/settings.py

     'django.contrib.messages.middleware.MessageMiddleware',
     # Uncomment the next line for simple clickjacking protection:
     # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
+    'armonge_info.middleware.SecureRequiredMiddleware',
+
 )
 
 ROOT_URLCONF = 'armonge_info.urls'
 
 MARKITUP_FILTER = ('armonge_info.utils.markup_filter', {})
 MARKITUP_SET = 'markitup/sets/markdown'
+
+
+HTTPS_SUPPORT = True
+SECURE_REQUIRED_PATHS = (
+    '/admin/',
+ )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.