From a9c9de15c395b1e49244c6063c9c1cb204e450da Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Wed, 10 Jan 2018 15:05:03 +0300
Subject: Add configuration variables for external services
* Add configuration variables for GitHub and ORCID which will be used by
the system to allow users to login.
---
wqflask/utility/tools.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 57f97a81..d2e689a4 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -251,6 +251,10 @@ assert_dir(JS_GUIX_PATH)
JS_GN_PATH = get_setting('JS_GN_PATH')
# assert_dir(JS_GN_PATH)
+GITHUB_AUTH_URL = get_setting('GITHUB_AUTH_URL')
+ORCID_AUTH_URL = get_setting('ORCID_AUTH_URL')
+ORCID_TOKEN_URL = get_setting('ORCID_TOKEN_URL')
+
PYLMM_COMMAND = app_set("PYLMM_COMMAND",pylmm_command())
GEMMA_COMMAND = app_set("GEMMA_COMMAND",gemma_command())
PLINK_COMMAND = app_set("PLINK_COMMAND",plink_command())
--
cgit v1.2.3
From b4e4ca152256e1f1f06359d584034554db06402e Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Wed, 10 Jan 2018 15:07:11 +0300
Subject: Add template elements for OAuth login
* Add html elements that will be used to prompt users to login with
either GitHub or ORCID.
---
wqflask/wqflask/templates/new_security/login_user.html | 18 ++++++++++++++++--
wqflask/wqflask/user_manager.py | 9 ++++++++-
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/wqflask/wqflask/templates/new_security/login_user.html b/wqflask/wqflask/templates/new_security/login_user.html
index b9f49a61..15f0a27e 100644
--- a/wqflask/wqflask/templates/new_security/login_user.html
+++ b/wqflask/wqflask/templates/new_security/login_user.html
@@ -18,8 +18,22 @@
Create a new account
-
-
+
+ Login with external services
+
+ {% if external_login: %}
+
+
+
+ {% endif %}
Already have an account? Sign in here.
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index f7fcd2d0..25833464 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -506,7 +506,14 @@ class LoginUser(object):
params = request.form if request.form else request.args
logger.debug("in login params are:", params)
if not params:
- return render_template("new_security/login_user.html")
+ from utility.tools import GITHUB_AUTH_URL, ORCID_AUTH_URL
+ external_login = None
+ if GITHUB_AUTH_URL or ORCID_AUTH_URL:
+ external_login={
+ "github": GITHUB_AUTH_URL,
+ "orcid": ORCID_AUTH_URL
+ }
+ return render_template("new_security/login_user.html", external_login=external_login)
else:
try:
user = model.User.query.filter_by(email_address=params['email_address']).one()
--
cgit v1.2.3
From 76299c30c265919fd4025e11017b687c2b63fd82 Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Fri, 12 Jan 2018 18:01:11 +0300
Subject: Add client_id and client_secret configurations
* Provide the OAuth2 client_id and client_secret values in configuration
variables.
---
wqflask/utility/tools.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index d2e689a4..310b4cea 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -251,7 +251,11 @@ assert_dir(JS_GUIX_PATH)
JS_GN_PATH = get_setting('JS_GN_PATH')
# assert_dir(JS_GN_PATH)
+GITHUB_CLIENT_ID = get_setting('GITHUB_CLIENT_ID')
+GITHUB_CLIENT_SECRET = get_setting('GITHUB_CLIENT_SECRET')
GITHUB_AUTH_URL = get_setting('GITHUB_AUTH_URL')
+ORCID_CLIENT_ID = get_setting('ORCID_CLIENT_ID')
+ORCID_CLIENT_SECRET = get_setting('ORCID_CLIENT_SECRET')
ORCID_AUTH_URL = get_setting('ORCID_AUTH_URL')
ORCID_TOKEN_URL = get_setting('ORCID_TOKEN_URL')
--
cgit v1.2.3
From 3e70cab812e29e504f714c782c71bc4b79793686 Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Fri, 12 Jan 2018 18:05:45 +0300
Subject: Add elasticsearch_tools module
* Collect variables and functions for using the elasticsearch system in
a separate module.
---
wqflask/utility/elasticsearch_tools.py | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 wqflask/utility/elasticsearch_tools.py
diff --git a/wqflask/utility/elasticsearch_tools.py b/wqflask/utility/elasticsearch_tools.py
new file mode 100644
index 00000000..bc7bb240
--- /dev/null
+++ b/wqflask/utility/elasticsearch_tools.py
@@ -0,0 +1,22 @@
+from elasticsearch import Elasticsearch, TransportError
+from utility.tools import ELASTICSEARCH_HOST, ELASTICSEARCH_PORT
+
+es = Elasticsearch([{
+ "host": ELASTICSEARCH_HOST
+ , "port": ELASTICSEARCH_PORT
+}])
+
+def get_user_by_unique_column(column_name, column_value):
+ user_details = None
+ try:
+ response = es.search(
+ index = "users"
+ , doc_type = "local"
+ , body = {
+ "query": { "match": { column_name: column_value } }
+ })
+ if len(response["hits"]["hits"]) > 0:
+ user_details = response["hits"]["hits"][0]["_source"]
+ except TransportError as te:
+ pass
+ return user_details
--
cgit v1.2.3
From 7004c0ee5e86bfb7ebe491356ca3210d2dc2b67b Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Fri, 12 Jan 2018 18:07:13 +0300
Subject: Add functions to help handle github login
* Add functions to help with the github OAuth2 login process
---
wqflask/wqflask/user_manager.py | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index 25833464..9012c842 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -494,6 +494,37 @@ def login():
lu = LoginUser()
return lu.standard_login()
+@app.route("/n/login/github_oauth2", methods=('GET', 'POST'))
+def github_oauth2():
+ from utility.tools import GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET
+ from utility.elasticsearch_tools import get_user_by_unique_column
+ import requests
+ code = request.args.get("code")
+ data = {
+ "client_id": GITHUB_CLIENT_ID,
+ "client_secret": GITHUB_CLIENT_SECRET,
+ "code": code
+ }
+ result = requests.post("https://github.com/login/oauth/access_token", json=data)
+ result_dict = {arr[0]:arr[1] for arr in [tok.split("=") for tok in [token.encode("utf-8") for token in result.text.split("&")]]}
+
+ github_user = get_github_user_details(result_dict["access_token"])
+ user_details = get_user_by_unique_column("github_id", github_user["id"])
+ if user_details == None:
+ user_details = {
+ "user_id": str(uuid4())
+ , "name": github_user["name"]
+ , "github_id": github_user["id"]
+ , "user_url": github_user["html_url"]
+ , "login_type": "github"
+ }
+ url = "/n/login?type=github"
+ return redirect(url)
+
+def get_github_user_details(access_token):
+ from utility.tools import GITHUB_API_URL
+ result = requests.get(GITHUB_API_URL, params={"access_token":access_token})
+ return result.json()
class LoginUser(object):
remember_time = 60 * 60 * 24 * 30 # One month in seconds
--
cgit v1.2.3
From 63a5c8a42ad02e9126bb207465ff5eca98f6515d Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Fri, 19 Jan 2018 10:36:19 +0300
Subject: Add elasticsearch module to the path
* Add some code to set up the path for the python-elasticsearch module.
---
bin/genenetwork2 | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/bin/genenetwork2 b/bin/genenetwork2
index a7edb1c2..ccd9b1d9 100755
--- a/bin/genenetwork2
+++ b/bin/genenetwork2
@@ -61,6 +61,11 @@ export WQFLASK_OVERRIDES=$overrides # JSON
echo WQFLASK_SETTINGS=$settings
echo WQFLASK_OVERRIDES=$overrides
+if [ -z $ELASTICSEARCH_PROFILE ]; then
+ echo -e "\033[1;33mWARNING: Elastic Search profile has not been set - use ELASTICSEARCH_PROFILE\033[0m";
+else
+ PYTHONPATH="$PYTHONPATH${PYTHONPATH:+:}$ELASTICSEARCH_PROFILE/lib/python2.7/site-packages"
+fi
if [ -z $GN2_PROFILE ] ; then
echo "WARNING: GN2_PROFILE has not been set - you need the environment, so I hope you know what you are doing!"
export GN2_PROFILE=$(dirname $(dirname $(which genenetwork2)))
@@ -72,7 +77,7 @@ if [ -z $GN2_PROFILE ]; then
read -p "PRESS [ENTER] TO CONTINUE..."
else
export PATH=$GN2_PROFILE/bin:$PATH
- export PYTHONPATH=$GN2_PROFILE/lib/python2.7/site-packages
+ export PYTHONPATH="$GN2_PROFILE/lib/python2.7/site-packages${PYTHONPATH:+:}$PYTHONPATH"
export R_LIBS_SITE=$GN2_PROFILE/site-library
export GEM_PATH=$GN2_PROFILE/lib/ruby/gems/2.4.0
export JS_GUIX_PATH=$GN2_PROFILE/share/genenetwork2/javascript
--
cgit v1.2.3
From 7282e0b47c1c6d12fc4c06a080af07c8e67ca75c Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Fri, 19 Jan 2018 10:38:04 +0300
Subject: Add save_user() function
* On successful login via OAuth2, save the details of the user in
elasticsearch store, to avoid hitting the external provider for the
basic details.
---
wqflask/utility/elasticsearch_tools.py | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/wqflask/utility/elasticsearch_tools.py b/wqflask/utility/elasticsearch_tools.py
index bc7bb240..74db489b 100644
--- a/wqflask/utility/elasticsearch_tools.py
+++ b/wqflask/utility/elasticsearch_tools.py
@@ -20,3 +20,10 @@ def get_user_by_unique_column(column_name, column_value):
except TransportError as te:
pass
return user_details
+
+def save_user(user, user_id, index="users", doc_type="local"):
+ es = Elasticsearch([{
+ "host": ELASTICSEARCH_HOST
+ , "port": ELASTICSEARCH_PORT
+ }])
+ es.create(index, doc_type, body=user, id=user_id)
--
cgit v1.2.3
From 4ae020160a9ae9c399fe338c9415897b26425201 Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Fri, 19 Jan 2018 10:41:41 +0300
Subject: Add more configuration variables.
* Add configurations for elasticsearch and github.
---
wqflask/utility/tools.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 310b4cea..df066e67 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -254,11 +254,15 @@ JS_GN_PATH = get_setting('JS_GN_PATH')
GITHUB_CLIENT_ID = get_setting('GITHUB_CLIENT_ID')
GITHUB_CLIENT_SECRET = get_setting('GITHUB_CLIENT_SECRET')
GITHUB_AUTH_URL = get_setting('GITHUB_AUTH_URL')
+GITHUB_API_URL = get_setting('GITHUB_API_URL')
ORCID_CLIENT_ID = get_setting('ORCID_CLIENT_ID')
ORCID_CLIENT_SECRET = get_setting('ORCID_CLIENT_SECRET')
ORCID_AUTH_URL = get_setting('ORCID_AUTH_URL')
ORCID_TOKEN_URL = get_setting('ORCID_TOKEN_URL')
+ELASTICSEARCH_HOST = get_setting('ELASTICSEARCH_HOST')
+ELASTICSEARCH_PORT = get_setting('ELASTICSEARCH_PORT')
+
PYLMM_COMMAND = app_set("PYLMM_COMMAND",pylmm_command())
GEMMA_COMMAND = app_set("GEMMA_COMMAND",gemma_command())
PLINK_COMMAND = app_set("PLINK_COMMAND",plink_command())
--
cgit v1.2.3
From e185fd3895473e86f2c9fdf174a36b1d325a8c36 Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Fri, 19 Jan 2018 12:00:04 +0300
Subject: Delay after save for indexing
* Elasticsearch need a short delay after adding document for it to index
the document for subsequent access.
---
wqflask/utility/elasticsearch_tools.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/wqflask/utility/elasticsearch_tools.py b/wqflask/utility/elasticsearch_tools.py
index 74db489b..c2c999ea 100644
--- a/wqflask/utility/elasticsearch_tools.py
+++ b/wqflask/utility/elasticsearch_tools.py
@@ -22,8 +22,10 @@ def get_user_by_unique_column(column_name, column_value):
return user_details
def save_user(user, user_id, index="users", doc_type="local"):
+ from time import sleep
es = Elasticsearch([{
"host": ELASTICSEARCH_HOST
, "port": ELASTICSEARCH_PORT
}])
es.create(index, doc_type, body=user, id=user_id)
+ sleep(1) # Delay 1 second to allow indexing
--
cgit v1.2.3
From 2e7335182e55b22e9c61eef111e00f119760d365 Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Fri, 19 Jan 2018 12:03:10 +0300
Subject: Add code to enable OAuth2 login
* Add some code to handle the login if the user chooses to login via
GitHub or ORCID.
---
wqflask/wqflask/user_manager.py | 58 +++++++++++++++++++++++++++++++++++++----
1 file changed, 53 insertions(+), 5 deletions(-)
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index 9012c842..daeb7bc5 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -54,6 +54,9 @@ logger = getLogger(__name__)
from base.data_set import create_datasets_list
+import requests
+from utility.elasticsearch_tools import get_user_by_unique_column, save_user
+
THREE_DAYS = 60 * 60 * 24 * 3
#THREE_DAYS = 45
@@ -492,13 +495,16 @@ class DecodeUser(object):
@app.route("/n/login", methods=('GET', 'POST'))
def login():
lu = LoginUser()
- return lu.standard_login()
+ login_type = request.args.get("type")
+ if login_type:
+ uid = request.args.get("uid")
+ return lu.oauth2_login(login_type, uid)
+ else:
+ return lu.standard_login()
@app.route("/n/login/github_oauth2", methods=('GET', 'POST'))
def github_oauth2():
from utility.tools import GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET
- from utility.elasticsearch_tools import get_user_by_unique_column
- import requests
code = request.args.get("code")
data = {
"client_id": GITHUB_CLIENT_ID,
@@ -512,13 +518,15 @@ def github_oauth2():
user_details = get_user_by_unique_column("github_id", github_user["id"])
if user_details == None:
user_details = {
- "user_id": str(uuid4())
+ "user_id": str(uuid.uuid4())
, "name": github_user["name"]
, "github_id": github_user["id"]
, "user_url": github_user["html_url"]
, "login_type": "github"
+ , "organization": ""
}
- url = "/n/login?type=github"
+ save_user(user_details, user_details.get("user_id"))
+ url = "/n/login?type=github&uid="+user_details["user_id"]
return redirect(url)
def get_github_user_details(access_token):
@@ -532,6 +540,46 @@ class LoginUser(object):
def __init__(self):
self.remember_me = False
+ def oauth2_login(self, login_type, user_id):
+ """Login via an OAuth2 provider"""
+ user_details = get_user_by_unique_column("user_id", user_id)
+ if user_details:
+ user = model.User()
+ user.id = user_details["user_id"]
+ user.full_name = user_details["name"]
+ user.login_type = user_details["login_type"]
+ return self.actual_login_oauth2(user)
+ else:
+ flash("Error logging in via OAuth2")
+ return make_response(redirect(url_for('login')))
+
+ def actual_login_oauth2(self, user, assumed_by=None, import_collections=None):
+ """The meat of the logging in process"""
+ session_id_signed = self.successful_login_oauth2(user)
+ flash("Thank you for logging in {}.".format(user.full_name), "alert-success")
+ 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
+
+ def successful_login_oauth2(self, user, assumed_by=None):
+ login_rec = model.Login(user)
+ login_rec.successful = True
+ login_rec.session_id = str(uuid.uuid4())
+ login_rec.assumed_by = assumed_by
+ session_id_signature = actual_hmac_creation(login_rec.session_id)
+ session_id_signed = login_rec.session_id + ":" + session_id_signature
+ logger.debug("session_id_signed:", session_id_signed)
+
+ session = dict(login_time = time.time(),
+ user_id = user.id,
+ user_login_type = user.login_type)
+ return session_id_signed
+
def standard_login(self):
"""Login through the normal form"""
params = request.form if request.form else request.args
--
cgit v1.2.3
From d30cbe103946d70b9c61bc48575f23ead1d4048c Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Fri, 19 Jan 2018 13:00:51 +0300
Subject: Update configurations
* Have the authorisation URLs build up from the client id and client
secret values.
---
wqflask/utility/tools.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index df066e67..8a32c9b4 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -253,11 +253,11 @@ JS_GN_PATH = get_setting('JS_GN_PATH')
GITHUB_CLIENT_ID = get_setting('GITHUB_CLIENT_ID')
GITHUB_CLIENT_SECRET = get_setting('GITHUB_CLIENT_SECRET')
-GITHUB_AUTH_URL = get_setting('GITHUB_AUTH_URL')
+GITHUB_AUTH_URL = "https://github.com/login/oauth/authorize?client_id="+GITHUB_CLIENT_ID+"&client_secret="+GITHUB_CLIENT_SECRET
GITHUB_API_URL = get_setting('GITHUB_API_URL')
ORCID_CLIENT_ID = get_setting('ORCID_CLIENT_ID')
ORCID_CLIENT_SECRET = get_setting('ORCID_CLIENT_SECRET')
-ORCID_AUTH_URL = get_setting('ORCID_AUTH_URL')
+ORCID_AUTH_URL = "https://sandbox.orcid.org/oauth/authorize?response_type=code&scope=/authenticate&show_login=true&client_id="+ORCID_CLIENT_ID+"&client_secret="+ORCID_CLIENT_SECRET
ORCID_TOKEN_URL = get_setting('ORCID_TOKEN_URL')
ELASTICSEARCH_HOST = get_setting('ELASTICSEARCH_HOST')
--
cgit v1.2.3
From 03127502a982af308e6cd134e218214f6a156cd8 Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Fri, 19 Jan 2018 13:02:11 +0300
Subject: Add OAuth2 login code for ORCID
* Add code to handle the login via ORCID
---
wqflask/wqflask/user_manager.py | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index daeb7bc5..c3f190c3 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -529,6 +529,40 @@ def github_oauth2():
url = "/n/login?type=github&uid="+user_details["user_id"]
return redirect(url)
+@app.route("/n/login/orcid_oauth2", methods=('GET', 'POST'))
+def orcid_oauth2():
+ from uuid import uuid4
+ from utility.tools import ORCID_CLIENT_ID, ORCID_CLIENT_SECRET, ORCID_TOKEN_URL, ORCID_AUTH_URL
+ code = request.args.get("code")
+ error = request.args.get("error")
+ url = "/n/login"
+ if code:
+ data = {
+ "client_id": ORCID_CLIENT_ID
+ , "client_secret": ORCID_CLIENT_SECRET
+ , "grant_type": "authorization_code"
+ , "code": code
+ }
+ result = requests.post(ORCID_TOKEN_URL, data=data)
+ result_dict = json.loads(result.text.encode("utf-8"))
+ print("The dict: ", result_dict);
+ user_details = get_user_by_unique_column("orcid", result_dict["orcid"])
+ if user_details == None:
+ user_details = {
+ "user_id": str(uuid4())
+ , "name": result_dict["name"]
+ , "orcid": result_dict["orcid"]
+ , "user_url": "%s/%s" % (
+ "/".join(ORCID_AUTH_URL.split("/")[:-2]),
+ result_dict["orcid"])
+ , "login_type": "orcid"
+ }
+ save_user(user_details, user_details["user_id"])
+ url = "/n/login?type=orcid&uid="+user_details["user_id"]
+ else:
+ flash("There was an error getting code from ORCID")
+ return redirect(url)
+
def get_github_user_details(access_token):
from utility.tools import GITHUB_API_URL
result = requests.get(GITHUB_API_URL, params={"access_token":access_token})
--
cgit v1.2.3
From 309eca58943bf94ce80deb91cf83135957d20980 Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Fri, 19 Jan 2018 17:48:43 +0300
Subject: Use elasticsearch rather than mysql for local accounts
* Register local accounts onto elasticsearch rather than mysql.
* Login from the accounts on elasticsearch
* Harmonise local and oauth2 logins to use the same code.
---
wqflask/wqflask/user_manager.py | 106 ++++++++++++++--------------------------
1 file changed, 36 insertions(+), 70 deletions(-)
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index c3f190c3..4322945b 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -272,15 +272,19 @@ class RegisterUser(object):
self.errors = []
self.user = Bunch()
- self.user.email_address = kw.get('email_address', '').strip()
+ self.user.email_address = kw.get('email_address', '').encode("utf-8").strip()
if not (5 <= len(self.user.email_address) <= 50):
self.errors.append('Email Address needs to be between 5 and 50 characters.')
- self.user.full_name = kw.get('full_name', '').strip()
+ email_exists = get_user_by_unique_column("email_address", self.user.email_address)
+ if email_exists:
+ self.errors.append('User already exists with that email')
+
+ self.user.full_name = kw.get('full_name', '').encode("utf-8").strip()
if not (5 <= len(self.user.full_name) <= 50):
self.errors.append('Full Name needs to be between 5 and 50 characters.')
- self.user.organization = kw.get('organization', '').strip()
+ self.user.organization = kw.get('organization', '').encode("utf-8").strip()
if self.user.organization and not (5 <= len(self.user.organization) <= 50):
self.errors.append('Organization needs to be empty or between 5 and 50 characters.')
@@ -297,28 +301,11 @@ class RegisterUser(object):
logger.debug("No errors!")
set_password(password, self.user)
+ self.user.user_id = str(uuid.uuid4())
+ self.user.confirmed = 1
self.user.registration_info = json.dumps(basic_info(), sort_keys=True)
-
- self.new_user = model.User(**self.user.__dict__)
- db_session.add(self.new_user)
-
- try:
- db_session.commit()
- except sqlalchemy.exc.IntegrityError:
- # This exception is thrown if the email address is already in the database
- # To do: Perhaps put a link to sign in using an existing account here
- self.errors.append("An account with this email address already exists. "
- "Click the button above to sign in using an existing account.")
- return
-
- logger.debug("Adding verification email to queue")
- #self.send_email_verification()
- VerificationEmail(self.new_user)
- logger.debug("Added verification email to queue")
-
- self.thank_you_mode = True
-
+ save_user(self.user.__dict__, self.user.user_id)
def set_password(password, user):
pwfields = Bunch()
@@ -364,7 +351,7 @@ class VerificationEmail(object):
verification_code = str(uuid.uuid4())
key = self.key_prefix + ":" + verification_code
- data = json.dumps(dict(id=user.id,
+ data = json.dumps(dict(id=user.user_id,
timestamp=timestamp())
)
@@ -519,13 +506,15 @@ def github_oauth2():
if user_details == None:
user_details = {
"user_id": str(uuid.uuid4())
- , "name": github_user["name"]
+ , "name": github_user["name"].encode("utf-8")
, "github_id": github_user["id"]
- , "user_url": github_user["html_url"]
+ , "user_url": github_user["html_url"].encode("utf-8")
, "login_type": "github"
, "organization": ""
+ , "active": 1
+ , "confirmed": 1
}
- save_user(user_details, user_details.get("user_id"))
+ save_user(user_details, user_details["user_id"])
url = "/n/login?type=github&uid="+user_details["user_id"]
return redirect(url)
@@ -545,7 +534,7 @@ def orcid_oauth2():
}
result = requests.post(ORCID_TOKEN_URL, data=data)
result_dict = json.loads(result.text.encode("utf-8"))
- print("The dict: ", result_dict);
+
user_details = get_user_by_unique_column("orcid", result_dict["orcid"])
if user_details == None:
user_details = {
@@ -556,6 +545,9 @@ def orcid_oauth2():
"/".join(ORCID_AUTH_URL.split("/")[:-2]),
result_dict["orcid"])
, "login_type": "orcid"
+ , "organization": ""
+ , "active": 1
+ , "confirmed": 1
}
save_user(user_details, user_details["user_id"])
url = "/n/login?type=orcid&uid="+user_details["user_id"]
@@ -582,38 +574,11 @@ class LoginUser(object):
user.id = user_details["user_id"]
user.full_name = user_details["name"]
user.login_type = user_details["login_type"]
- return self.actual_login_oauth2(user)
+ return self.actual_login(user)
else:
flash("Error logging in via OAuth2")
return make_response(redirect(url_for('login')))
- def actual_login_oauth2(self, user, assumed_by=None, import_collections=None):
- """The meat of the logging in process"""
- session_id_signed = self.successful_login_oauth2(user)
- flash("Thank you for logging in {}.".format(user.full_name), "alert-success")
- 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
-
- def successful_login_oauth2(self, user, assumed_by=None):
- login_rec = model.Login(user)
- login_rec.successful = True
- login_rec.session_id = str(uuid.uuid4())
- login_rec.assumed_by = assumed_by
- session_id_signature = actual_hmac_creation(login_rec.session_id)
- session_id_signed = login_rec.session_id + ":" + session_id_signature
- logger.debug("session_id_signed:", session_id_signed)
-
- session = dict(login_time = time.time(),
- user_id = user.id,
- user_login_type = user.login_type)
- return session_id_signed
-
def standard_login(self):
"""Login through the normal form"""
params = request.form if request.form else request.args
@@ -628,20 +593,23 @@ class LoginUser(object):
}
return render_template("new_security/login_user.html", external_login=external_login)
else:
- try:
- user = model.User.query.filter_by(email_address=params['email_address']).one()
- except sqlalchemy.orm.exc.NoResultFound:
- logger.debug("No account exists for that email address")
- valid = False
- user = None
- else:
+ user_details = get_user_by_unique_column("email_address", params["email_address"])
+ user = None
+ if user_details:
+ user = model.User();
+ for key in user_details:
+ user.__dict__[key] = user_details[key]
+ print("RETRIEVED USER: ", user)
+ valid = False;
+
submitted_password = params['password']
pwfields = Struct(json.loads(user.password))
- encrypted = Password(submitted_password,
- pwfields.salt,
- pwfields.iterations,
- pwfields.keylength,
- pwfields.hashfunc)
+ encrypted = Password(
+ submitted_password,
+ pwfields.salt,
+ pwfields.iterations,
+ pwfields.keylength,
+ pwfields.hashfunc)
logger.debug("\n\nComparing:\n{}\n{}\n".format(encrypted.password, pwfields.password))
valid = pbkdf2.safe_str_cmp(encrypted.password, pwfields.password)
logger.debug("valid is:", valid)
@@ -709,8 +677,6 @@ class LoginUser(object):
else:
expire_time = THREE_DAYS
Redis.expire(key, expire_time)
- db_session.add(login_rec)
- db_session.commit()
return session_id_signed
def unsuccessful_login(self, user):
--
cgit v1.2.3
From fb0ad54313366a3f0efda3ef20e800d5e52d1d53 Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Tue, 30 Jan 2018 12:23:31 +0300
Subject: Set to None if no value provided
* Add a method to set the configuration variables to None if the
configuration values are not provided at startup or in the
configuration files.
The system already checks for these values, and if they are absent, it
simply fails to display the OAuth service as available for use to
login.
---
wqflask/utility/tools.py | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 8a32c9b4..feeeccfc 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -251,17 +251,28 @@ assert_dir(JS_GUIX_PATH)
JS_GN_PATH = get_setting('JS_GN_PATH')
# assert_dir(JS_GN_PATH)
-GITHUB_CLIENT_ID = get_setting('GITHUB_CLIENT_ID')
-GITHUB_CLIENT_SECRET = get_setting('GITHUB_CLIENT_SECRET')
-GITHUB_AUTH_URL = "https://github.com/login/oauth/authorize?client_id="+GITHUB_CLIENT_ID+"&client_secret="+GITHUB_CLIENT_SECRET
-GITHUB_API_URL = get_setting('GITHUB_API_URL')
-ORCID_CLIENT_ID = get_setting('ORCID_CLIENT_ID')
-ORCID_CLIENT_SECRET = get_setting('ORCID_CLIENT_SECRET')
-ORCID_AUTH_URL = "https://sandbox.orcid.org/oauth/authorize?response_type=code&scope=/authenticate&show_login=true&client_id="+ORCID_CLIENT_ID+"&client_secret="+ORCID_CLIENT_SECRET
-ORCID_TOKEN_URL = get_setting('ORCID_TOKEN_URL')
-
-ELASTICSEARCH_HOST = get_setting('ELASTICSEARCH_HOST')
-ELASTICSEARCH_PORT = get_setting('ELASTICSEARCH_PORT')
+def get_setting_safe(setting):
+ try:
+ return get_setting(setting)
+ except:
+ print("Could not find the setting '", setting, "'. Continuing with value unset")
+ return None
+
+GITHUB_CLIENT_ID = get_setting_safe('GITHUB_CLIENT_ID')
+GITHUB_CLIENT_SECRET = get_setting_safe('GITHUB_CLIENT_SECRET')
+GITHUB_AUTH_URL = None
+if GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET:
+ GITHUB_AUTH_URL = "https://github.com/login/oauth/authorize?client_id="+GITHUB_CLIENT_ID+"&client_secret="+GITHUB_CLIENT_SECRET
+GITHUB_API_URL = get_setting_safe('GITHUB_API_URL')
+ORCID_CLIENT_ID = get_setting_safe('ORCID_CLIENT_ID')
+ORCID_CLIENT_SECRET = get_setting_safe('ORCID_CLIENT_SECRET')
+ORCID_AUTH_URL = None
+if ORCID_CLIENT_ID and ORCID_CLIENT_SECRET:
+ ORCID_AUTH_URL = "https://sandbox.orcid.org/oauth/authorize?response_type=code&scope=/authenticate&show_login=true&client_id="+ORCID_CLIENT_ID+"&client_secret="+ORCID_CLIENT_SECRET
+ORCID_TOKEN_URL = get_setting_safe('ORCID_TOKEN_URL')
+
+ELASTICSEARCH_HOST = get_setting_safe('ELASTICSEARCH_HOST')
+ELASTICSEARCH_PORT = get_setting_safe('ELASTICSEARCH_PORT')
PYLMM_COMMAND = app_set("PYLMM_COMMAND",pylmm_command())
GEMMA_COMMAND = app_set("GEMMA_COMMAND",gemma_command())
--
cgit v1.2.3
From afaea1b1297d0cf08565746799d2900a6981823a Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Tue, 30 Jan 2018 13:07:58 +0300
Subject: Fail safely if elasticsearch is down or unconfigured
* If elasticsearch server is down, or the configuration variables are
not provided at startup or in a configuration file, then do not allow
the system to simply crash, but instead, inform the user that they
cannot use the services that depend on elasticsearch to be running.
---
wqflask/utility/elasticsearch_tools.py | 16 ++++++++------
.../wqflask/templates/new_security/login_user.html | 25 ++++++++++++++++++----
wqflask/wqflask/user_manager.py | 6 +++++-
3 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/wqflask/utility/elasticsearch_tools.py b/wqflask/utility/elasticsearch_tools.py
index c2c999ea..8b8ad9cc 100644
--- a/wqflask/utility/elasticsearch_tools.py
+++ b/wqflask/utility/elasticsearch_tools.py
@@ -1,10 +1,14 @@
-from elasticsearch import Elasticsearch, TransportError
-from utility.tools import ELASTICSEARCH_HOST, ELASTICSEARCH_PORT
+es = None
+try:
+ from elasticsearch import Elasticsearch, TransportError
+ from utility.tools import ELASTICSEARCH_HOST, ELASTICSEARCH_PORT
-es = Elasticsearch([{
- "host": ELASTICSEARCH_HOST
- , "port": ELASTICSEARCH_PORT
-}])
+ es = Elasticsearch([{
+ "host": ELASTICSEARCH_HOST
+ , "port": ELASTICSEARCH_PORT
+ }]) if (ELASTICSEARCH_HOST and ELASTICSEARCH_PORT) else None
+except:
+ es = None
def get_user_by_unique_column(column_name, column_value):
user_details = None
diff --git a/wqflask/wqflask/templates/new_security/login_user.html b/wqflask/wqflask/templates/new_security/login_user.html
index 15f0a27e..0dae3503 100644
--- a/wqflask/wqflask/templates/new_security/login_user.html
+++ b/wqflask/wqflask/templates/new_security/login_user.html
@@ -16,7 +16,14 @@
Don't have an account?
- Create a new account
+ {% if es_server: %}
+ Create a new account
+ {% else: %}
+
+
You cannot create an account at this moment.
+ Please try again later.
+
+ {% endif %}
Login with external services
@@ -31,13 +38,17 @@
Login with ORCID
{% endif %}
-
-
+ {% else: %}
+
+
You cannot login with external services at this time.
+ Please try again later.
+
{% endif %}
+
Already have an account? Sign in here.
-
+ {% if es_server: %}
{% else: %}
-
You cannot login at this moment using your GeneNetwork account.
+
You cannot login at this moment using your GeneNetwork account (the authentication service is down).
Please try again later.
{% endif %}
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index c344ea27..c55649f3 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -626,13 +626,12 @@ class LoginUser(object):
logger.debug("in login params are:", params)
es = get_elasticsearch_connection()
if not params:
- from utility.tools import GITHUB_AUTH_URL, ORCID_AUTH_URL
- external_login = None
- if GITHUB_AUTH_URL or ORCID_AUTH_URL:
- external_login={
- "github": GITHUB_AUTH_URL,
- "orcid": ORCID_AUTH_URL
- }
+ from utility.tools import GITHUB_AUTH_URL, GITHUB_CLIENT_ID, ORCID_AUTH_URL, ORCID_CLIENT_ID
+ external_login = {}
+ if GITHUB_AUTH_URL and GITHUB_CLIENT_ID != 'UNKNOWN':
+ external_login["github"] = GITHUB_AUTH_URL
+ if ORCID_AUTH_URL and ORCID_CLIENT_ID != 'UNKNOWN':
+ external_login["orcid"] = ORCID_AUTH_URL
assert(es is not None)
return render_template(
"new_security/login_user.html"
--
cgit v1.2.3
From ab369995d4a16de5d20123192279e32658f870a0 Mon Sep 17 00:00:00 2001
From: Pjotr Prins
Date: Tue, 20 Mar 2018 09:50:34 +0000
Subject: Fix
---
wqflask/utility/tools.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index ed54f77c..4b4cd633 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -263,7 +263,7 @@ ORCID_CLIENT_ID = get_setting('ORCID_CLIENT_ID')
ORCID_CLIENT_SECRET = get_setting('ORCID_CLIENT_SECRET')
ORCID_AUTH_URL = None
if ORCID_CLIENT_ID != 'UNKNOWN' and ORCID_CLIENT_SECRET:
- ORCID_AUTH_URL = "https://sandbox.orcid.org/oauth/authorize?response_type=code&scope=/authenticate&show_login=true&client_id=" +
+ ORCID_AUTH_URL = "https://sandbox.orcid.org/oauth/authorize?response_type=code&scope=/authenticate&show_login=true&client_id=" + \
ORCID_CLIENT_ID+"&client_secret="+ORCID_CLIENT_SECRET
ORCID_TOKEN_URL = get_setting('ORCID_TOKEN_URL')
--
cgit v1.2.3
From afd8d38c19be78b7e962f4edea0972ac3f48c25d Mon Sep 17 00:00:00 2001
From: Pjotr Prins
Date: Tue, 20 Mar 2018 11:02:25 +0000
Subject: Refactor startup config for gunicorn and werkzeug
---
wqflask/run_gunicorn.py | 6 ++--
wqflask/runserver.py | 17 ++--------
wqflask/utility/elasticsearch_tools.py | 5 +++
wqflask/utility/startup_config.py | 39 ++++++++++++++++++++++
wqflask/utility/tools.py | 4 ++-
.../wqflask/templates/new_security/login_user.html | 8 ++++-
6 files changed, 59 insertions(+), 20 deletions(-)
create mode 100644 wqflask/utility/startup_config.py
diff --git a/wqflask/run_gunicorn.py b/wqflask/run_gunicorn.py
index ebe3add5..adffdca3 100644
--- a/wqflask/run_gunicorn.py
+++ b/wqflask/run_gunicorn.py
@@ -7,12 +7,12 @@
# from flask import Flask
# application = Flask(__name__)
-print "Starting up Gunicorn process"
+print "===> Starting up Gunicorn process"
from wqflask import app
+from utility.startup_config import app_config
-app.config['SESSION_TYPE'] = 'filesystem'
-app.config['SECRET_KEY'] = 'super secret key'
+app_config()
@app.route("/gunicorn")
def hello():
diff --git a/wqflask/runserver.py b/wqflask/runserver.py
index a0c76e51..5f41d04d 100644
--- a/wqflask/runserver.py
+++ b/wqflask/runserver.py
@@ -21,22 +21,9 @@ GREEN = '\033[92m'
BOLD = '\033[1m'
ENDC = '\033[0m'
-import os
-app.config['SECRET_KEY'] = os.urandom(24)
+from utility.startup_config import app_config
-from utility.tools import WEBSERVER_MODE,get_setting_int,get_setting,get_setting_bool
-
-port = get_setting_int("SERVER_PORT")
-
-print("GN2 API server URL is ["+BLUE+get_setting("GN_SERVER_URL")+ENDC+"]")
-
-if get_setting_bool("USE_GN_SERVER"):
- import requests
- page = requests.get(get_setting("GN_SERVER_URL"))
- if page.status_code != 200:
- raise Exception("API server not found!")
-
-print("GN2 is running. Visit %s[http://localhost:%s/%s](%s)" % (BLUE,str(port),ENDC,get_setting("WEBSERVER_URL")))
+app_config()
werkzeug_logger = logging.getLogger('werkzeug')
diff --git a/wqflask/utility/elasticsearch_tools.py b/wqflask/utility/elasticsearch_tools.py
index 2d3d5add..734379f7 100644
--- a/wqflask/utility/elasticsearch_tools.py
+++ b/wqflask/utility/elasticsearch_tools.py
@@ -6,6 +6,11 @@ logger = getLogger(__name__)
from utility.tools import ELASTICSEARCH_HOST, ELASTICSEARCH_PORT
+def test_elasticsearch_connection():
+ es = Elasticsearch(['http://'+ELASTICSEARCH_HOST+":"+ELASTICSEARCH_PORT+'/'], verify_certs=True)
+ if not es.ping():
+ logger.warning("Elasticsearch is DOWN")
+
def get_elasticsearch_connection():
logger.info("get_elasticsearch_connection")
es = None
diff --git a/wqflask/utility/startup_config.py b/wqflask/utility/startup_config.py
new file mode 100644
index 00000000..02e8e56c
--- /dev/null
+++ b/wqflask/utility/startup_config.py
@@ -0,0 +1,39 @@
+
+from wqflask import app
+from utility.tools import WEBSERVER_MODE, show_settings, get_setting_int, get_setting, get_setting_bool
+
+import utility.logger
+logger = utility.logger.getLogger(__name__ )
+
+BLUE = '\033[94m'
+GREEN = '\033[92m'
+BOLD = '\033[1m'
+ENDC = '\033[0m'
+
+def app_config():
+ app.config['SESSION_TYPE'] = 'filesystem'
+ if not app.config.get('SECRET_KEY'):
+ import os
+ app.config['SECRET_KEY'] = str(os.urandom(24))
+
+ mode = WEBSERVER_MODE
+ if mode == "DEV" or mode == "DEBUG":
+ app.config['TEMPLATES_AUTO_RELOAD'] = True
+ if mode == "DEBUG":
+ app.config['EXPLAIN_TEMPLATE_LOADING'] = True
+ print("==========================================")
+ show_settings()
+
+ port = get_setting_int("SERVER_PORT")
+
+ if get_setting_bool("USE_GN_SERVER"):
+ print("GN2 API server URL is ["+BLUE+get_setting("GN_SERVER_URL")+ENDC+"]")
+ import requests
+ page = requests.get(get_setting("GN_SERVER_URL"))
+ if page.status_code != 200:
+ raise Exception("API server not found!")
+
+ import utility.elasticsearch_tools as es
+ es.test_elasticsearch_connection()
+
+ print("GN2 is running. Visit %s[http://localhost:%s/%s](%s)" % (BLUE,str(port),ENDC,get_setting("WEBSERVER_URL")))
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 4b4cd633..59bb49d8 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -220,7 +220,7 @@ def show_settings():
logger.info(OVERRIDES)
logger.info(BLUE+"Mr. Mojo Risin 2"+ENDC)
- print "runserver.py: ****** Webserver configuration ******"
+ print "runserver.py: ****** Webserver configuration - k,v pairs from app.config ******"
keylist = app.config.keys()
keylist.sort()
for k in keylist:
@@ -269,6 +269,8 @@ if ORCID_CLIENT_ID != 'UNKNOWN' and ORCID_CLIENT_SECRET:
ELASTICSEARCH_HOST = get_setting('ELASTICSEARCH_HOST')
ELASTICSEARCH_PORT = get_setting('ELASTICSEARCH_PORT')
+import utility.elasticsearch_tools as es
+es.test_elasticsearch_connection()
SMTP_CONNECT = get_setting('SMTP_CONNECT')
SMTP_USERNAME = get_setting('SMTP_USERNAME')
diff --git a/wqflask/wqflask/templates/new_security/login_user.html b/wqflask/wqflask/templates/new_security/login_user.html
index 6d597f6b..949760b6 100644
--- a/wqflask/wqflask/templates/new_security/login_user.html
+++ b/wqflask/wqflask/templates/new_security/login_user.html
@@ -15,7 +15,6 @@
Don't have an account?
-
{% if es_server: %}
Create a new account
{% else: %}
@@ -92,6 +91,13 @@
Please try again later.
{% endif %}
+ {% if not es_server and not external_login: %}
+
+
+ Note: it is safe to use GeneNetwork without a login. Login is only required for keeping track of
+ collections and getting access to some types of restricted data.
+
+ {% endif %}
--
cgit v1.2.3
From fe08b7773b2903baf80adf97bad9db4317774c2a Mon Sep 17 00:00:00 2001
From: Pjotr Prins
Date: Wed, 21 Mar 2018 10:05:54 +0000
Subject: Skip automatic use of EXPLAIN_TEMPLATE_LOADING.
---
wqflask/utility/startup_config.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/wqflask/utility/startup_config.py b/wqflask/utility/startup_config.py
index 02e8e56c..5a62cc50 100644
--- a/wqflask/utility/startup_config.py
+++ b/wqflask/utility/startup_config.py
@@ -19,8 +19,8 @@ def app_config():
mode = WEBSERVER_MODE
if mode == "DEV" or mode == "DEBUG":
app.config['TEMPLATES_AUTO_RELOAD'] = True
- if mode == "DEBUG":
- app.config['EXPLAIN_TEMPLATE_LOADING'] = True
+ # if mode == "DEBUG":
+ # app.config['EXPLAIN_TEMPLATE_LOADING'] = True <--- use overriding app param instead
print("==========================================")
show_settings()
--
cgit v1.2.3
From c0df4a12d17af0233e525d07eb9e6e341aded298 Mon Sep 17 00:00:00 2001
From: Pjotr Prins
Date: Wed, 21 Mar 2018 10:13:04 +0000
Subject: Use logger.info instead of logger.debug, fixes
https://github.com/genenetwork/genenetwork2/issues/296
---
wqflask/wqflask/views.py | 66 ++++++++++++++++++++++++------------------------
1 file changed, 33 insertions(+), 33 deletions(-)
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 4e81c29c..8476b6c5 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -123,7 +123,7 @@ def handle_bad_request(e):
@app.route("/")
def index_page():
logger.info("Sending index_page")
- logger.error(request.url)
+ logger.info(request.url)
params = request.args
if 'import_collections' in params:
import_collections = params['import_collections']
@@ -141,7 +141,7 @@ def index_page():
def tmp_page(img_path):
logger.info("In tmp_page")
logger.info("img_path:", img_path)
- logger.error(request.url)
+ logger.info(request.url)
initial_start_vars = request.form
logger.info("initial_start_vars:", initial_start_vars)
imgfile = open(GENERATED_IMAGE_DIR + img_path, 'rb')
@@ -174,7 +174,7 @@ def twitter(filename):
@app.route("/search", methods=('GET',))
def search_page():
logger.info("in search_page")
- logger.error(request.url)
+ logger.info(request.url)
if 'info_database' in request.args:
logger.info("Going to sharing_info_page")
template_vars = sharing_info_page()
@@ -213,7 +213,7 @@ def search_page():
@app.route("/gsearch", methods=('GET',))
def gsearchact():
- logger.error(request.url)
+ logger.info(request.url)
result = gsearch.GSearch(request.args).__dict__
type = request.args['type']
if type == "gene":
@@ -224,7 +224,7 @@ def gsearchact():
@app.route("/gsearch_updating", methods=('POST',))
def gsearch_updating():
logger.info("REQUEST ARGS:", request.values)
- logger.error(request.url)
+ logger.info(request.url)
result = update_search_results.GSearch(request.args).__dict__
return result['results']
# type = request.args['type']
@@ -235,31 +235,31 @@ def gsearch_updating():
@app.route("/docedit")
def docedit():
- logger.error(request.url)
+ logger.info(request.url)
doc = docs.Docs(request.args['entry'])
return render_template("docedit.html", **doc.__dict__)
@app.route('/generated/')
def generated_file(filename):
- logger.error(request.url)
+ logger.info(request.url)
return send_from_directory(GENERATED_IMAGE_DIR,filename)
@app.route("/help")
def help():
- logger.error(request.url)
+ logger.info(request.url)
doc = docs.Docs("help")
return render_template("docs.html", **doc.__dict__)
@app.route("/wgcna_setup", methods=('POST',))
def wcgna_setup():
logger.info("In wgcna, request.form is:", request.form) # We are going to get additional user input for the analysis
- logger.error(request.url)
+ logger.info(request.url)
return render_template("wgcna_setup.html", **request.form) # Display them using the template
@app.route("/wgcna_results", methods=('POST',))
def wcgna_results():
logger.info("In wgcna, request.form is:", request.form)
- logger.error(request.url)
+ logger.info(request.url)
wgcna = wgcna_analysis.WGCNA() # Start R, load the package and pointers and create the analysis
wgcnaA = wgcna.run_analysis(request.form) # Start the analysis, a wgcnaA object should be a separate long running thread
result = wgcna.process_results(wgcnaA) # After the analysis is finished store the result
@@ -268,13 +268,13 @@ def wcgna_results():
@app.route("/ctl_setup", methods=('POST',))
def ctl_setup():
logger.info("In ctl, request.form is:", request.form) # We are going to get additional user input for the analysis
- logger.error(request.url)
+ logger.info(request.url)
return render_template("ctl_setup.html", **request.form) # Display them using the template
@app.route("/ctl_results", methods=('POST',))
def ctl_results():
logger.info("In ctl, request.form is:", request.form)
- logger.error(request.url)
+ logger.info(request.url)
ctl = ctl_analysis.CTL() # Start R, load the package and pointers and create the analysis
ctlA = ctl.run_analysis(request.form) # Start the analysis, a ctlA object should be a separate long running thread
result = ctl.process_results(ctlA) # After the analysis is finished store the result
@@ -313,13 +313,13 @@ def environments():
@app.route("/submit_trait")
def submit_trait_form():
- logger.error(request.url)
+ logger.info(request.url)
species_and_groups = get_species_groups()
return render_template("submit_trait.html", **{'species_and_groups' : species_and_groups, 'gn_server_url' : GN_SERVER_URL, 'version' : GN_VERSION})
@app.route("/create_temp_trait", methods=('POST',))
def create_temp_trait():
- logger.error(request.url)
+ logger.info(request.url)
print("REQUEST.FORM:", request.form)
#template_vars = submit_trait.SubmitTrait(request.form)
@@ -332,7 +332,7 @@ def export_trait_excel():
"""Excel file consisting of the sample data from the trait data and analysis page"""
logger.info("In export_trait_excel")
logger.info("request.form:", request.form)
- logger.error(request.url)
+ logger.info(request.url)
sample_data = export_trait_data.export_sample_table(request.form)
logger.info("sample_data - type: %s -- size: %s" % (type(sample_data), len(sample_data)))
@@ -358,7 +358,7 @@ def export_trait_csv():
"""CSV file consisting of the sample data from the trait data and analysis page"""
logger.info("In export_trait_csv")
logger.info("request.form:", request.form)
- logger.error(request.url)
+ logger.info(request.url)
sample_data = export_trait_data.export_sample_table(request.form)
logger.info("sample_data - type: %s -- size: %s" % (type(sample_data), len(sample_data)))
@@ -379,7 +379,7 @@ def export_traits_csv():
"""CSV file consisting of the traits from the search result page"""
logger.info("In export_traits_csv")
logger.info("request.form:", request.form)
- logger.error(request.url)
+ logger.info(request.url)
csv_data = export_traits.export_search_results_csv(request.form)
return Response(csv_data,
@@ -389,7 +389,7 @@ def export_traits_csv():
@app.route('/export_perm_data', methods=('POST',))
def export_perm_data():
"""CSV file consisting of the permutation data for the mapping results"""
- logger.error(request.url)
+ logger.info(request.url)
num_perm = float(request.form['num_perm'])
perm_data = json.loads(request.form['perm_results'])
@@ -412,7 +412,7 @@ def export_perm_data():
@app.route("/show_temp_trait", methods=('POST',))
def show_temp_trait_page():
- logger.error(request.url)
+ logger.info(request.url)
template_vars = show_trait.ShowTrait(request.form)
#logger.info("js_data before dump:", template_vars.js_data)
template_vars.js_data = json.dumps(template_vars.js_data,
@@ -427,7 +427,7 @@ def show_temp_trait_page():
@app.route("/show_trait")
def show_trait_page():
- logger.error(request.url)
+ logger.info(request.url)
template_vars = show_trait.ShowTrait(request.args)
#logger.info("js_data before dump:", template_vars.js_data)
template_vars.js_data = json.dumps(template_vars.js_data,
@@ -443,7 +443,7 @@ def show_trait_page():
@app.route("/heatmap", methods=('POST',))
def heatmap_page():
logger.info("In heatmap, request.form is:", pf(request.form))
- logger.error(request.url)
+ logger.info(request.url)
start_vars = request.form
temp_uuid = uuid.uuid4()
@@ -493,7 +493,7 @@ def mapping_results_container_page():
@app.route("/loading", methods=('POST',))
def loading_page():
- logger.error(request.url)
+ logger.info(request.url)
initial_start_vars = request.form
logger.debug("Marker regression called with initial_start_vars:", initial_start_vars.items())
#temp_uuid = initial_start_vars['temp_uuid']
@@ -552,7 +552,7 @@ def loading_page():
def marker_regression_page():
initial_start_vars = request.form
logger.debug("Marker regression called with initial_start_vars:", initial_start_vars.items())
- logger.error(request.url)
+ logger.info(request.url)
temp_uuid = initial_start_vars['temp_uuid']
wanted = (
'trait_id',
@@ -678,7 +678,7 @@ def marker_regression_page():
@app.route("/export_mapping_results", methods = ('POST',))
def export_mapping_results():
logger.info("request.form:", request.form)
- logger.error(request.url)
+ logger.info(request.url)
file_path = request.form.get("results_path")
results_csv = open(file_path, "r").read()
response = Response(results_csv,
@@ -691,7 +691,7 @@ def export_mapping_results():
@app.route("/export", methods = ('POST',))
def export():
logger.info("request.form:", request.form)
- logger.error(request.url)
+ logger.info(request.url)
svg_xml = request.form.get("data", "Invalid data")
filename = request.form.get("filename", "manhattan_plot_snp")
response = Response(svg_xml, mimetype="image/svg+xml")
@@ -702,7 +702,7 @@ def export():
def export_pdf():
import cairosvg
logger.info("request.form:", request.form)
- logger.error(request.url)
+ logger.info(request.url)
svg_xml = request.form.get("data", "Invalid data")
logger.info("svg_xml:", svg_xml)
filename = request.form.get("filename", "interval_map_pdf")
@@ -715,7 +715,7 @@ def export_pdf():
@app.route("/network_graph", methods=('POST',))
def network_graph_page():
logger.info("In network_graph, request.form is:", pf(request.form))
- logger.error(request.url)
+ logger.info(request.url)
start_vars = request.form
traits = [trait.strip() for trait in start_vars['trait_list'].split(',')]
if traits[0] != "":
@@ -731,7 +731,7 @@ def network_graph_page():
@app.route("/corr_compute", methods=('POST',))
def corr_compute_page():
logger.info("In corr_compute, request.form is:", pf(request.form))
- logger.error(request.url)
+ logger.info(request.url)
#fd = webqtlFormData.webqtlFormData(request.form)
template_vars = show_corr_results.CorrelationResults(request.form)
return render_template("correlation_page.html", **template_vars.__dict__)
@@ -739,7 +739,7 @@ def corr_compute_page():
@app.route("/corr_matrix", methods=('POST',))
def corr_matrix_page():
logger.info("In corr_matrix, request.form is:", pf(request.form))
- logger.error(request.url)
+ logger.info(request.url)
start_vars = request.form
traits = [trait.strip() for trait in start_vars['trait_list'].split(',')]
@@ -755,7 +755,7 @@ def corr_matrix_page():
@app.route("/corr_scatter_plot")
def corr_scatter_plot_page():
- logger.error(request.url)
+ logger.info(request.url)
template_vars = corr_scatter_plot.CorrScatterPlot(request.args)
template_vars.js_data = json.dumps(template_vars.js_data,
default=json_default_handler,
@@ -764,7 +764,7 @@ def corr_scatter_plot_page():
@app.route("/submit_bnw", methods=('POST',))
def submit_bnw():
- logger.error(request.url)
+ logger.info(request.url)
template_vars = get_bnw_input(request.form)
return render_template("empty_collection.html", **{'tool':'Correlation Matrix'})
@@ -772,7 +772,7 @@ def submit_bnw():
def sharing_info_page():
"""Info page displayed when the user clicks the "Info" button next to the dataset selection"""
logger.info("In sharing_info_page")
- logger.error(request.url)
+ logger.info(request.url)
fd = webqtlFormData.webqtlFormData(request.args)
template_vars = SharingInfoPage.SharingInfoPage(fd)
return template_vars
@@ -780,7 +780,7 @@ def sharing_info_page():
# Take this out or secure it before putting into production
@app.route("/get_temp_data")
def get_temp_data():
- logger.error(request.url)
+ logger.info(request.url)
temp_uuid = request.args['key']
return flask.jsonify(temp_data.TempData(temp_uuid).get_all())
--
cgit v1.2.3