diff --git a/backend/app/models.py b/backend/app/models.py index 128d765..0f8d1a0 100644 --- a/backend/app/models.py +++ b/backend/app/models.py @@ -1,6 +1,7 @@ from . import db import uuid from sqlalchemy.dialects.postgresql import UUID +from werkzeug.security import generate_password_hash, check_password_hash from datetime import datetime @@ -10,6 +11,7 @@ class UserMixin(object): phone_number = db.Column(db.String(64), nullable=False) email_address = db.Column(db.String(64), nullable=False) username = db.Column(db.String(64), nullable=False) + password = db.Column(db.Text, nullable=False) @property def serialize(self): @@ -21,6 +23,17 @@ def serialize(self): "username": self.username, } + @property + def password(self): + raise AttributeError("password is not a readable attribute") + + @password.setter + def password(self, password): + self.password_hash = generate_password_hash(password) + + def verify_password(self, password): + return check_password_hash(self.password_hash, password) + class Volunteer(UserMixin, db.Model): __tablename__ = "volunteers" diff --git a/backend/requirements.txt b/backend/requirements.txt index 9bd1e82..34be9b9 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -2,6 +2,7 @@ alembic==1.7.5 click==8.0.3 Flask==1.1.2 Flask-Cors==3.0.10 +Flask-JWT-Extended==4.3.1 Flask-Migrate==2.5.3 Flask-Script==2.0.6 Flask-SQLAlchemy==2.5.1 @@ -12,6 +13,7 @@ Jinja2==3.0.3 Mako==1.1.6 MarkupSafe==2.0.1 psycopg2==2.9.2 +PyJWT==2.3.0 six==1.16.0 SQLAlchemy==1.4.28 Werkzeug==2.0.2