-
-
Save varundey/ff6e1c0ab8299122a1d1130b02e973a7 to your computer and use it in GitHub Desktop.
Simple flask app with user login, registration based on twitters bootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template | |
from flask.ext.security import SQLAlchemyUserDatastore, Security | |
from flask.ext.sqlalchemy import SQLAlchemy | |
from flask.ext.bootstrap import Bootstrap | |
from flask_mail import Mail | |
from flask.ext.security import UserMixin, RoleMixin | |
app = Flask(__name__) | |
app.config.update( | |
DEBUG=True, | |
SQLALCHEMY_DATABASE_URI='sqlite:///:memory:', | |
SECRET_KEY='James Bond', | |
SECURITY_REGISTERABLE=True, | |
) | |
db = SQLAlchemy(app) | |
Bootstrap(app) | |
Mail(app) | |
roles_users = db.Table('roles_users', db.Column('user_id', db.Integer(), | |
db.ForeignKey('user.id')), | |
db.Column('role_id', db.Integer(), | |
db.ForeignKey('role.id'))) | |
class Role(db.Model, RoleMixin): | |
id = db.Column(db.Integer(), primary_key=True) | |
name = db.Column(db.String(80), unique=True) | |
description = db.Column(db.String(255)) | |
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)) | |
active = db.Column(db.Boolean()) | |
confirmed_at = db.Column(db.DateTime()) | |
roles = db.relationship('Role', secondary=roles_users, | |
backref=db.backref('users', lazy='dynamic')) | |
user_datastore = SQLAlchemyUserDatastore(db, User, Role) | |
Security(app, user_datastore) | |
@app.before_first_request | |
def setupDatabase(): | |
db.create_all() | |
@app.route('/') | |
def index(): | |
return render_template('index_alternative.html') | |
if __name__ == '__main__': | |
app.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "bootstrap_responsive.html" %} | |
{% import "bootstrap_wtf.html" as wtf %} | |
{% block body_content %} | |
<div class="container-fluid"> | |
{% block container %} | |
{% endblock %} | |
</div> | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "base_layout.html" %} | |
{% block container %} | |
<div class="row-fluid"> | |
<div class="span12"> | |
<h1>Login</h1> | |
<form class="form form-horizontal" action="{{ url_for_security('login') }}" method="POST" name="login_user_form"> | |
{{ login_user_form.hidden_tag() }} | |
{{ wtf.horizontal_field(login_user_form.email) }} | |
{{ wtf.horizontal_field(login_user_form.password) }} | |
{{ wtf.horizontal_field(login_user_form.remember) }} | |
<div class="controls"> | |
<button class="btn btn-primary" type="submit">Login</button> | |
</div> | |
</form> | |
</div> | |
</div> | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "base_layout.html" %} | |
{% block container %} | |
<div class="row-fluid"> | |
<div class="span12"> | |
<h1>Register</h1> | |
<form class="form form-horizontal" action="{{ url_for_security('register') }}" method="POST" name="register_user_form"> | |
{{ register_user_form.hidden_tag() }} | |
{{ wtf.horizontal_field(register_user_form.email) }} | |
{{ wtf.horizontal_field(register_user_form.password) }} | |
{% if register_user_form.password_confirm %} | |
{{ wtf.horizontal_field(register_user_form.password_confirm) }} | |
{% endif %} | |
<div class="controls"> | |
<button class="btn btn-primary" type="submit">Register</button> | |
</div> | |
</form> | |
</div> | |
</div> | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blinker==1.2 | |
Flask-BasicAuth==0.1.0 | |
Flask-Bootstrap==2.2.1-1 | |
Flask-Login==0.1.3 | |
Flask-Mail==0.7.3 | |
Flask-Principal==0.3.3 | |
Flask-Script==0.5.1 | |
Flask-Security==1.5.0 | |
Flask-SQLAlchemy==0.16 | |
Flask-Testing==0.4 | |
Flask-WTF==0.8 | |
Flask==0.9 | |
gunicorn==0.15.0 | |
itsdangerous==0.17 | |
Jinja2==2.6 | |
mock==1.0.1 | |
nose==1.2.1 | |
passlib==1.6.1 | |
Pattern==2.4 | |
py==1.4.12 | |
python-termstyle==0.1.10 | |
readline==6.2.4.1 | |
rednose==0.3.3 | |
SQLAlchemy==0.7.9 | |
twill==0.9 | |
virtualenv==1.8.2 | |
Werkzeug==0.8.3 | |
WTForms==1.0.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment