mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-30 11:19:57 +00:00
Added login functionality and login required
This commit is contained in:
19
application/auth/models.py
Normal file
19
application/auth/models.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from application import db
|
||||
from flask_login import UserMixin
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
|
||||
# User model
|
||||
class User(db.Model, UserMixin):
|
||||
__tablename__ = "user"
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
username = db.Column(db.String(150), unique=True, nullable=False)
|
||||
password = db.Column(db.String, nullable=False)
|
||||
|
||||
# Initialize user, prevents red stuff
|
||||
def __init__(self, username: str, password: str, is_admin: bool = False):
|
||||
self.username = username
|
||||
self.password = generate_password_hash(password)
|
||||
|
||||
def check_password(self, password: str):
|
||||
return check_password_hash(self.password, password=password)
|
||||
Reference in New Issue
Block a user