whole bunch of changes I really should be keeping track of better
Some checks failed
Linter / Lint (3.11) (push) Failing after 37s

This commit is contained in:
SeaswimmerTheFsh 2023-11-25 01:24:05 -05:00
parent 7bd35f2713
commit 9fcb9fbc09
Signed by: cswimr
GPG key ID: 1EBC234EEDA901AE
12 changed files with 453 additions and 123 deletions

View file

@ -1,15 +1,15 @@
import os
from flask import Flask, render_template, redirect, url_for
from flask_discord import DiscordOAuth2Session, requires_authorization, Unauthorized
from flask_discord import DiscordOAuth2Session, requires_authorization, AccessDenied, Unauthorized
from config import load_config
app = Flask(__name__, template_folder="../templates")
app = Flask(__name__, template_folder="templates")
# This code reads the variables set in the site's 'config.json' file.
config = load_config()
app.secret_key = config['secret_key'].encode('UTF-8')
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = str(config['dev'])
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = config['dev']
app.config["DISCORD_CLIENT_ID"] = config['discord']['client_id']
app.config["DISCORD_CLIENT_SECRET"] = config['discord']['client_secret']
app.config["DISCORD_REDIRECT_URI"] = config['webroot'] + "/callback/"
@ -21,35 +21,27 @@ discord = DiscordOAuth2Session(app)
def login():
return discord.create_session()
@app.route("/logout/")
def logout():
discord.revoke()
return redirect(url_for(".index"))
@app.route("/callback/")
def callback():
discord.callback()
return redirect(url_for(".me"))
return redirect(url_for(".index"))
@app.errorhandler(Unauthorized)
@app.errorhandler(AccessDenied)
def redirect_unauthorized(e):
return redirect(url_for("login"))
@app.route("/me/")
@requires_authorization
def me():
user = discord.fetch_user()
return f"""
<html>
<head>
<title>{user.name}</title>
</head>
<body>
<img src='{user.avatar_url}' />
</body>
</html>"""
return redirect(url_for(".index"))
@app.route("/")
def index():
if discord.authorized:
user = discord.fetch_user()
print(user.default_avatar_url, user.username, user.discriminator)
return render_template('index.html', name=config['name'], user=user)
return render_template('index.html', name=config['name'])
@app.route("/hello")

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 -28.5 256 256" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
<g>
<path d="M216.856339,16.5966031 C200.285002,8.84328665 182.566144,3.2084988 164.041564,0 C161.766523,4.11318106 159.108624,9.64549908 157.276099,14.0464379 C137.583995,11.0849896 118.072967,11.0849896 98.7430163,14.0464379 C96.9108417,9.64549908 94.1925838,4.11318106 91.8971895,0 C73.3526068,3.2084988 55.6133949,8.86399117 39.0420583,16.6376612 C5.61752293,67.146514 -3.4433191,116.400813 1.08711069,164.955721 C23.2560196,181.510915 44.7403634,191.567697 65.8621325,198.148576 C71.0772151,190.971126 75.7283628,183.341335 79.7352139,175.300261 C72.104019,172.400575 64.7949724,168.822202 57.8887866,164.667963 C59.7209612,163.310589 61.5131304,161.891452 63.2445898,160.431257 C105.36741,180.133187 151.134928,180.133187 192.754523,160.431257 C194.506336,161.891452 196.298154,163.310589 198.110326,164.667963 C191.183787,168.842556 183.854737,172.420929 176.223542,175.320965 C180.230393,183.341335 184.861538,190.991831 190.096624,198.16893 C211.238746,191.588051 232.743023,181.531619 254.911949,164.955721 C260.227747,108.668201 245.831087,59.8662432 216.856339,16.5966031 Z M85.4738752,135.09489 C72.8290281,135.09489 62.4592217,123.290155 62.4592217,108.914901 C62.4592217,94.5396472 72.607595,82.7145587 85.4738752,82.7145587 C98.3405064,82.7145587 108.709962,94.5189427 108.488529,108.914901 C108.508531,123.290155 98.3405064,135.09489 85.4738752,135.09489 Z M170.525237,135.09489 C157.88039,135.09489 147.510584,123.290155 147.510584,108.914901 C147.510584,94.5396472 157.658606,82.7145587 170.525237,82.7145587 C183.391518,82.7145587 193.761324,94.5189427 193.539891,108.914901 C193.539891,123.290155 183.391518,135.09489 170.525237,135.09489 Z" fill="#5865F2" fill-rule="nonzero">
</path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -0,0 +1,71 @@
body {
background-color: #333;
color: #fff;
font-family: Arial, sans-serif;
}
#menu {
position: fixed;
left: 0;
top: 0;
bottom: 0;
width: 200px;
background-color: #444;
padding: 20px;
}
#menu ul {
list-style-type: none;
padding: 0;
}
#menu li {
margin-bottom: 10px;
}
.txt-danger, .txt-danger:hover, txt-danger:visited, .txt-danger:active {
color: #ff0000 !important;
}
.dropdown-content {
display: none;
position: relative;
background-color: #81B8F9;
margin-left: 10px;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #7289da;}
#logout:hover .dropdown-content {display: block;}
.log-button:hover {background-color: #6C91F6;}
.log-button {
background-color: #7289da;
color: #fff;
border: none;
padding: 3px 5px;
border-radius: 5px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
position: absolute;
right: 0;
margin-right: 20px;
}
.log-button-icon {
border-radius: 50%;
width: 40px;
margin-right: 10px;
}

27
src/templates/hello.html Normal file
View file

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ name }}</title>
<style>
body {
background-color: #36393f;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
h1 {
color: #ffffff;
font-size: 36px;
text-align: center;
}
</style>
</head>
<body>
<h1>{{ name }}</h1>
</body>
</html>

41
src/templates/index.html Normal file
View file

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<title>Audit Log</title>
<link rel="stylesheet" href="{{url_for('static', filename='styles/index.css')}}">
</head>
<body>
<div id="menu">
<ul>
<li>Audit Log</li>
</ul>
</div>
{% if not user %}
<div id="login">
<button id="discord-login" class="log-button" onclick="window.location.href='/login'">
<img src="{{url_for('static', filename='img/discord.svg')}}" alt="Log in with Discord" class="log-button-icon">
Log in with Discord
</button>
</div>
{% elif user %}
<div id = "logout">
<button id="discord-logout" class="log-button">
{% if user.avatar_url %}
<img src="{{user.avatar_url}}" alt="User Avatar" class="log-button-icon">
{% else %}
<img src="{{user.default_avatar_url}}" alt="User Avatar" class="log-button-icon">
{% endif %}
{% if user.discriminator != "0" %}
{{ user.username }}#{{ user.discriminator }}
{% else %}
{{ user.username }}
{% endif %}
<div class="dropdown-content">
<a href="/me">User Info</a>
<a href="/logout" class="txt-danger">Log Out</a>
</div>
</button>
</div>
{% endif %}
</body>
</html>