Skip to content

Commit

Permalink
Added User Invite to Points System
Browse files Browse the repository at this point in the history
  • Loading branch information
code-wolf-byte committed Sep 3, 2024
1 parent 83e934a commit b5c1c19
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions modules/points/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class User(Base):
name = Column(String, nullable=False)
email = Column(String, nullable=False, unique=True)
academic_standing = Column(String, nullable=False)
major = Column(String, nullable=False)
points = relationship("Points", backref="user", cascade="all, delete-orphan")

def __repr__(self):
Expand Down
40 changes: 37 additions & 3 deletions modules/users/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,53 @@
import re
import os
from flask import Blueprint, jsonify, request
from modules.auth.decoraters import auth_required
from modules.auth.decoraters import auth_required, error_handler
from modules.points.models import User
from modules.users.invite import InvitationSender
from shared import config
from shared import config, db_connect

# Flask Blueprint for users
users_blueprint = Blueprint("users", __name__, template_folder=None, static_folder=None)


@users_blueprint.route("/", methods=["GET"])
def users_index():
return jsonify({"message": "users api"}), 200


@users_blueprint.route("/create", methods=["POST"])
def create_user():
data = request.get_json() # Get JSON data from the request body
name = data.get("name")
email = data.get("email")
asu_id = data.get("asu_id")
standing = data.get("standing")
major = data.get("major")

print(f"Creating {name}, {email}, {standing}, {major}, {asu_id}")
print(f"Type: {type(name)}, {type(email)}, {type(standing)}, {type(major)}, {type(asu_id)}")
# Create user in the database
def add_user_to_db(db_connect, asu_id, name, email, year, major):
db = next(db_connect.get_db())
try:
user = User(asu_id=asu_id, name=name, email=email, academic_standing=year, major=major)
db_user = db_connect.create_user(db, user)
print(
f"Successfully added user: {db_user.name} ({db_user.email}) with ASU ID {db_user.asu_id}"
)
except Exception as e:
print(f"Error adding user: {e}")

finally:
db.close()
print("Database connection closed")

add_user_to_db(db_connect, asu_id, name, email, standing, major)
return jsonify({"message": "User created successfully"}), 201

'''
Deprecatation warning: This function has been deprecated as selenium
is not working properly
'''
@users_blueprint.route("/invite", methods=["POST"])
def invite_users():
email = request.args.get("email")
Expand Down

0 comments on commit b5c1c19

Please sign in to comment.