Skip to content

Instantly share code, notes, and snippets.

@joshfinnie
Created February 7, 2011 16:57
Show Gist options
  • Star 51 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save joshfinnie/5cfbe51a80914da1aebe to your computer and use it in GitHub Desktop.
Save joshfinnie/5cfbe51a80914da1aebe to your computer and use it in GitHub Desktop.
Flask Sign up/Log in Template
from datetime import datetime
from flask import *
from flaskext.wtf import *
from flaskext.sqlalchemy import *
from werkzeug import generate_password_hash, check_password_hash
app = Flask()
app.config.from_pyfile('app_settings.py')
db = SQLAlchemy(app)
# Standard Databases
class User(db.Model):
__tablename__ = 'users'
uid = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(60))
pwdhash = db.Column(db.String())
email = db.Column(db.String(60))
activate = db.Column(db.Boolean)
created = db.Column(db.DateTime)
def __init__(self, username, password, email):
self.username = username
self.pwdhash = generate_password_hash(password)
self.email = email
self.activate = False
self.created = datetime.utcnow()
def check_password(self, password):
return check_password_hash(self.pwdhash, password)
# Standard Forms
class signup_form(Form):
username = TextField('Username', [validators.Required()])
password = PasswordField('Password', [validators.Required(), validators.EqualTo('confirm', message='Passwords must match')])
confirm = PasswordField('Confirm Password', [validators.Required()])
email = TextField('eMail', [validators.Required()])
accept_tos = BooleanField('I accept the TOS', [validators.Required])
class login_form(Form):
username = TextField('Username', [validators.Required()])
password = TextField('Password', [validators.Required()])
@ohadperry
Copy link

thanks for sharing, very lightweight and useful

@hkst
Copy link

hkst commented May 12, 2015

do you a similar example for sqlite pls?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment