-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
31 lines (27 loc) · 814 Bytes
/
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
from flask_sqlalchemy import SQLAlchemy
from werkzeug import generate_password_hash, check_password_hash
db = SQLAlchemy()
class Admin(db.Model):
'''
Admin class
'''
__tablename__ = 'admin'
uid = db.Column(db.Integer, primary_key = True)
username = db.Column(db.String(120), unique=True)
pwdhash = db.Column(db.String(255))
def __init__(self, username, pwdhash):
'''
Define the variables
'''
self.username = username.lower()
self.set_password(pwdhash)
def set_password(self, pwdhash):
'''
Set Passwords
'''
self.pwdhash = generate_password_hash(pwdhash)
def check_password(self, pwdhash):
'''
Check the passwords
'''
return check_password_hash(self.pwdhash, pwdhash)