secret
Last active

Flask Sign up/Log in Template

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
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()])

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.