diff options
-rw-r--r-- | wqflask/wqflask/templates/base.html | 2 | ||||
-rw-r--r-- | wqflask/wqflask/user_manager.py | 3 | ||||
-rw-r--r-- | wqflask/wqflask/user_session.py | 21 | ||||
-rw-r--r-- | wqflask/wqflask/views.py | 1 |
4 files changed, 18 insertions, 9 deletions
diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html index 487cf3f2..abe14831 100644 --- a/wqflask/wqflask/templates/base.html +++ b/wqflask/wqflask/templates/base.html @@ -72,6 +72,7 @@ <li><a href="httP://datafiles.genenetwork.org">Interplanetary File System</a></li> </ul> </li> + {% if g.user_session %} <li class=""> <a href="/collections/list">Collections <span class="badge badge-info">{{ g.user_session.num_collections }}</span> @@ -93,6 +94,7 @@ <a id="login_in" href="/n/login">Sign in</a> {% endif %} </li> + {% endif %} <!-- <li style="margin-left: 20px;"> <a href="http://gn2-staging.genenetwork.org" style="font-weight: bold;" >Use Staging Branch</a> diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py index 1b27d7cb..ce76e0e8 100644 --- a/wqflask/wqflask/user_manager.py +++ b/wqflask/wqflask/user_manager.py @@ -351,7 +351,8 @@ class UserSession(object): logger.debug("At end of delete_session") @app.before_request -def before_request(): +def get_cookie(): + logger.info("@app.before_request get cookie") g.user_session = UserSession() g.cookie_session = AnonUser() diff --git a/wqflask/wqflask/user_session.py b/wqflask/wqflask/user_session.py index fd1779fb..4c2305ba 100644 --- a/wqflask/wqflask/user_session.py +++ b/wqflask/wqflask/user_session.py @@ -25,6 +25,19 @@ logger = getLogger(__name__) THREE_DAYS = 60 * 60 * 24 * 3 THIRTY_DAYS = 60 * 60 * 24 * 30 +@app.before_request +def get_user_session(): + logger.info("@app.before_request get_session") + g.user_session = UserSession() + +@app.after_request +def set_user_session(response): + if hasattr(g, 'user_session'): + if not request.cookies.get(g.user_session.cookie_name): + response.set_cookie(g.user_session.cookie_name, g.user_session.cookie) + return response + + def verify_cookie(cookie): the_uuid, separator, the_signature = cookie.partition(':') assert len(the_uuid) == 36, "Is session_id a uuid?" @@ -280,12 +293,4 @@ class UserSession(object): Redis.delete(self.redis_key) self.logged_in = False -@app.before_request -def before_request(): - g.user_session = UserSession() -@app.after_request -def set_cookie(response): - if not request.cookies.get(g.user_session.cookie_name): - response.set_cookie(g.user_session.cookie_name, g.user_session.cookie) - return response
\ No newline at end of file diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 76857650..ef295b5b 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -80,6 +80,7 @@ logger = utility.logger.getLogger(__name__ ) @app.before_request def connect_db(): + logger.info("@app.before_request connect_db") db = getattr(g, '_database', None) if db is None: logger.debug("Get new database connector") |