aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorzsloan2018-04-04 12:15:45 -0500
committerGitHub2018-04-04 12:15:45 -0500
commitb152aca03be73655d2fb5eda17d533504ed900e2 (patch)
tree8e6b5d3810081d44b59f91e15fbf1702c444f7af /wqflask
parent57e6d490cf8c7acb326552456a597f1e1cdecc2c (diff)
parent273c72ef02f839b88b3d2ad504e9d84eab0f9ec5 (diff)
downloadgenenetwork2-b152aca03be73655d2fb5eda17d533504ed900e2.tar.gz
Merge pull request #303 from pjotrp/testing
Minor edits and document on ES
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/utility/elasticsearch_tools.py9
-rw-r--r--wqflask/wqflask/user_manager.py30
2 files changed, 14 insertions, 25 deletions
diff --git a/wqflask/utility/elasticsearch_tools.py b/wqflask/utility/elasticsearch_tools.py
index 734379f7..1dba357d 100644
--- a/wqflask/utility/elasticsearch_tools.py
+++ b/wqflask/utility/elasticsearch_tools.py
@@ -12,6 +12,7 @@ def test_elasticsearch_connection():
logger.warning("Elasticsearch is DOWN")
def get_elasticsearch_connection():
+ """Return a connection to ES. Returns None on failure"""
logger.info("get_elasticsearch_connection")
es = None
try:
@@ -20,14 +21,14 @@ def get_elasticsearch_connection():
logger.info("ES HOST",ELASTICSEARCH_HOST)
es = Elasticsearch([{
- "host": ELASTICSEARCH_HOST
- , "port": ELASTICSEARCH_PORT
+ "host": ELASTICSEARCH_HOST, "port": ELASTICSEARCH_PORT
}]) if (ELASTICSEARCH_HOST and ELASTICSEARCH_PORT) else None
es_logger = logging.getLogger("elasticsearch")
es_logger.setLevel(logging.INFO)
es_logger.addHandler(logging.NullHandler())
except:
+ logger.error("Failed to get elasticsearch connection")
es = None
return es
@@ -42,9 +43,7 @@ def get_item_by_unique_column(es, column_name, column_value, index, doc_type):
item_details = None
try:
response = es.search(
- index = index
- , doc_type = doc_type
- , body = {
+ index = index, doc_type = doc_type, body = {
"query": { "match": { column_name: column_value } }
})
if len(response["hits"]["hits"]) > 0:
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index ac3824a7..5f6c818e 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -1,45 +1,30 @@
from __future__ import print_function, division, absolute_import
-"""Used to Access things in template like this:
-(BUT NOW OUT OF DATE)
-
- x: {{ g.identity.name }}
- security: {{ security.__dict__ }}
-
-"""
-
import os
import hashlib
import datetime
import time
import logging
-
import uuid
import hashlib
import hmac
import base64
-
import urlparse
import simplejson as json
#from redis import StrictRedis
-import redis
+import redis # used for collections
Redis = redis.StrictRedis()
-
from flask import (Flask, g, render_template, url_for, request, make_response,
redirect, flash, abort)
from wqflask import app
-
-
from pprint import pformat as pf
-from wqflask import pbkdf2
-
+from wqflask import pbkdf2 # password hashing
from wqflask.database import db_session
-
from wqflask import model
from utility import Bunch, Struct, after
@@ -62,8 +47,8 @@ THREE_DAYS = 60 * 60 * 24 * 3
def timestamp():
return datetime.datetime.utcnow().isoformat()
-
class AnonUser(object):
+ """Anonymous user handling"""
cookie_name = 'anon_user_v8'
def __init__(self):
@@ -169,6 +154,8 @@ def create_signed_cookie():
return the_uuid, uuid_signed
class UserSession(object):
+ """Logged in user handling"""
+
cookie_name = 'session_id_v2'
def __init__(self):
@@ -437,6 +424,7 @@ def verify_email():
@app.route("/n/password_reset", methods=['GET'])
def password_reset():
+ """Entry point after user clicks link in E-mail"""
logger.debug("in password_reset request.url is:", request.url)
# We do this mainly just to assert that it's in proper form for displaying next page
# Really not necessary but doesn't hurt
@@ -467,6 +455,7 @@ def password_reset():
@app.route("/n/password_reset_step2", methods=('POST',))
def password_reset_step2():
+ """Handle confirmation E-mail for password reset"""
logger.debug("in password_reset request.url is:", request.url)
errors = []
@@ -663,8 +652,6 @@ class LoginUser(object):
VerificationEmail(user)
return render_template("new_security/verification_still_needed.html",
subject=VerificationEmail.subject)
-
-
if valid:
if params.get('remember'):
logger.debug("I will remember you")
@@ -742,12 +729,15 @@ def logout():
@app.route("/n/forgot_password")
def forgot_password():
+ """Entry point for forgotten password"""
return render_template("new_security/forgot_password.html")
@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: