- Removed hardcoded email address `hello@ciphervance.com` and replaced it with `SENDER_EMAIL` from environment variables. - Added `python-dotenv` to load environment variables from `.env` file for better configuration management. - Removed redundant logging setup and debug statements for cleaner code. - Simplified the `send_email` function by removing unnecessary logging and debug output. - Ensured consistent use of environment variables for SMTP settings and recipient email. This change improves maintainability and security by avoiding hardcoded values and centralizing configuration.
91 lines
No EOL
2.6 KiB
Python
91 lines
No EOL
2.6 KiB
Python
from flask import Blueprint, render_template, request, flash, redirect, url_for
|
|
import smtplib
|
|
from email.mime.text import MIMEText
|
|
from dotenv import load_dotenv
|
|
import os
|
|
|
|
load_dotenv()
|
|
|
|
main = Blueprint('main', __name__)
|
|
|
|
@main.route('/')
|
|
def index():
|
|
return render_template('index.html')
|
|
|
|
@main.route('/services')
|
|
def services():
|
|
return render_template('services.html')
|
|
|
|
@main.route('/pricing')
|
|
def pricing():
|
|
return render_template('pricing.html')
|
|
|
|
@main.route('/solutions')
|
|
def solutions():
|
|
return render_template('solutions.html')
|
|
|
|
@main.route('/about')
|
|
def about():
|
|
return render_template('about.html')
|
|
|
|
@main.route('/privacy-policy')
|
|
def privacy_policy():
|
|
return render_template('privacy.html')
|
|
|
|
@main.route('/terms-of-service')
|
|
def terms_of_service():
|
|
return render_template('termsofservice.html')
|
|
|
|
@main.route('/careers')
|
|
def careers():
|
|
return render_template('careers.html')
|
|
|
|
def send_email(subject, body, recipient):
|
|
"""Sends email, returns True on success, False on failure."""
|
|
try:
|
|
smtp_server = os.getenv('SMTP_SERVER')
|
|
smtp_port = int(os.getenv('SMTP_PORT'))
|
|
smtp_user = os.getenv('SMTP_USER')
|
|
smtp_password = os.getenv('SMTP_PASSWORD')
|
|
sender_email = smtp_user
|
|
|
|
server = smtplib.SMTP_SSL(smtp_server, smtp_port, timeout=10)
|
|
server.set_debuglevel(False)
|
|
server.login(smtp_user, smtp_password)
|
|
|
|
msg = MIMEText(body, "plain", "utf-8")
|
|
msg["Subject"] = subject
|
|
msg["From"] = sender_email
|
|
msg["To"] = recipient
|
|
|
|
server.sendmail(sender_email, recipient, msg.as_string())
|
|
server.quit()
|
|
|
|
return True
|
|
except Exception as e:
|
|
return False
|
|
|
|
@main.route('/contact', methods=['GET', 'POST'])
|
|
def contact():
|
|
if request.method == 'POST':
|
|
name = request.form.get('name')
|
|
email = request.form.get('email')
|
|
message = request.form.get('message')
|
|
|
|
if not name or not email or not message:
|
|
flash('Please fill out all fields.', 'error')
|
|
return redirect(url_for('main.contact'))
|
|
|
|
subject = f"New Contact Form Submission from {name}"
|
|
body = f"Name: {name}\nEmail: {email}\nMessage: {message}"
|
|
|
|
recipient_email = os.getenv('SENDER_EMAIL')
|
|
|
|
if send_email(subject, body, recipient_email):
|
|
flash('Your message has been sent! We will get back to you soon.', 'success')
|
|
else:
|
|
flash('An error occurred while sending your message. Please try again later.', 'error')
|
|
|
|
return redirect(url_for('main.contact'))
|
|
|
|
return render_template('contact.html') |