From e57b07a1460b7716660b7d8a6747910f587642e8 Mon Sep 17 00:00:00 2001 From: Parker Date: Fri, 9 Aug 2024 12:16:57 -0500 Subject: [PATCH] Accept Black formatting recommendations --- app/views.py | 76 +++++++++++++++++++++++++++++----------------------- run.py | 5 ++-- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/app/views.py b/app/views.py index af8ea55..58d219c 100644 --- a/app/views.py +++ b/app/views.py @@ -14,59 +14,65 @@ dotenv.load_dotenv() webhook_url = os.getenv("WEBHOOK_URL") hmac_key = random.randbytes(500) -@app.route('/', methods=['GET']) + +@app.route("/", methods=["GET"]) 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(): - 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(): - if flask.request.method == 'GET': - return flask.render_template('contact.html') + if flask.request.method == "GET": + return flask.render_template("contact.html") - if flask.request.method == 'POST': + if flask.request.method == "POST": try: # Decode payload - data = json.loads(base64.b64decode(flask.request.form['altcha']).decode()) + data = json.loads(base64.b64decode(flask.request.form["altcha"]).decode()) # Validate algorithm - if data['algorithm'] != 'SHA-256': - return flask.render_template('contact.html', error=True) + if data["algorithm"] != "SHA-256": + return flask.render_template("contact.html", error=True) # Validate challenge expected_challenge = hashlib.sha256( - (data['salt'] + str(data['number'])).encode() + (data["salt"] + str(data["number"])).encode() ).hexdigest() - if data['challenge'] != expected_challenge: - return flask.render_template('contact.html', error=True) + if data["challenge"] != expected_challenge: + return flask.render_template("contact.html", error=True) # Validate signature - signature = hmac.new(hmac_key, data['challenge'].encode(), hashlib.sha256).hexdigest() - if data['signature'] != signature: - return flask.render_template('contact.html', error=True) + signature = hmac.new( + hmac_key, data["challenge"].encode(), hashlib.sha256 + ).hexdigest() + if data["signature"] != signature: + return flask.render_template("contact.html", error=True) # All checks passed, send off form data - name = flask.request.form['name'] - email = flask.request.form['email'] - message = flask.request.form['message'] + name = flask.request.form["name"] + email = flask.request.form["email"] + message = flask.request.form["message"] # Send the contact form to Discord via a webhook webhook = discord.SyncWebhook.from_url(webhook_url) embed = discord.Embed( - title='New Message', + title="New Message", description=f"**Name:** ` {name} `\n**Email:** ` {email} `\n**Message:** ` {message} `", - color=0x85C0F7 + color=0x85C0F7, ) 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 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(): salt = secrets.token_urlsafe(25) secret_number = random.randint(10000, 50000) @@ -77,19 +83,21 @@ def altcha_challenge(): signature = hmac.new(hmac_key, challenge.encode(), hashlib.sha256).hexdigest() response = { - 'algorithm': 'SHA-256', - 'challenge': challenge, - 'salt': salt, - 'signature': signature + "algorithm": "SHA-256", + "challenge": challenge, + "salt": salt, + "signature": signature, } 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(): # Send the file to download - return flask.send_file('static/parker.asc', as_attachment=True) \ No newline at end of file + return flask.send_file("static/parker.asc", as_attachment=True) diff --git a/run.py b/run.py index 723e5a8..ed0d2b2 100644 --- a/run.py +++ b/run.py @@ -1,5 +1,6 @@ from app.views import app as application -app=application -if __name__ == '__main__': +app = application + +if __name__ == "__main__": application.run(port="4343")