(feat): Basic user auth

This commit is contained in:
Blake Ridgway 2024-12-17 14:23:38 -06:00
parent e5976d3c8d
commit de460fbcbc
6 changed files with 90 additions and 9 deletions

25
models/user.py Normal file
View file

@ -0,0 +1,25 @@
from models import db, bcrypt
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
password_hash = db.Column(db.String(128), nullable=False)
@staticmethod
def create_user(username, password):
"""Create a new user with a hashed password"""
password_hash = bcrypt.generate_password_hash(password).decode('utf-8')
new_user = User(username=username, password_hash=password_hash)
db.session.add(new_user)
db.session.commit()
return new_user
@staticmethod
def verify_user(username, password):
"""Verify user creds"""
user = User.query.filter_by(username=username).first()
if user and bcrypt.check_password_hash(user.password_hash, password):
return user
return None