This repository has been archived by the owner on Aug 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
46 lines (37 loc) · 1.45 KB
/
models.py
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
43
44
45
46
# pylint: disable=C0103,C0111
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy, orm
from flask.ext.login import UserMixin
from datetime import datetime
from werkzeug.security import generate_password_hash, check_password_hash
app = Flask("led-movie-visualization")
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db = SQLAlchemy(app)
#db.create_all()
class SessionMixin(object):
def save(self):
self.updated_at = datetime.now()
db.session.add(self)
db.session.commit()
return self
def delete(self):
db.session.delete(self)
db.session.commit()
class User(SessionMixin, UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
login = db.Column(db.String(255), nullable=False, unique=True)
password = orm.deferred(db.Column(db.String(255), nullable=False))
active = db.Column(db.Boolean(), nullable=False, default=True)
created_at = db.Column(db.DateTime(), nullable=False)
updated_at = db.Column(db.DateTime(), nullable=False)
def __init__(self, login, password):
self.login = login
self.password = generate_password_hash(password)
self.created_at = datetime.now()
self.updated_at = datetime.now()
def __repr__(self):
return '<User %r>' % self.id
def check_password(self, password):
return check_password_hash(self.password, password)
def is_active(self):
return self.active