aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorzsloan2018-04-16 10:46:56 -0500
committerGitHub2018-04-16 10:46:56 -0500
commita58a4c3b8ee4f7256a18c99542ff6a9f355c0a2e (patch)
tree1e7677fa1fa210a2a957855578cd3ac3a47b720b /wqflask
parent270f86c41f7c90cc4ca51bca0aec789a09a36a0e (diff)
parentebbc8c67c13b44df98ea3c2b355e86f77572543b (diff)
downloadgenenetwork2-a58a4c3b8ee4f7256a18c99542ff6a9f355c0a2e.tar.gz
Merge pull request #317 from pjotrp/testing
Testing
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/base/anon_collection.py3
-rw-r--r--wqflask/utility/elasticsearch_tools.py61
-rw-r--r--wqflask/utility/svg.py2
-rw-r--r--wqflask/wqflask/templates/new_security/login_user.html7
-rw-r--r--wqflask/wqflask/user_manager.py35
5 files changed, 85 insertions, 23 deletions
diff --git a/wqflask/base/anon_collection.py b/wqflask/base/anon_collection.py
index 8ee73296..dd1aa27f 100644
--- a/wqflask/base/anon_collection.py
+++ b/wqflask/base/anon_collection.py
@@ -1,6 +1,6 @@
class AnonCollection(TraitCollection):
- def __init__(self, anon_id)
+ def __init__(self, anon_id):
self.anon_id = anon_id
self.collection_members = Redis.smembers(self.anon_id)
print("self.collection_members is:", self.collection_members)
@@ -12,6 +12,7 @@ class AnonCollection(TraitCollection):
print("traits_to_remove:", traits_to_remove)
for trait in traits_to_remove:
Redis.srem(self.anon_id, trait)
+
members_now = self.collection_members - traits_to_remove
print("members_now:", members_now)
print("Went from {} to {} members in set.".format(len(self.collection_members), len(members_now)))
diff --git a/wqflask/utility/elasticsearch_tools.py b/wqflask/utility/elasticsearch_tools.py
index 1dba357d..76dcaebf 100644
--- a/wqflask/utility/elasticsearch_tools.py
+++ b/wqflask/utility/elasticsearch_tools.py
@@ -1,3 +1,44 @@
+# Elasticsearch support
+#
+# Some helpful commands to view the database:
+#
+# You can test the server being up with
+#
+# curl -H 'Content-Type: application/json' http://localhost:9200
+#
+# List all indices
+#
+# curl -H 'Content-Type: application/json' 'localhost:9200/_cat/indices?v'
+#
+# To see the users index 'table'
+#
+# curl http://localhost:9200/users
+#
+# To list all user ids
+#
+# curl -H 'Content-Type: application/json' http://localhost:9200/users/local/_search?pretty=true -d '
+# {
+# "query" : {
+# "match_all" : {}
+# },
+# "stored_fields": []
+# }'
+#
+# To view a record
+#
+# curl -H 'Content-Type: application/json' http://localhost:9200/users/local/_search?pretty=true -d '
+# {
+# "query" : {
+# "match" : { "email_address": "pjotr2017@thebird.nl"}
+# }
+# }'
+#
+#
+# To delete the users index and data (dangerous!)
+#
+# curl -XDELETE -H 'Content-Type: application/json' 'localhost:9200/users'
+
+
from elasticsearch import Elasticsearch, TransportError
import logging
@@ -7,7 +48,7 @@ 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)
+ es = Elasticsearch(['http://'+ELASTICSEARCH_HOST+":"+str(ELASTICSEARCH_PORT)+'/'], verify_certs=True)
if not es.ping():
logger.warning("Elasticsearch is DOWN")
@@ -24,15 +65,29 @@ def get_elasticsearch_connection():
"host": ELASTICSEARCH_HOST, "port": ELASTICSEARCH_PORT
}]) if (ELASTICSEARCH_HOST and ELASTICSEARCH_PORT) else None
+ setup_users_index(es)
+
es_logger = logging.getLogger("elasticsearch")
es_logger.setLevel(logging.INFO)
es_logger.addHandler(logging.NullHandler())
- except:
- logger.error("Failed to get elasticsearch connection")
+ except Exception as e:
+ logger.error("Failed to get elasticsearch connection", e)
es = None
return es
+def setup_users_index(es_connection):
+ if es_connection:
+ index_settings = {
+ "properties": {
+ "email_address": {
+ "type": "keyword"}}}
+
+ es_connection.indices.create(index='users', ignore=400)
+ es_connection.indices.close(index="users")
+ es_connection.indices.put_mapping(body=index_settings, index="users", doc_type="local")
+ es_connection.indices.open(index="users")
+
def get_user_by_unique_column(es, column_name, column_value, index="users", doc_type="local"):
return get_item_by_unique_column(es, column_name, column_value, index=index, doc_type=doc_type)
diff --git a/wqflask/utility/svg.py b/wqflask/utility/svg.py
index 512bc9e6..db13b9d1 100644
--- a/wqflask/utility/svg.py
+++ b/wqflask/utility/svg.py
@@ -1029,7 +1029,7 @@ class drawing:
try:
xv.feed(svg)
except:
- raise "SVG is not well formed, see messages above"
+ raise Exception("SVG is not well formed, see messages above")
else:
print "SVG well formed"
if __name__=='__main__':
diff --git a/wqflask/wqflask/templates/new_security/login_user.html b/wqflask/wqflask/templates/new_security/login_user.html
index 4a857c60..27b20ebf 100644
--- a/wqflask/wqflask/templates/new_security/login_user.html
+++ b/wqflask/wqflask/templates/new_security/login_user.html
@@ -31,16 +31,19 @@
<div>
{% if external_login["github"]: %}
<a href="{{external_login['github']}}" title="Login with GitHub" class="btn btn-info btn-group">Login with Github</a>
+ {% else %}
+ <p>Github login is not available right now</p>
{% endif %}
{% if external_login["orcid"]: %}
<a href="{{external_login['orcid']}}" title="Login with ORCID" class="btn btn-info btn-group">Login with ORCID</a>
+ {% else %}
+ <p>ORCID login is not available right now</p>
{% endif %}
</div>
{% else: %}
<div class="alert alert-warning">
- <p>You cannot login with external services at this time.<br />
- Please try again later.</p>
+ <p>Sorry, you cannot login with Github or ORCID at this time.</p>
</div>
{% endif %}
<hr />
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index 5f6c818e..d652f2e9 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -727,30 +727,33 @@ def logout():
return response
-@app.route("/n/forgot_password")
+@app.route("/n/forgot_password", methods=['GET'])
def forgot_password():
"""Entry point for forgotten password"""
- return render_template("new_security/forgot_password.html")
+ print("ARGS: ", request.args)
+ errors = {"no-email": request.args.get("no-email")}
+ print("ERRORS: ", errors)
+ return render_template("new_security/forgot_password.html", errors=errors)
@app.route("/n/forgot_password_submit", methods=('POST',))
def forgot_password_submit():
"""When a forgotten password form is submitted we get here"""
params = request.form
email_address = params['email_address']
- logger.debug("Wants to send password E-mail to ",email_address)
- es = get_elasticsearch_connection()
- user_details = get_user_by_unique_column(es, "email_address", email_address)
- if user_details:
- ForgotPasswordEmail(user_details["email_address"])
- # try:
- # user = model.User.query.filter_by(email_address=email_address).one()
- # except orm.exc.NoResultFound:
- # flash("Couldn't find a user associated with the email address {}. Sorry.".format(
- # email_address))
- # return redirect(url_for("login"))
- # ForgotPasswordEmail(user)
- return render_template("new_security/forgot_password_step2.html",
- subject=ForgotPasswordEmail.subject)
+ next_page = None
+ if email_address != "":
+ logger.debug("Wants to send password E-mail to ",email_address)
+ es = get_elasticsearch_connection()
+ user_details = get_user_by_unique_column(es, "email_address", email_address)
+ if user_details:
+ ForgotPasswordEmail(user_details["email_address"])
+
+ return render_template("new_security/forgot_password_step2.html",
+ subject=ForgotPasswordEmail.subject)
+
+ else:
+ flash("You MUST provide an email", "alert-danger")
+ return redirect(url_for("forgot_password"))
@app.errorhandler(401)
def unauthorized(error):