Accept Black formatting recommendations

This commit is contained in:
Parker M. 2024-08-09 12:16:57 -05:00
parent 770ee7d438
commit e57b07a146
No known key found for this signature in database
GPG Key ID: 95CD2E0C7E329F2A
2 changed files with 45 additions and 36 deletions

View File

@ -14,59 +14,65 @@ dotenv.load_dotenv()
webhook_url = os.getenv("WEBHOOK_URL") webhook_url = os.getenv("WEBHOOK_URL")
hmac_key = random.randbytes(500) hmac_key = random.randbytes(500)
@app.route('/', methods=['GET'])
@app.route("/", methods=["GET"])
def index(): def index():
return flask.render_template('index.html') return flask.render_template("index.html")
@app.route('/about', methods=['GET'])
@app.route("/about", methods=["GET"])
def about(): def about():
return flask.render_template('about.html') return flask.render_template("about.html")
@app.route('/contact', methods=['GET', 'POST'])
@app.route("/contact", methods=["GET", "POST"])
def contact(): def contact():
if flask.request.method == 'GET': if flask.request.method == "GET":
return flask.render_template('contact.html') return flask.render_template("contact.html")
if flask.request.method == 'POST': if flask.request.method == "POST":
try: try:
# Decode payload # Decode payload
data = json.loads(base64.b64decode(flask.request.form['altcha']).decode()) data = json.loads(base64.b64decode(flask.request.form["altcha"]).decode())
# Validate algorithm # Validate algorithm
if data['algorithm'] != 'SHA-256': if data["algorithm"] != "SHA-256":
return flask.render_template('contact.html', error=True) return flask.render_template("contact.html", error=True)
# Validate challenge # Validate challenge
expected_challenge = hashlib.sha256( expected_challenge = hashlib.sha256(
(data['salt'] + str(data['number'])).encode() (data["salt"] + str(data["number"])).encode()
).hexdigest() ).hexdigest()
if data['challenge'] != expected_challenge: if data["challenge"] != expected_challenge:
return flask.render_template('contact.html', error=True) return flask.render_template("contact.html", error=True)
# Validate signature # Validate signature
signature = hmac.new(hmac_key, data['challenge'].encode(), hashlib.sha256).hexdigest() signature = hmac.new(
if data['signature'] != signature: hmac_key, data["challenge"].encode(), hashlib.sha256
return flask.render_template('contact.html', error=True) ).hexdigest()
if data["signature"] != signature:
return flask.render_template("contact.html", error=True)
# All checks passed, send off form data # All checks passed, send off form data
name = flask.request.form['name'] name = flask.request.form["name"]
email = flask.request.form['email'] email = flask.request.form["email"]
message = flask.request.form['message'] message = flask.request.form["message"]
# Send the contact form to Discord via a webhook # Send the contact form to Discord via a webhook
webhook = discord.SyncWebhook.from_url(webhook_url) webhook = discord.SyncWebhook.from_url(webhook_url)
embed = discord.Embed( embed = discord.Embed(
title='New Message', title="New Message",
description=f"**Name:** ` {name} `\n**Email:** ` {email} `\n**Message:** ` {message} `", description=f"**Name:** ` {name} `\n**Email:** ` {email} `\n**Message:** ` {message} `",
color=0x85C0F7 color=0x85C0F7,
) )
webhook.send(embed=embed) webhook.send(embed=embed)
return flask.render_template('contact.html', success=True) return flask.render_template("contact.html", success=True)
# If any error happens for any reason, return the contact page with error # If any error happens for any reason, return the contact page with error
except: except:
return flask.render_template('contact.html', error=True) return flask.render_template("contact.html", error=True)
@app.route('/altcha-challenge', methods=['GET'])
@app.route("/altcha-challenge", methods=["GET"])
def altcha_challenge(): def altcha_challenge():
salt = secrets.token_urlsafe(25) salt = secrets.token_urlsafe(25)
secret_number = random.randint(10000, 50000) secret_number = random.randint(10000, 50000)
@ -77,19 +83,21 @@ def altcha_challenge():
signature = hmac.new(hmac_key, challenge.encode(), hashlib.sha256).hexdigest() signature = hmac.new(hmac_key, challenge.encode(), hashlib.sha256).hexdigest()
response = { response = {
'algorithm': 'SHA-256', "algorithm": "SHA-256",
'challenge': challenge, "challenge": challenge,
'salt': salt, "salt": salt,
'signature': signature "signature": signature,
} }
return flask.jsonify(response) return flask.jsonify(response)
@app.route('/pgp', methods=['GET'])
def pgp():
return flask.render_template('pgp.html')
@app.route('/parker.asc', methods=['GET']) @app.route("/pgp", methods=["GET"])
def pgp():
return flask.render_template("pgp.html")
@app.route("/parker.asc", methods=["GET"])
def parker(): def parker():
# Send the file to download # Send the file to download
return flask.send_file('static/parker.asc', as_attachment=True) return flask.send_file("static/parker.asc", as_attachment=True)

5
run.py
View File

@ -1,5 +1,6 @@
from app.views import app as application from app.views import app as application
app=application
if __name__ == '__main__': app = application
if __name__ == "__main__":
application.run(port="4343") application.run(port="4343")