diff options
author | zsloan | 2020-01-23 11:08:27 -0600 |
---|---|---|
committer | zsloan | 2020-01-23 11:08:27 -0600 |
commit | 81afc6fd60d2b267c9041835a93088f7a5e4c3c4 (patch) | |
tree | 3f2a83754100c15e2bed2c15b715acc1b690b45d /wqflask | |
parent | 1295aa5f56cf9b2cfc6b61afc324b7a13fac5a07 (diff) | |
download | genenetwork2-81afc6fd60d2b267c9041835a93088f7a5e4c3c4.tar.gz |
Forgot to commit new file containing Redis functions
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/utility/redis_tools.py | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/wqflask/utility/redis_tools.py b/wqflask/utility/redis_tools.py new file mode 100644 index 00000000..ffd263e8 --- /dev/null +++ b/wqflask/utility/redis_tools.py @@ -0,0 +1,73 @@ +from __future__ import print_function, division, absolute_import
+
+import simplejson as json
+
+import redis # used for collections
+Redis = redis.StrictRedis()
+
+import logging
+
+from flask import (render_template, flash)
+
+from utility.logger import getLogger
+logger = getLogger(__name__)
+
+def get_user_id(column_name, column_value):
+ user_list = Redis.hgetall("users")
+ for key in user_list:
+ user_ob = json.loads(user_list[key])
+ if user_ob[column_name] == column_value:
+ return key
+
+ return None
+
+def get_user_by_unique_column(column_name, column_value):
+ item_details = None
+
+ user_list = Redis.hgetall("users")
+ if column_name != "user_id":
+ for key in user_list:
+ user_ob = json.loads(user_list[key])
+ if user_ob[column_name] == column_value:
+ item_details = user_ob
+ else:
+ item_details = json.loads(user_list[column_value])
+
+ return item_details
+
+def set_user_attribute(user_id, column_name, column_value):
+ user_info = json.loads(Redis.hget("users", user_id))
+ user_info[column_name] = column_value
+
+ Redis.hset("users", user_id, json.dumps(user_info))
+
+def get_user_collections(user_id):
+ collections = None
+ collections = Redis.hget("collections", user_id)
+
+ if collections:
+ return json.loads(collections)
+ else:
+ return []
+
+def save_user(user, user_id):
+ Redis.hset("users", user_id, json.dumps(user))
+
+def save_collections(user_id, collections_ob):
+ Redis.hset("collections", user_id, collections_ob)
+
+def save_verification_code(user_email, code):
+ Redis.hset("verification_codes", code, user_email)
+
+def check_verification_code(code):
+ email_address = None
+ user_details = None
+ email_address = Redis.hget("verification_codes", code)
+ return email_address
+
+ if email_address:
+ user_details = get_user_by_unique_column('email_address', email_address)
+ return user_details
+ else:
+ return None
+ #flash("Invalid code: Password reset code does not exist or might have expired!", "error")
|