diff options
author | Zachary Sloan | 2013-03-22 23:29:55 +0000 |
---|---|---|
committer | Zachary Sloan | 2013-03-22 23:29:55 +0000 |
commit | 05f4cfc55a6473cb438ce0059d6d37f913abcb01 (patch) | |
tree | 6f72ee7498d802e79051f054570ff9b278876f5a /wqflask | |
parent | b0cb34e8e4ddf09b0cfe3081439610c6f6d0341c (diff) | |
download | genenetwork2-05f4cfc55a6473cb438ce0059d6d37f913abcb01.tar.gz |
Began creating templates for login/registration
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/cfg/default_settings.py | 7 | ||||
-rw-r--r-- | wqflask/secure_server.py | 24 | ||||
-rw-r--r-- | wqflask/wqflask/templates/security/_macros.html | 16 | ||||
-rw-r--r-- | wqflask/wqflask/templates/security/_menu.html | 15 | ||||
-rw-r--r-- | wqflask/wqflask/templates/security/_messages.html | 9 | ||||
-rw-r--r-- | wqflask/wqflask/templates/security/register_user.html | 45 |
6 files changed, 96 insertions, 20 deletions
diff --git a/wqflask/cfg/default_settings.py b/wqflask/cfg/default_settings.py index 53b5a96e..a575a3bd 100644 --- a/wqflask/cfg/default_settings.py +++ b/wqflask/cfg/default_settings.py @@ -4,5 +4,8 @@ LOGFILE = """/tmp/flask_gn_log""" #400 bad request response with no exception/log TRAP_BAD_REQUEST_ERRORS = True -#SECURITY_CONFIRMABLE = True -SECURITY_TRACKABLE = True
\ No newline at end of file +# http://pythonhosted.org/Flask-Security/configuration.html +SECURITY_CONFIRMABLE = True +SECURITY_TRACKABLE = True +SECURITY_REGISTERABLE = True +SECURITY_RECOVERABLE = True diff --git a/wqflask/secure_server.py b/wqflask/secure_server.py index 49e0b433..425fce89 100644 --- a/wqflask/secure_server.py +++ b/wqflask/secure_server.py @@ -4,15 +4,8 @@ from wqflask import app from flask import Flask, render_template from flask.ext.sqlalchemy import SQLAlchemy -from flask.ext.security import Security, SQLAlchemyUserDatastore, \ - UserMixin, RoleMixin +from flask.ext.security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin -# Create app -#app = Flask(__name__) -app.config['SECRET_KEY'] = 'LjfrbDOlvdFMT5cCi9qrJqStxK4NcmxW' -app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://webqtl:f2ZypIflRM@gn.cazhbciu2y1i.us-east-1.rds.amazonaws.com/db_webqtl' -#app.config['SECURITY_CONFIRMABLE'] = True -app.config['SECURITY_TRACKABLE'] = True # Create database connection object db = SQLAlchemy(app) @@ -48,19 +41,14 @@ user_datastore = SQLAlchemyUserDatastore(db, User, Role) security = Security(app, user_datastore) # Create a user to test with -#@app.before_first_request -def create_user(): - db.create_all() - user_datastore.create_user(email='matt@example.com', password='notebook') - db.session.commit() +##@app.before_first_request +#def create_user(): +# db.create_all() +# user_datastore.create_user(email='matt@example.com', password='notebook') +# db.session.commit() -## Views -#@app.route('/') -#def home(): -# return render_template('index.html') import logging -#from themodule import TheHandlerYouWant file_handler = logging.FileHandler("/tmp/flask_gn_log") file_handler.setLevel(logging.DEBUG) app.logger.addHandler(file_handler) diff --git a/wqflask/wqflask/templates/security/_macros.html b/wqflask/wqflask/templates/security/_macros.html new file mode 100644 index 00000000..8575f3db --- /dev/null +++ b/wqflask/wqflask/templates/security/_macros.html @@ -0,0 +1,16 @@ +{% macro render_field_with_errors(field) %} + <p> + {{ field.label }} {{ field(**kwargs)|safe }} + {% if field.errors %} + <ul> + {% for error in field.errors %} + <li>{{ error }}</li> + {% endfor %} + </ul> + {% endif %} + </p> +{% endmacro %} + +{% macro render_field(field) %} + <p>{{ field(**kwargs)|safe }}</p> +{% endmacro %}
\ No newline at end of file diff --git a/wqflask/wqflask/templates/security/_menu.html b/wqflask/wqflask/templates/security/_menu.html new file mode 100644 index 00000000..5291f809 --- /dev/null +++ b/wqflask/wqflask/templates/security/_menu.html @@ -0,0 +1,15 @@ +{% if security.registerable or security.recoverable or security.confirmabled %} +<h2>Menu</h2> +<ul> + <li><a href="{{ url_for_security('login') }}">Login</a></li> + {% if security.registerable %} + <li><a href="{{ url_for_security('register') }}">Register</a><br/></li> + {% endif %} + {% if security.recoverable %} + <li><a href="{{ url_for_security('forgot_password') }}">Forgot password</a><br/></li> + {% endif %} + {% if security.confirmable %} + <li><a href="{{ url_for_security('send_confirmation') }}">Confirm account</a></li> + {% endif %} +</ul> +{% endif %} diff --git a/wqflask/wqflask/templates/security/_messages.html b/wqflask/wqflask/templates/security/_messages.html new file mode 100644 index 00000000..179d0636 --- /dev/null +++ b/wqflask/wqflask/templates/security/_messages.html @@ -0,0 +1,9 @@ +{%- with messages = get_flashed_messages(with_categories=true) -%} + {% if messages %} + <ul class="flashes"> + {% for category, message in messages %} + <li class="{{ category }}">{{ message }}</li> + {% endfor %} + </ul> + {% endif %} +{%- endwith %}
\ No newline at end of file diff --git a/wqflask/wqflask/templates/security/register_user.html b/wqflask/wqflask/templates/security/register_user.html new file mode 100644 index 00000000..af87f810 --- /dev/null +++ b/wqflask/wqflask/templates/security/register_user.html @@ -0,0 +1,45 @@ +{% from "security/_macros.html" import render_field_with_errors, render_field %} +{% extends "base.html" %} +{% include "security/_messages.html" %} +{% block content %} +<body> + <div class="container"> + <div class="content"> + <div class="row"> + <div class="login-form"> + <h2>Register</h2> + <form action="{{ url_for_security('register') }}" method="POST" name="register_user_form"> + <fieldset> + <div class="clearfix"> + {{ render_field_with_errors(register_user_form.email) }} + </div> + <div class="clearfix"> + {{ render_field_with_errors(register_user_form.password) }} + </div> + {% if register_user_form.password_confirm %} + <div class="clearfix"> + {{ render_field_with_errors(register_user_form.password_confirm) }} + </div> + {% endif %} + {{ render_field(register_user_form.submit) }} + </fieldset> + </form> + </div> + </div> + </div> + </div> +</body> + +{% include "security/_menu.html" %} + +{% endblock %} + +<!--<form action="{{ url_for_security('register') }}" method="POST" name="register_user_form"> + {{ register_user_form.hidden_tag() }} + {{ render_field_with_errors(register_user_form.email) }} + {{ render_field_with_errors(register_user_form.password) }} + {% if register_user_form.password_confirm %} + {{ render_field_with_errors(register_user_form.password_confirm) }} + {% endif %} + {{ render_field(register_user_form.submit) }} +</form>-->
\ No newline at end of file |