Skip to content

Commit

Permalink
Add DiscordUser database table for relations
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiro47 committed Mar 13, 2020
1 parent a7de834 commit 75207e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/discord_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# Local module imports
from .discord_oauth import Discord_Oauth
from .discord_database import DiscordUser

# Global variables
# Used primarily due to flask routed functions being unable to use class "self" reflections
Expand Down Expand Up @@ -147,6 +148,9 @@ def load(app):
base_asset_path = os.path.dirname(os.path.realpath(__file__)) + "/../assets/"
register_plugin_assets_directory(app, base_path=base_asset_path)

# DB Setup
app.db.create_all()

# Registration
override_page(base_asset_path, "login.html")
override_page(base_asset_path, "users/private.html")
Expand Down
19 changes: 19 additions & 0 deletions src/discord_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from CTFd.models import db


class DiscordUser(db.Model):
__tablename__ = "discorduser"
__table_args__ = (db.UniqueConstraint("id"), {})

# Core variables
id = db.Column(db.BigInteger, primary_key=True, unique=True) # Discord ID, int64
# Discord Username 2-32 characters
username = db.Column(db.String(128), db.ForeignKey("users.name", ondelete="CASCADE"))
discriminator = db.Column(db.Integer) # Discriminator ID, 4 digits
avatar_hash = db.Column(db.String(256)) # Avatar hash, no known limit, 33 from samples
mfa_enabled = db.Column(db.Boolean)
verified = db.Column(db.Boolean)
email = db.Column(db.String(256))

def __init__(self, **kwargs):
super(DiscordUser, self).__init__(**kwargs)

0 comments on commit 75207e3

Please sign in to comment.