-
-
Save joshfinnie/5cfbe51a80914da1aebe to your computer and use it in GitHub Desktop.
Flask Sign up/Log in Template
This file contains 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 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()]) |
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
thanks for sharing, very lightweight and useful