-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
47 lines (37 loc) · 1.36 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
47
from app import db, login
from datetime import datetime
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
class Contact(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.Text)
email = db.Column(db.Text)
message = db.Column(db.Text)
dateSubmitted = db.Column(db.DateTime)
def __init__(self, name, email, message):
self.name = name
self.email = email
self.message = message
self.dateSubmitted = datetime.today()
class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
email_address = db.Column(db.String(255), unique=True)
name = db.Column(db.String(255))
password_hash = db.Column(db.String(255))
user_level = db.Column(db.Integer)
active = db.Column(db.Boolean)
def set_password (self, password):
self.password_hash = generate_password_hash(password)
def check_password (self, password):
return check_password_hash(self.password_hash, password)
def is_admin(self):
if self.user_level == 2:
return True
else:
return False
def update_details(self, email_address, name):
self.email_address = email_address
self.name = name
@login.user_loader
def load_user(id):
return User.query.get(int(id))