aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorSam2013-09-06 17:33:19 -0500
committerSam2013-09-06 17:33:19 -0500
commite91c058cd718fea25e38181098b1d0eb2ccf64cd (patch)
tree88c67ea1894c8b8d4932349a47a306d19155313c /wqflask
parentdb38728a7a59347847fb2fc5823a14f0f059f278 (diff)
downloadgenenetwork2-e91c058cd718fea25e38181098b1d0eb2ccf64cd.tar.gz
Registration form validaiton without js works
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/secure_server.py2
-rw-r--r--wqflask/wqflask/model.py8
-rw-r--r--wqflask/wqflask/static/new/js_external/zxcvbn/zxcvbn-async.js1
-rw-r--r--wqflask/wqflask/templates/new_security/register_user.html25
-rw-r--r--wqflask/wqflask/user_manager.py33
-rw-r--r--wqflask/wqflask/views.py30
6 files changed, 83 insertions, 16 deletions
diff --git a/wqflask/secure_server.py b/wqflask/secure_server.py
index 697ebfe0..df195bd2 100644
--- a/wqflask/secure_server.py
+++ b/wqflask/secure_server.py
@@ -36,4 +36,4 @@ if __name__ == '__main__':
port=app.config['SERVER_PORT'],
use_debugger=False,
threaded=True,
- use_reloader=False)
+ use_reloader=True)
diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py
index c1b8d060..b3dfe746 100644
--- a/wqflask/wqflask/model.py
+++ b/wqflask/wqflask/model.py
@@ -47,11 +47,11 @@ class Role(db.Model, RoleMixin):
class User(db.Model, UserMixin):
id = db.Column(db.Integer(), primary_key=True)
- email = db.Column(db.String(255), unique=True)
- password = db.Column(db.String(255))
+ email = db.Column(db.String(50), unique=True)
+ password = db.Column(db.String(50))
- name = db.Column(db.Unicode(255))
- organization = db.Column(db.Unicode(255))
+ full_name = db.Column(db.Unicode(50))
+ organization = db.Column(db.Unicode(50))
active = db.Column(db.Boolean())
confirmed_at = db.Column(db.DateTime())
diff --git a/wqflask/wqflask/static/new/js_external/zxcvbn/zxcvbn-async.js b/wqflask/wqflask/static/new/js_external/zxcvbn/zxcvbn-async.js
new file mode 100644
index 00000000..404944d3
--- /dev/null
+++ b/wqflask/wqflask/static/new/js_external/zxcvbn/zxcvbn-async.js
@@ -0,0 +1 @@
+(function(){var a;a=function(){var a,b;b=document.createElement("script");b.src="//dl.dropbox.com/u/209/zxcvbn/zxcvbn.js";b.type="text/javascript";b.async=!0;a=document.getElementsByTagName("script")[0];return a.parentNode.insertBefore(b,a)};null!=window.attachEvent?window.attachEvent("onload",a):window.addEventListener("load",a,!1)}).call(this);
diff --git a/wqflask/wqflask/templates/new_security/register_user.html b/wqflask/wqflask/templates/new_security/register_user.html
index d203d65f..6a7f4c9c 100644
--- a/wqflask/wqflask/templates/new_security/register_user.html
+++ b/wqflask/wqflask/templates/new_security/register_user.html
@@ -28,15 +28,26 @@
<h4>Don't have an account?</h4>
<h5>Register here</h5>
-
- <form class="form-horizontal" action="/n/register_submit" data-validate="parsley"
+
+ {% if errors %}
+ <div class="alert alert-error">
+ <strong>Please note:</strong>
+ <ul>
+ {% for error in errors %}
+ <li>{{error}}</li>
+ {% endfor %}
+ </ul>
+ </div>
+ {% endif %}
+
+ <form class="form-horizontal" action="/n/register" data-validate="parsley"
method="POST" name="login_user_form">
<fieldset>
<div class="control-group">
<label class="control-label" for="email">Email Address</label>
<div class="controls">
- <input id="email" name="email" class="focused" type="text" value=""
+ <input id="email_address" name="email_address" class="focused" type="text" value="{{values.email_address}}"
data-trigger="change" data-required="true" data-type="email" data-maxlength="50">
</div>
</div>
@@ -44,7 +55,7 @@
<div class="control-group">
<label class="control-label" for="email">Full Name</label>
<div class="controls">
- <input id="name" name="name" type="text" value=""
+ <input id="full_name" name="full_name" type="text" value="{{values.full_name}}"
data-trigger="change" data-required="true" data-minlength="5" data-maxlength="50">
</div>
</div>
@@ -52,7 +63,7 @@
<div class="control-group">
<label class="control-label" for="email">Organization</label>
<div class="controls">
- <input id="organization" name="organization" type="text" value="" data-minlength="3" data-maxlength="50">
+ <input id="organization" name="organization" type="text" value="{{values.organization}}" data-minlength="3" data-maxlength="50">
</div>
</div>
@@ -62,8 +73,7 @@
<input id="password" name="password" type="password" value=""
data-trigger="change" data-required="true" data-minlength="6" data-maxlength="30">
</div>
- </div>
-
+ </div>
<div class="control-group" style="display: none" id="password_alert">
<div class="controls"">
@@ -71,7 +81,6 @@
</div>
</div>
-
<div class="control-group">
<label class="control-label" for="password_confirm">Confirm Password</label>
<div class="controls">
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index 9e666bbd..d03910ca 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -9,6 +9,8 @@ from __future__ import print_function, division, absolute_import
from wqflask import model
+from utility import Bunch
+
from flask import Flask, g
from pprint import pformat as pf
@@ -43,6 +45,37 @@ class UserManager(object):
print(" ID:", dataset.id)
print(" Confidential:", dataset.check_confidentiality())
#print(" ---> self.datasets:", self.datasets)
+
+
+class RegisterUser(object):
+ def __init__(self, kw):
+ self.errors = []
+ user = Bunch()
+
+ user.email_address = kw.get('email_address', '').strip()
+ if not (5 <= len(user.email_address) <= 50):
+ self.errors.append('Email Address needs to be between 5 and 50 characters.')
+
+ user.full_name = kw.get('full_name', '').strip()
+ if not (5 <= len(user.full_name) <= 50):
+ self.errors.append('Full Name needs to be between 5 and 50 characters.')
+
+ user.organization = kw.get('organization', '').strip()
+ if user.organization and not (5 <= len(user.organization) <= 50):
+ self.errors.append('Organization needs to be empty or between 5 and 50 characters.')
+
+ user.password = kw.get('password', '')
+ if not (6 <= len(user.password) <= 30):
+ self.errors.append('Password needs to be between 6 and 30 characters.')
+
+ if kw.get('password_confirm') != user.password:
+ self.errors.append("Passwords don't match.")
+
+ if self.errors:
+ return
+
+
+
class GroupsManager(object):
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 6f14ac8d..9a0401d6 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -23,7 +23,8 @@ import sqlalchemy
from wqflask import app
-from flask import render_template, request, make_response, Response, Flask, g, config, jsonify
+from flask import (render_template, request, make_response, Response,
+ Flask, g, config, jsonify, redirect, url_for)
from wqflask import search_results
from base.data_set import DataSet # Used by YAML in marker_regression
@@ -292,9 +293,32 @@ def manage_groups():
return render_template("admin/group_manager.html", **template_vars.__dict__)
-@app.route("/n/register")
+@app.route("/n/register", methods=('GET', 'POST'))
def new_register():
- return render_template("new_security/register_user.html")
+ params = None
+ errors = None
+ if request.form:
+ params = request.form
+ else:
+ params = request.args
+ if params:
+ result = user_manager.RegisterUser(params)
+ errors = result.errors
+ return render_template("new_security/register_user.html", values=params, errors=errors)
+
+#@app.route("/n/register_submit", methods=('POST',))
+#def register_submit():
+# print("request.args are: ", request.args)
+# result = user_manager.RegisterUser(request.form)
+# if result.errors:
+# print("Redirecting")
+# # 307 preserves the post on the redirect (maybe)
+# errors = result.errors
+# #errors = json.dumps(errors)
+# print("request.args are: ", request.args)
+# return render_template("new_security/register_user.html", errors=errors, values=request.form)
+# #return redirect(url_for('new_register', errors=errors), code=307)
+
@app.route("/n/login")
def new_login():