aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorzsloan2016-08-11 20:25:47 +0000
committerzsloan2016-08-11 20:25:47 +0000
commit76a5fba80bba30df35fb0cee4ceb414312a1ea5a (patch)
treeef6a72af92f7f086a0e9952fc73e60ce235014ee /wqflask
parentb37f5cc857849a29ea13825b96fbb8ea7c24a807 (diff)
downloadgenenetwork2-76a5fba80bba30df35fb0cee4ceb414312a1ea5a.tar.gz
Added prompt when user logs in that lets them choose to import existing anonymous collections as user collections
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/model.py2
-rw-r--r--wqflask/wqflask/templates/new_security/login_user.html13
-rw-r--r--wqflask/wqflask/user_manager.py25
-rw-r--r--wqflask/wqflask/views.py5
4 files changed, 40 insertions, 5 deletions
diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py
index 3b480e0c..17343186 100644
--- a/wqflask/wqflask/model.py
+++ b/wqflask/wqflask/model.py
@@ -83,7 +83,7 @@ class User(Base):
def get_collection_by_name(self, collection_name):
try:
- collect = self.user_collections.filter_by(name=collection_name).one()
+ collect = self.user_collections.filter_by(name=collection_name).first()
except sqlalchemy.orm.exc.NoResultFound:
collect = None
return collect
diff --git a/wqflask/wqflask/templates/new_security/login_user.html b/wqflask/wqflask/templates/new_security/login_user.html
index e9dd4ab1..9e5942cd 100644
--- a/wqflask/wqflask/templates/new_security/login_user.html
+++ b/wqflask/wqflask/templates/new_security/login_user.html
@@ -54,6 +54,7 @@
<label class="col-xs-1 control-label" for="submit"></label>
<div style="margin-left:20px;" class="col-xs-4 controls">
<input id="next" name="next" type="hidden" value="">
+ <input id="import_collections" name="import_collections" type="hidden" value="false">
<input class="btn btn-primary" id="submit" name="submit" type="submit" value="Sign in">
</div>
</div>
@@ -99,6 +100,18 @@ label.error,div.error{
}
});
});
+
+ $("input[name=submit]").on("click", function() {
+ import_collections = confirm("Would you like to import existing collections?")
+ if (import_collections == true) {
+ $("input[name=import_collections]").val("true");
+ }
+ else {
+ $("input[name=import_collections]").val("false");
+ }
+ $("#loginUserForm").submit();
+ });
+
</script>
{% include "new_security/_scripts.html" %}
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index 4ff3e79c..64fa82c1 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -118,6 +118,20 @@ class AnonUser(object):
collection['changed_timestamp'] = datetime.datetime.strptime(collection['changed_timestamp'], '%b %d %Y %I:%M%p')
return collections
+ def import_traits_to_user(self):
+ collections_list = json.loads(Redis.get(self.key))
+ for collection in collections_list:
+ uc = model.UserCollection()
+ uc.name = collection['name']
+ collection_exists = g.user_session.user_ob.get_collection_by_name(uc.name)
+ if collection_exists:
+ continue
+ else:
+ uc.user = g.user_session.user_id
+ uc.members = json.dumps(collection['members'])
+ db_session.add(uc)
+ db_session.commit()
+
def display_num_collections(self):
"""
Returns the number of collections or a blank string if there are zero.
@@ -524,7 +538,10 @@ class LoginUser(object):
logger.debug("I will remember you")
self.remember_me = True
- return self.actual_login(user)
+ import_col = params['import_collections']
+ #g.cookie_session.import_traits_to_user()
+
+ return self.actual_login(user, import_collections=import_col)
else:
if user:
@@ -534,16 +551,16 @@ class LoginUser(object):
return response
- def actual_login(self, user, assumed_by=None):
+ def actual_login(self, user, assumed_by=None, import_collections=None):
"""The meat of the logging in process"""
session_id_signed = self.successful_login(user, assumed_by)
flash("Thank you for logging in {}.".format(user.full_name), "alert-success")
- response = make_response(redirect(url_for('index_page')))
+ print("IMPORT1:", import_collections)
+ response = make_response(redirect(url_for('index_page', import_collections=import_collections)))
if self.remember_me:
max_age = self.remember_time
else:
max_age = None
-
response.set_cookie(UserSession.cookie_name, session_id_signed, max_age=max_age)
return response
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 70e465d1..63dceb42 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -84,6 +84,11 @@ def shutdown_session(exception=None):
@app.route("/")
def index_page():
logger.info("Sending index_page")
+ params = request.args
+ if 'import_collections' in params:
+ import_collections = params['import_collections']
+ if import_collections == "true":
+ g.cookie_session.import_traits_to_user()
if USE_GN_SERVER:
# The menu is generated using GN_SERVER
return render_template("index_page.html", gn_server_url = GN_SERVER_URL)