Permalink
Browse files

Auth(secure=True), thanks Yarin and Niphlod

  • Loading branch information...
1 parent f501da7 commit dc51abe54c123b34d49969fabaa9441e6a4d5c7c @mdipierro mdipierro committed Oct 4, 2012
Showing with 10 additions and 4 deletions.
  1. +1 −1 VERSION
  2. +5 −2 gluon/main.py
  3. +4 −1 gluon/tools.py
View
@@ -1 +1 @@
-Version 2.0.9 (2012-10-04 15:06:45) dev
+Version 2.0.9 (2012-10-04 15:12:44) dev
View
@@ -123,6 +123,8 @@
load()
+HTTPS_SCHEMES = set(('https','HTTPS'))
+
def get_client(env):
"""
guess the client address from the environment variables
@@ -445,8 +447,9 @@ def wsgibase(environ, responder):
ajax = x_req_with == 'xmlhttprequest',
cid = env.http_web2py_component_element,
is_local = env.remote_addr in local_hosts,
- is_https = env.wsgi_url_scheme \
- in ['https', 'HTTPS'] or env.https=='on')
+ is_https = env.wsgi_url_scheme in HTTPS_SCHEMES \
+ or request.env.http_x_forwarded_proto in HTTPS_SCHEMES \
+ or env.https=='on')
request.uuid = request.compute_uuid() # requires client
request.url = environ['PATH_INFO']
View
@@ -1050,7 +1050,7 @@ def here(self):
def __init__(self, environment=None, db=None, mailer=True,
hmac_key=None, controller='default', function='user',
- cas_provider=None, signature=True):
+ cas_provider=None, signature=True, secure=False):
"""
auth=Auth(db)
@@ -1070,6 +1070,9 @@ def __init__(self, environment=None, db=None, mailer=True,
session = current.session
auth = session.auth
self.user_groups = auth and auth.user_groups or {}
+ if secure and not request.is_https:
+ session.secure()
+ redirect(URL(args=request.args,vars=request.vars,scheme='http'))
if auth and auth.last_visit and auth.last_visit + \
datetime.timedelta(days=0, seconds=auth.expiration) > request.now:
self.user = auth.user

0 comments on commit dc51abe

Please sign in to comment.