Contact Me
+Got a question or want to talk about something on this site? Drop me a message below:
+ + + {% if user_message is not none %} +{{ user_message }}
+ {% endif %} +diff --git a/src/contact.py b/src/contact.py
new file mode 100644
index 0000000..7774c10
--- /dev/null
+++ b/src/contact.py
@@ -0,0 +1,62 @@
+#!/usr/bin/python3
+
+from index import app
+from os import environ
+from flask import request, render_template
+from requests import post, get
+from uuid import uuid4
+from textwrap import dedent
+
+def validate_turnstile(response: str, ip: str) -> bool:
+ turnstile_secret = environ['TURNSTILE_SECRET']
+ cf_response = post(
+ url='https://challenges.cloudflare.com/turnstile/v0/siteverify',
+ data={
+ 'secret': turnstile_secret,
+ 'response': response,
+ 'remoteip': ip,
+ 'idempotency_key': uuid4()
+ }
+ ).json()
+
+ return cf_response.get('success', False)
+
+def send_to_discord(form: dict) -> bool:
+ try:
+ discord_hook = environ['DISCORD_WEBHOOK']
+ except:
+ return False
+ discord_msg = dedent(
+ f'''
+ __**New Contact Form Response**__
+
+ **From:** {form.get('name')} <{form.get('email')}>
+
+ ''')
+ if form.get("message") == '':
+ discord_msg += '*No Message*'
+ else:
+ discord_msg += f'>>> {form.get("message")}'
+ discord_response = post(
+ url=discord_hook,
+ data={
+ 'username': form.get('name'),
+ 'content': discord_msg
+ }
+ ).status_code
+
+ if discord_response == 204:
+ return True
+ return False
+
+@app.route('/contact/', methods=('GET', 'POST'))
+def contact():
+ if request.method == 'POST':
+ if not validate_turnstile(request.form['cf-turnstile-response'], request.remote_addr):
+ return render_template('contact.html', error=True, user_message='You appear to be a robot.')
+ send_result = send_to_discord(request.form)
+ if send_result:
+ return render_template('contact.html', user_message='Your message has been sent!')
+ return render_template('contact.html', error=True, user_message='An error occurred.')
+ else:
+ return render_template('contact.html')
diff --git a/src/index.py b/src/index.py
index 7efbddc..51a84c8 100644
--- a/src/index.py
+++ b/src/index.py
@@ -5,6 +5,7 @@ from flask import Flask, render_template, Response
app = Flask(__name__)
import projects
+import contact
@app.route('/')
def index():
diff --git a/src/requirements.txt b/src/requirements.txt
index e2d8dd1..f3b6919 100644
--- a/src/requirements.txt
+++ b/src/requirements.txt
@@ -3,3 +3,4 @@ flask-markdown>=0.3
markdown>=3.4.1
beautifulsoup4>=4.11.1
python-frontmatter>=1.1.0
+requests>=2.32.3
diff --git a/src/static/style/desktop.css b/src/static/style/desktop.css
index e77c0f5..9d98ded 100644
--- a/src/static/style/desktop.css
+++ b/src/static/style/desktop.css
@@ -54,4 +54,9 @@
width: fit-content;
padding-right: 20px;
}
+
+ #logo-container{
+ position: absolute;
+ height: 25vh;
+ }
}
\ No newline at end of file
diff --git a/src/static/style/mobile.css b/src/static/style/mobile.css
index 8606853..8dcd1f1 100644
--- a/src/static/style/mobile.css
+++ b/src/static/style/mobile.css
@@ -30,6 +30,7 @@ footer{
width: 100%;
justify-content: center;
display: flex;
+ align-items: center;
}
#logo{
@@ -167,4 +168,39 @@ a{
.article-category:hover{
text-decoration: underline;
+}
+
+#contact-main{
+ padding: 20px 10px 0 10px;
+ min-height: 65vh;
+}
+
+#contact-main>h2 {
+ margin-top: 0;
+}
+
+input, textarea{
+ display: block;
+ padding: 10px;
+ margin-bottom: 20px;
+ background-color: #4c4c4c;
+ border-radius: 10px;
+ border:none;
+ color: white;
+ width: 100%;
+}
+
+label{
+ line-height: 2rem;
+}
+
+.cf-turnstile{
+ width: fit-content;
+ padding: 10px 0 10px 0;
+ margin-left: auto;
+ margin-right: auto;
+}
+
+#contact-error{
+ color: red;
}
\ No newline at end of file
diff --git a/src/templates/contact.html b/src/templates/contact.html
new file mode 100644
index 0000000..bc0c72b
--- /dev/null
+++ b/src/templates/contact.html
@@ -0,0 +1,20 @@
+{% include 'header.html' %}
+ Got a question or want to talk about something on this site? Drop me a message below: {{ user_message }}Contact Me
+