2017-05-17 20:16:30 +02:00
|
|
|
from os import getenv
|
|
|
|
from flask import Flask
|
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
|
from flask_script import Manager
|
|
|
|
from flask_migrate import Migrate, MigrateCommand
|
2017-05-18 18:25:54 +02:00
|
|
|
from uuid import uuid4
|
2017-05-17 20:16:30 +02:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = getenv('SQLALCHEMY_DATABASE_URI')
|
|
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
|
|
db = SQLAlchemy(app)
|
|
|
|
|
|
|
|
migrate = Migrate(app, db)
|
|
|
|
manager = Manager(app)
|
|
|
|
manager.add_command('db', MigrateCommand)
|
|
|
|
|
|
|
|
|
|
|
|
class User(db.Model):
|
2017-05-18 18:25:54 +02:00
|
|
|
'''
|
|
|
|
Table user
|
|
|
|
'''
|
2017-05-17 20:16:30 +02:00
|
|
|
__tablename__ = 'users'
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
username = db.Column(db.String(30), nullable=False)
|
|
|
|
email = db.Column(db.String(254), nullable=False, unique=True)
|
|
|
|
password = db.Column(db.String(106), nullable=False, unique=False)
|
|
|
|
is_active = db.Column(db.Boolean)
|
|
|
|
token = db.Column(db.String(32), nullable=False, unique=False)
|
|
|
|
|
2017-05-18 18:25:54 +02:00
|
|
|
def __init__(self):
|
2017-05-17 20:16:30 +02:00
|
|
|
self.is_active = False
|
2017-05-18 18:25:54 +02:00
|
|
|
self.token = str(uuid4()).replace('-', '')
|
2017-05-17 20:16:30 +02:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return '<User %r>' % self.username
|
|
|
|
|
2017-05-18 18:25:54 +02:00
|
|
|
|
2017-05-17 20:16:30 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
manager.run()
|