Users are allowed to register now

This includes sending a welcome email.
This commit is contained in:
Joachim Lusiardi 2016-04-19 07:39:17 +02:00
parent 2e0fc3b772
commit 1240a3c64b
6 changed files with 37 additions and 10 deletions

View File

@ -7,5 +7,6 @@ RUN pip3 install -r /requirements.txt; \
ADD app /app ADD app /app
VOLUME ["/data"] VOLUME ["/data"]
VOLUME ["/app/config]
EXPOSE 5000 EXPOSE 5000
ENTRYPOINT python3 /app/main.py ENTRYPOINT python3 /app/main.py

View File

@ -3,6 +3,14 @@
## build ## build
`docker build --tag=$(basename $PWD) .` `docker build --tag=$(basename $PWD) .`
## general configuration
Look at *app/config/email.py.example** for the configuration of the
parameters required for sending emails. Copy the file as *email.py* to
a folder that will serve as configuration directory and fill in the
information. The directory will be used as volume during container
operation.
## run in development ## run in development
Include the development version of the code as volume, so the app gets Include the development version of the code as volume, so the app gets
@ -10,7 +18,7 @@ reloaded automatically. The sqlite file will be stored in *tmp* so it
can be inspected with tools like *sqlite3*. The switch *DEBUG* enables can be inspected with tools like *sqlite3*. The switch *DEBUG* enables
debugging during development. debugging during development.
`docker run --name rollerverbrauch -ti -v `pwd`/app:/app -v /tmp/pitstops/:/data -e DEBUG=True -p 5000:5000 rollerverbrauch` `docker run --rm --name rollerverbrauch -ti -v `pwd`/app:/app -v `pwd`/../rollerverbrauch_config:/app/config -v /tmp/pitstops/:/data -e DEBUG=True -p 5000:5000 rollerverbrauch`
## run in production ## run in production
`docker run --name pitstops -d -v /data/pitstops/:/data -p 80:5000 rollerverbrauch` `docker run --name pitstops -d -v /data/pitstops/:/data -v /configs/pitstops/:/app/config -p 80:5000 rollerverbrauch`

View File

@ -1,5 +1,4 @@
from datetime import date from datetime import date
from datetime import datetime
from flask import Flask from flask import Flask
from flask import render_template, make_response from flask import render_template, make_response
from flask import request, redirect, g from flask import request, redirect, g
@ -7,9 +6,7 @@ from flask import url_for
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
from flask.ext.security import Security, SQLAlchemyUserDatastore, \ from flask.ext.security import Security, SQLAlchemyUserDatastore, \
UserMixin, RoleMixin, login_required, utils UserMixin, RoleMixin, login_required, utils
import uuid from flask.ext.mail import Mail, Message
import hashlib
from functools import wraps
from flask_wtf import Form from flask_wtf import Form
from wtforms import DateField, IntegerField, DecimalField from wtforms import DateField, IntegerField, DecimalField
from wtforms.validators import DataRequired, ValidationError from wtforms.validators import DataRequired, ValidationError
@ -23,8 +20,12 @@ db = SQLAlchemy(app)
app.config['SECRET_KEY'] = 'development key' app.config['SECRET_KEY'] = 'development key'
app.config['SECURITY_PASSWORD_HASH'] = 'pbkdf2_sha512' app.config['SECURITY_PASSWORD_HASH'] = 'pbkdf2_sha512'
app.config['SECURITY_PASSWORD_SALT'] = 'xxxxxxxxxxxxxxxxxxxxxx' app.config['SECURITY_PASSWORD_SALT'] = 'xxxxxxxxxxxxxxxxxxxxxx'
app.config['SECURITY_REGISTERABLE'] = True
app.config['SECURITY_EMAIL_SENDER'] = 'pitstops@lusiardi.de'
app.config.from_object('config.email')
app.config.from_object(__name__) app.config.from_object(__name__)
mail = Mail(app)
roles_users = db.Table('roles_users', roles_users = db.Table('roles_users',
db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('user_id', db.Integer(), db.ForeignKey('user.id')),
@ -77,6 +78,7 @@ class Pitstop(db.Model):
user_datastore = SQLAlchemyUserDatastore(db, User, Role) user_datastore = SQLAlchemyUserDatastore(db, User, Role)
security = Security(app, user_datastore) security = Security(app, user_datastore)
@app.before_first_request @app.before_first_request
def before_first_request(): def before_first_request():
db.create_all() db.create_all()

View File

@ -1,9 +1,12 @@
{% macro navigation() -%} {% macro navigation() -%}
<li><a href='{{ url_for('create_pit_stop_form') }}'>Create Pitstop</a></li>
<li><a href='{{ url_for('get_statistics') }}'>Statistics</a></li>
<li><a href='{{ url_for('get_manual') }}'>Manual</a></li>
{% if current_user.email %} {% if current_user.email %}
<li><a href='{{ url_for('create_pit_stop_form') }}'>Create Pitstop</a></li>
<li><a href='{{ url_for('get_statistics') }}'>Statistics</a></li>
<li><a href='{{ url_for('get_manual') }}'>Manual</a></li>
<li><a href='{{ url_for('security.logout') }}'>Logout</a></li> <li><a href='{{ url_for('security.logout') }}'>Logout</a></li>
{% else %}
<li><a href='{{ url_for('security.login') }}'>Login</a></li>
<li><a href='{{ url_for('security.register') }}'>Register</a></li>
{% endif %} {% endif %}
{%- endmacro %} {%- endmacro %}

View File

@ -10,5 +10,4 @@
{{ render_field(login_user_form.next) }} {{ render_field(login_user_form.next) }}
{{ render_field(login_user_form.submit) }} {{ render_field(login_user_form.submit) }}
</form> </form>
{% include "security/_menu.html" %}
{% endblock %} {% endblock %}

View File

@ -0,0 +1,14 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field %}
{% block body %}
<form class='form-horizontal' 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>
{% endblock %}