diff options
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/static/new/javascript/marker_regression.coffee | 7 | ||||
-rw-r--r-- | wqflask/wqflask/templates/collections/add_anonymous.html | 5 | ||||
-rw-r--r-- | wqflask/wqflask/user_manager.py | 38 |
3 files changed, 36 insertions, 14 deletions
diff --git a/wqflask/wqflask/static/new/javascript/marker_regression.coffee b/wqflask/wqflask/static/new/javascript/marker_regression.coffee index 3f8fbe0d..091dab93 100644 --- a/wqflask/wqflask/static/new/javascript/marker_regression.coffee +++ b/wqflask/wqflask/static/new/javascript/marker_regression.coffee @@ -253,9 +253,8 @@ class Manhattan_Plot .attr("transform", (d) => return "translate(-12,0) rotate(-90)" ) - #.attr("dy", "-1.0em") - - + #.attr("dy", "-1.0em") + add_y_axis: () -> @yAxis = d3.svg.axis() .scale(@y_scale) @@ -266,7 +265,7 @@ class Manhattan_Plot .attr("class", "y_axis") .attr("transform", "translate(" + @x_buffer + ",0)") .call(@yAxis) - + add_axis_labels: () -> @svg.append("text") .attr("transform","rotate(-90)") diff --git a/wqflask/wqflask/templates/collections/add_anonymous.html b/wqflask/wqflask/templates/collections/add_anonymous.html index 9259f667..2eb7525f 100644 --- a/wqflask/wqflask/templates/collections/add_anonymous.html +++ b/wqflask/wqflask/templates/collections/add_anonymous.html @@ -10,9 +10,8 @@ <div class="modal-body"> <form action="/collections/new" data-validate="parsley" id="add_form"> <input type="hidden" name="traits" value="{{ traits }}" /> - <button type="submit" name="Default" class="btn btn-large btn-block btn-primary">Continue without signing in</button> - <button type="submit" name="create_new" class="btn btn-large btn-block">Sign in or create an account</button> - + <button type="submit" name="anonymous_add" class="btn btn-large btn-block btn-primary">Continue without signing in</button> + <button type="submit" name="sign_in" class="btn btn-large btn-block">Sign in or create an account</button> </form> </div> </div> diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py index ff4535bb..a80dff3b 100644 --- a/wqflask/wqflask/user_manager.py +++ b/wqflask/wqflask/user_manager.py @@ -44,7 +44,7 @@ from wqflask.database import db_session from wqflask import model -from utility import Bunch, Struct +from utility import Bunch, Struct, after @@ -57,8 +57,34 @@ def timestamp(): return datetime.datetime.utcnow().isoformat() +class AnonUser(object): + cookie_name = 'anon_user_v1' + + def __init__(self): + self.cookie = request.cookies.get(self.cookie_name) + if self.cookie: + self.anon_id = verify_cookie(cookie) + else: + self.anon_id, self.cookie = create_signed_cookie() + after.set_cookie(self.cookie_name, self.cookie) + + + +def verify_cookie(cookie): + the_uuid, separator, the_signature = cookie.partition(':') + assert len(the_uuid) == 36, "Is session_id a uuid?" + assert separator == ":", "Expected a : here" + assert the_signature == actual_hmac_creation(the_uuid), "Uh-oh, someone tampering with the cookie?" + return the_uuid +def create_signed_cookie(): + the_uuid = str(uuid.uuid4()) + signature = actual_hmac_creation(the_uuid) + uuid_signed = the_id + ":" + signature + print("uuid_signed:", uuid_signed) + return the_uuid, uuid_signed + class UserSession(object): cookie_name = 'session_id_v2' @@ -68,10 +94,8 @@ class UserSession(object): self.logged_in = False return else: - session_id, separator, session_id_signature = cookie.partition(':') - assert len(session_id) == 36, "Is session_id a uuid?" - assert separator == ":", "Expected a : here" - assert session_id_signature == actual_hmac_creation(session_id), "Uh-oh, someone tampering with the cookie?" + session_id = verify_cookie(cookie) + self.redis_key = self.cookie_name + ":" + session_id print("self.redis_key is:", self.redis_key) self.session_id = session_id @@ -90,8 +114,8 @@ class UserSession(object): #flash( # "Due to inactivity your session has expired. If you'd like please login again.") #return response - return - + return + if Redis.ttl(self.redis_key) < THREE_DAYS: # (Almost) everytime the user does something we extend the session_id in Redis... print("Extending ttl...") |