From 1cf6894c7416f879fcd114ae7358bb7d4169a677 Mon Sep 17 00:00:00 2001
From: Sam
Date: Thu, 9 May 2013 22:28:22 +0000
Subject: Working on user registration
---
wqflask/secure_server.py | 9 +++--
wqflask/wqflask/templates/base.html | 30 +++++++++++++---
wqflask/wqflask/templates/index_page.html | 7 ++--
.../wqflask/templates/security/register_user.html | 40 +++-------------------
4 files changed, 39 insertions(+), 47 deletions(-)
diff --git a/wqflask/secure_server.py b/wqflask/secure_server.py
index 5448dbeb..60f6db44 100644
--- a/wqflask/secure_server.py
+++ b/wqflask/secure_server.py
@@ -7,6 +7,11 @@ from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin
+# Setup mail
+from flask.ext.mail import Mail
+mail = Mail(app)
+
+
# Create database connection object
db = SQLAlchemy(app)
@@ -26,13 +31,13 @@ class User(db.Model, UserMixin):
password = db.Column(db.String(255))
active = db.Column(db.Boolean())
confirmed_at = db.Column(db.DateTime())
-
+
last_login_at = db.Column(db.DateTime())
current_login_at = db.Column(db.DateTime())
last_login_ip_= db.Column(db.String(39))
current_login_ip = db.Column(db.String(39))
login_count = db.Column(db.Integer())
-
+
roles = db.relationship('Role', secondary=roles_users,
backref=db.backref('users', lazy='dynamic'))
diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html
index 71c12941..6f4b8e1e 100644
--- a/wqflask/wqflask/templates/base.html
+++ b/wqflask/wqflask/templates/base.html
@@ -14,9 +14,9 @@
-
+
{% block css %}
{% endblock %}
@@ -57,13 +57,17 @@
News
- References
+ References
+
+
+ Policies
- Policies
+ Links
- Links
+ Login
@@ -137,6 +141,22 @@
+
+
+
+
+
+
One fine body…this is getting replaced with content that comes from passed-in href
+
+
+
+
diff --git a/wqflask/wqflask/templates/security/_macros.html b/wqflask/wqflask/templates/security/_macros.html
index 8575f3db..919b979a 100644
--- a/wqflask/wqflask/templates/security/_macros.html
+++ b/wqflask/wqflask/templates/security/_macros.html
@@ -13,4 +13,4 @@
{% macro render_field(field) %}
{{ field(**kwargs)|safe }}
-{% endmacro %}
\ No newline at end of file
+{% endmacro %}
diff --git a/wqflask/wqflask/templates/security/login_user.html b/wqflask/wqflask/templates/security/login_user.html
index d781ce08..b5fcbfdc 100644
--- a/wqflask/wqflask/templates/security/login_user.html
+++ b/wqflask/wqflask/templates/security/login_user.html
@@ -5,8 +5,13 @@
{{ login_user_form.hidden_tag() }}
{{ render_field_with_errors(login_user_form.email) }}
{{ render_field_with_errors(login_user_form.password) }}
+
+ {% if security.recoverable %}
+ Forgot your password?
+ {% endif %}
+
{{ render_field_with_errors(login_user_form.remember) }}
{{ render_field(login_user_form.next) }}
{{ render_field(login_user_form.submit) }}
-{% include "security/_menu.html" %}
\ No newline at end of file
+
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
new file mode 100644
index 00000000..4d608dc7
--- /dev/null
+++ b/wqflask/wqflask/user_manager.py
@@ -0,0 +1,22 @@
+from __future__ import print_function, division, absolute_import
+
+"""Access things in template like this:
+
+ x: {{ g.identity.name }}
+ security: {{ security.__dict__ }}
+
+"""
+
+from wqflask import model
+
+from flask import Flask, g
+
+#from app import db
+print("globals are:", globals())
+
+
+class UserManager(object):
+ def __init__(self):
+ self.users = model.User.query.all()
+ print("Users are:", self.users)
+
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 8531561a..dadce4d5 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -35,6 +35,8 @@ from utility.benchmark import Bench
from pprint import pformat as pf
+from wqflask import user_manager
+
#import logging
#logging.basicConfig(filename="/tmp/gn_log", level=logging.INFO)
#_log = logging.getLogger("correlation")
@@ -166,21 +168,21 @@ def marker_regression_page():
'dataset',
'suggestive'
)
-
+
start_vars = {}
for key, value in initial_start_vars.iteritems():
if key in wanted or key.startswith(('value:')):
start_vars[key] = value
-
+
version = "v14"
key = "marker_regression:{}:".format(version) + json.dumps(start_vars, sort_keys=True)
with Bench("Loading cache"):
result = Redis.get(key)
-
+
#print("************************ Starting result *****************")
#print("result is [{}]: {}".format(type(result), result))
#print("************************ Ending result ********************")
-
+
if result:
print("Cache hit!!!")
with Bench("Loading results"):
@@ -194,17 +196,17 @@ def marker_regression_page():
indent=" ")
result = template_vars.__dict__
-
+
#for item in template_vars.__dict__.keys():
# print(" ---**--- {}: {}".format(type(template_vars.__dict__[item]), item))
-
+
#causeerror
Redis.set(key, pickle.dumps(result))
Redis.expire(key, 60*60)
-
+
with Bench("Rendering template"):
rendered_template = render_template("marker_regression.html", **result)
-
+
return rendered_template
@@ -234,6 +236,11 @@ def get_temp_data():
temp_uuid = request.args['key']
return flask.jsonify(temp_data.TempData(temp_uuid).get_all())
+@app.route("/users")
+def manage_users():
+ template_vars = user_manager.UserManager()
+ return render_template("admin/user_manager.html", **template_vars.__dict__)
+
def json_default_handler(obj):
'''Based on http://stackoverflow.com/a/2680060/1175849'''
@@ -251,4 +258,4 @@ def json_default_handler(obj):
# return None
else:
raise TypeError, 'Object of type %s with value of %s is not JSON serializable' % (
- type(obj), repr(obj))
\ No newline at end of file
+ type(obj), repr(obj))
--
cgit v1.2.3
From fba7e9220054bf71a0c363da90378e0c42142b4a Mon Sep 17 00:00:00 2001
From: Sam
Date: Fri, 10 May 2013 21:11:54 +0000
Subject: More security changes
---
wqflask/wqflask/__init__.py | 2 ++
wqflask/wqflask/model.py | 3 +++
2 files changed, 5 insertions(+)
diff --git a/wqflask/wqflask/__init__.py b/wqflask/wqflask/__init__.py
index ff018fdc..8e648c63 100644
--- a/wqflask/wqflask/__init__.py
+++ b/wqflask/wqflask/__init__.py
@@ -11,6 +11,8 @@ from utility import formatting
app = Flask(__name__)
+app.config.SECURITY_PASSWORD_HASH='bcrypt'
+
# See http://flask.pocoo.org/docs/config/#configuring-from-files
app.config.from_object('cfg.default_settings')
app.config.from_envvar('WQFLASK_SETTINGS')
diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py
index be86ce77..9f9267d9 100644
--- a/wqflask/wqflask/model.py
+++ b/wqflask/wqflask/model.py
@@ -37,3 +37,6 @@ class User(db.Model, UserMixin):
# Setup Flask-Security
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
security = Security(app, user_datastore)
+
+
+db.metadata.create_all(db.engine)
--
cgit v1.2.3
From c2080606d8822e21edaad627d7deda1f114aa003 Mon Sep 17 00:00:00 2001
From: Sam
Date: Fri, 10 May 2013 21:52:37 +0000
Subject: Sign in template looking pretty good
---
wqflask/wqflask/templates/base.html | 4 +-
wqflask/wqflask/templates/security/_macros.html | 13 +++++
wqflask/wqflask/templates/security/login_user.html | 59 +++++++++++++++++-----
3 files changed, 60 insertions(+), 16 deletions(-)
diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html
index 69117d89..470ac9db 100644
--- a/wqflask/wqflask/templates/base.html
+++ b/wqflask/wqflask/templates/base.html
@@ -68,10 +68,10 @@
{% if g.identity.name=="anon" %}
Login
+ data-target="#utility" data-toggle="modal">Sign in
{% else %}
Logout
+ data-target="#utility" data-toggle="modal">Sign out
{% endif %}
diff --git a/wqflask/wqflask/templates/security/_macros.html b/wqflask/wqflask/templates/security/_macros.html
index 919b979a..83f12bf7 100644
--- a/wqflask/wqflask/templates/security/_macros.html
+++ b/wqflask/wqflask/templates/security/_macros.html
@@ -11,6 +11,19 @@
{% endmacro %}
+{% macro render_only_errors(field) %}
+
+
+ {% if field.errors %}
+
+ {% for error in field.errors %}
+ - {{ error }}
+ {% endfor %}
+
+ {% endif %}
+
+{% endmacro %}
+
{% macro render_field(field) %}
{{ field(**kwargs)|safe }}
{% endmacro %}
diff --git a/wqflask/wqflask/templates/security/login_user.html b/wqflask/wqflask/templates/security/login_user.html
index b5fcbfdc..76f28094 100644
--- a/wqflask/wqflask/templates/security/login_user.html
+++ b/wqflask/wqflask/templates/security/login_user.html
@@ -1,17 +1,48 @@
-{% from "security/_macros.html" import render_field_with_errors, render_field %}
+{% from "security/_macros.html" import render_only_errors %}
{% include "security/_messages.html" %}
-Login
-