Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhongxuanWang committed Nov 30, 2023
1 parent 089b1ee commit 73588a4
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ boto3
cryptography
docopt
firebase-admin
flask-login
flask-sqlalchemy
grpcio-status
gunicorn
pip-chill
pycryptodome
pyrebase
python-dotenv
typing-extensions
Expand Down
3 changes: 3 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from config import Config
from src.extensions import db
from src.extensions import login_manager

from dotenv import load_dotenv

Expand All @@ -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')

Expand Down
2 changes: 2 additions & 0 deletions src/extensions.py
Original file line number Diff line number Diff line change
@@ -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()
22 changes: 20 additions & 2 deletions src/models/club.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import json
from flask_login import UserMixin

from src import db
from .fundraiser import Fundraiser
Expand All @@ -10,7 +10,7 @@
)


class Club(db.Model):
class Club(db.Model, UserMixin):
__tablename__ = 'club'

id = db.Column(db.Integer, primary_key=True)
Expand All @@ -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.
Expand Down
22 changes: 21 additions & 1 deletion src/models/student.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/transactions/utils.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 73588a4

Please sign in to comment.