소스 검색

Support HTTPS based redirects.

Michael Hope 2 년 전
부모
커밋
b99a317835
1개의 변경된 파일14개의 추가작업 그리고 2개의 파일을 삭제
  1. 14 2
      niche.py

+ 14 - 2
niche.py 파일 보기

@@ -77,7 +77,6 @@ DEFAULTS = [
77 77
     ('general', {
78 78
             'dateformat': '%B %d, %Y',
79 79
             'base': '/',
80
-            'domain': None,
81 80
             'has_https': False,
82 81
             'extra_tags': '',
83 82
             'limit': 20,
@@ -455,6 +454,9 @@ class Model:
455 454
 
456 455
         return first_or_none('user', 'userID', id)
457 456
 
457
+    def is_active(self):
458
+        return session.get('userID', None) is not None
459
+
458 460
     def paginate(self, offset, total, per_page):
459 461
         # TODO(michaelh): really a helper, not part of the model.
460 462
         page = 1 + offset // per_page
@@ -612,7 +614,17 @@ def url_validator(v):
612 614
 
613 615
 def redirect(url):
614 616
     """Bounce to a different site absolute URL."""
615
-    raise web.seeother(url)
617
+    has_https = config.get('general', 'has_https')
618
+    if has_https and model.is_active():
619
+        base = config.get('general', 'base')
620
+        if base.endswith('/') and url.startswith('/'):
621
+            path = base[:-1] + url
622
+        else:
623
+            path = base + url
624
+
625
+        raise web.seeother('https://{host}{path}'.format(host=web.ctx.host, path=path), absolute=True)
626
+    else:
627
+        raise web.seeother(url)
616 628
 
617 629
 
618 630
 def authenticate(msg=_("Login required")):