Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions backend/app/models.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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):
Expand All @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down