Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3 Register User form #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions jobs_board/core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from flask import Flask
from flask.ext.foundation import Foundation
from flask.ext.mail import Mail
from flask.ext.security import Security, SQLAlchemyUserDatastore
from flask_security import Security, SQLAlchemyUserDatastore
from flask.ext.sqlalchemy import SQLAlchemy

from .forms import ExtendedRegisterForm

db = SQLAlchemy()
foundation = Foundation()
Expand All @@ -17,7 +18,11 @@ def create_app():
foundation.init_app(app)
mail.init_app(app)
from .users.models import Role, User
security.init_app(app, SQLAlchemyUserDatastore(db, User, Role))
security.init_app(
app,
SQLAlchemyUserDatastore(db, User, Role),
register_form=ExtendedRegisterForm,
)
from .jobs.views import blueprint as jobs
app.register_blueprint(jobs)
return app
8 changes: 8 additions & 0 deletions jobs_board/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
from flask.ext.wtf import Form
from flask_security import RegisterForm
from wtforms import StringField
from wtforms.validators import DataRequired
from wtforms_alchemy import model_form_factory

ModelForm = model_form_factory(Form)

class ExtendedRegisterForm(RegisterForm):
username = StringField('Username', [DataRequired()])
first_name = StringField('First Name', [DataRequired()])
last_name = StringField('Last Name', [DataRequired()])
2 changes: 2 additions & 0 deletions jobs_board/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
SECURITY_CHANGEABLE = True
SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/jobsboard'
SECRET_KEY = 'super-secret' # NOTE: this should obviously be changed
MAIL_DEFAULT_SENDER = '[email protected]'
MAIL_SUPPRESS_SEND = True
13 changes: 12 additions & 1 deletion jobs_board/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
{% extends "foundation_base.html" %}

{% macro render_field(field) %}
<dt>{{ field.label }}
<dd>{{ field(**kwargs)|safe }}
{% if field.errors %}
<ul class=errors>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</dd>
{% endmacro %}
{% block title %}{{ title|default('Jobs') }}{% endblock %}

{% block body_content %}
Expand Down
12 changes: 10 additions & 2 deletions jobs_board/templates/security/register_user.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{% extends "security/base.html" %}
{% from "foundation_wtf.html" import quick_form %}

{% block body_content %}
<div class="row">
<div class="large-4 columns large-offset-4 end">
{{ quick_form(register_user_form, action=url_for('security.register'), buttons=[]) }}
<form action="{{ url_for('security.register') }}" method="POST">
{{ register_user_form.csrf_token }}
{{ render_field(register_user_form.first_name) }}
{{ render_field(register_user_form.last_name) }}
{{ render_field(register_user_form.username) }}
{{ render_field(register_user_form.email) }}
{{ render_field(register_user_form.password) }}
{{ render_field(register_user_form.password_confirm) }}
{{ render_field(register_user_form.submit) }}
</form>
</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion jobs_board/users/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask.ext.security import RoleMixin, UserMixin
from flask_security import RoleMixin, UserMixin
from ..core import db

roles_users = db.Table(
Expand Down