diff --git a/requirements.txt b/requirements.txt index 8051e01..35549e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,10 +3,12 @@ boto3 cryptography docopt firebase-admin +flask-login flask-sqlalchemy grpcio-status gunicorn pip-chill +pycryptodome pyrebase python-dotenv typing-extensions diff --git a/src/__init__.py b/src/__init__.py index 68f8766..1c38246 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -2,6 +2,7 @@ from config import Config from src.extensions import db +from src.extensions import login_manager from dotenv import load_dotenv @@ -23,6 +24,8 @@ def create_app(config=Config()): with app.app_context(): db.create_all() + login_manager.init_app(app) + from src.clubs import bp as clubs_bp app.register_blueprint(blueprint=clubs_bp, url_prefix='/clubs') diff --git a/src/extensions.py b/src/extensions.py index 37a2561..9a2d650 100644 --- a/src/extensions.py +++ b/src/extensions.py @@ -1,7 +1,9 @@ from flask_sqlalchemy import SQLAlchemy from venmo_api import Client +from flask_login import LoginManager import os db = SQLAlchemy() client = Client(access_token=os.environ["VENMO_TOKEN"], ) +login_manager = LoginManager() diff --git a/src/models/club.py b/src/models/club.py index 220e4cc..8f77d9c 100644 --- a/src/models/club.py +++ b/src/models/club.py @@ -1,4 +1,4 @@ -import json +from flask_login import UserMixin from src import db from .fundraiser import Fundraiser @@ -10,7 +10,7 @@ ) -class Club(db.Model): +class Club(db.Model, UserMixin): __tablename__ = 'club' id = db.Column(db.Integer, primary_key=True) @@ -22,6 +22,24 @@ class Club(db.Model): fundraisers = db.relationship('Fundraiser', cascade='delete') + authenticated = db.Column(db.Boolean, nullable=False, default=False) + + @property + def is_authenticated(self): + """ + If the user is authenticated. + :return: True if authenticated. False otherwise. + """ + return self.authenticated + + @property + def is_anonymous(self): + """ + Return whether the student cna be anonymous + :return: False, because anonymity is not supported + """ + return False + def serialize(self, exclude_venmo_username=False, simplified=False): """ A serialized the output for the club entry. diff --git a/src/models/student.py b/src/models/student.py index ffb9486..847787d 100644 --- a/src/models/student.py +++ b/src/models/student.py @@ -1,8 +1,10 @@ +from flask_login import UserMixin + from src import db from .club import student_club_association_table -class Student(db.Model): +class Student(db.Model, UserMixin): __tablename__ = 'student' id = db.Column(db.Integer, primary_key=True) @@ -11,6 +13,24 @@ class Student(db.Model): venmo_username = db.Column(db.String, nullable=False, unique=True) clubs = db.relationship("Club", secondary=student_club_association_table, back_populates='members') + authenticated = db.Column(db.Boolean, nullable=False, default=False) + + @property + def is_authenticated(self): + """ + If the user is authenticated. + :return: True if authenticated. False otherwise. + """ + return self.authenticated + + @property + def is_anonymous(self): + """ + Return whether the student cna be anonymous + :return: False, because anonymity is not supported + """ + return False + def serialize(self, exclude_venmo_username=False, simplified=False): """ A serialized the output for the student entry. diff --git a/src/transactions/utils.py b/src/transactions/utils.py new file mode 100644 index 0000000..9d33e29 --- /dev/null +++ b/src/transactions/utils.py @@ -0,0 +1,5 @@ +from src.extensions import client + + +def get_user_by_username(username: str): + user_id = client.user.search_for_users(query=username, username=True)