-
Notifications
You must be signed in to change notification settings - Fork 4
/
model.py
64 lines (47 loc) · 1.66 KB
/
model.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from sqlalchemy import func
from werkzeug.security import generate_password_hash, check_password_hash
from app import db, create_app
class User(db.Model):
"""USER
User database code
"""
__tablename__ = "users"
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
username = db.Column(db.String(255), unique=True, nullable=False)
email = db.Column(db.String(255), unique=True, nullable=False)
password = db.Column(db.String(255), nullable=False)
created_at = db.Column(db.DateTime(timezone=True), server_default=func.now())
active = db.Column(db.Boolean(), default=False)
def __init__(self, username, email, password):
self.username = username
self.email = email
self.set_password(password)
def set_password(self, password):
self.password = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.password, password)
@property
def is_authenticated(self):
return True
@property
def is_active(self):
return True
@property
def is_anonymous(self):
return False
def get_id(self):
return str(self.id)
def __repr__(self):
return '<User %r>' % self.username
class HostName(db.Model):
"""HostName
Hostname database code
"""
__tablename__ = "hostnames"
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
hostname = db.Column(db.String(255), unique=False, nullable=False)
def __init__(self, hostname):
self.hostname = hostname
def __repr__(self):
return '%r' % self.hostname
db.create_all(app=create_app())