Feat(SQL, UI): Redesign database with much more detailed command response quality analysis and created successfully loading Dog Command Links page
This commit is contained in:
@@ -1,143 +0,0 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: App Routing
|
||||
Feature: Core - Contact Routes
|
||||
|
||||
Description:
|
||||
Contact Page Controller.
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
from business_objects.api import API
|
||||
from business_objects.project_hub.command import Command
|
||||
from datastores.project_hub.datastore_command import DataStore_Command
|
||||
from forms.contact import Form_Contact
|
||||
from helpers.helper_app import Helper_App
|
||||
from models.model_view_contact import Model_View_Contact
|
||||
from models.model_view_contact_success import Model_View_Contact_Success
|
||||
from models.model_view_home import Model_View_Home
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session, Blueprint, current_app, flash
|
||||
from flask_mail import Mail, Message
|
||||
from extensions import db, oauth, mail
|
||||
from urllib.parse import quote_plus, urlencode
|
||||
from authlib.integrations.flask_client import OAuth
|
||||
from authlib.integrations.base_client import OAuthError
|
||||
from urllib.parse import quote, urlparse, parse_qs
|
||||
import json
|
||||
import base64
|
||||
import hmac
|
||||
import hashlib
|
||||
import datetime
|
||||
from altcha import ChallengeOptions, create_challenge, verify_solution
|
||||
|
||||
routes_core_contact = Blueprint('routes_core_contact', __name__)
|
||||
|
||||
|
||||
@routes_core_contact.route(Model_View_Contact.HASH_PAGE_CONTACT, methods=['GET'])
|
||||
def contact():
|
||||
try:
|
||||
form = Form_Contact()
|
||||
model = Model_View_Contact(form)
|
||||
html_body = render_template('pages/core/_contact.html', model = model)
|
||||
return html_body
|
||||
except Exception as e:
|
||||
return API.get_standard_response(
|
||||
success = False,
|
||||
status_code = 500,
|
||||
message = f"Error: {e}",
|
||||
data = None,
|
||||
errors = [str(e)],
|
||||
meta = None
|
||||
)
|
||||
|
||||
@routes_core_contact.route(Model_View_Contact.HASH_GET_ALTCHA_CHALLENGE, methods=['GET'])
|
||||
def create_altcha_challenge():
|
||||
options = ChallengeOptions(
|
||||
expires = datetime.datetime.now() + datetime.timedelta(hours=1),
|
||||
max_number = 100000, # The maximum random number
|
||||
hmac_key = current_app.app_config.ALTCHA_SECRET_KEY,
|
||||
)
|
||||
challenge = create_challenge(options)
|
||||
Helper_App.console_log(f"Challenge created: {challenge}")
|
||||
# return jsonify({"challenge": challenge})
|
||||
return jsonify({
|
||||
"algorithm": challenge.algorithm,
|
||||
"challenge": challenge.challenge,
|
||||
"salt": challenge.salt,
|
||||
"signature": challenge.signature,
|
||||
})
|
||||
|
||||
@routes_core_contact.route(Model_View_Contact.HASH_PAGE_CONTACT, methods=['POST'])
|
||||
def contact_post():
|
||||
try:
|
||||
form = Form_Contact()
|
||||
if form.validate_on_submit():
|
||||
try:
|
||||
email = form.email.data
|
||||
# CC = form.CC.data # not in use
|
||||
contact_name = form.contact_name.data
|
||||
company_name = form.company_name.data
|
||||
message = form.message.data
|
||||
receive_marketing = form.receive_marketing.data
|
||||
receive_marketing_text = "I would like to receive marketing emails.\n" if receive_marketing else ""
|
||||
# send email
|
||||
mailItem = Message("PARTS Website Contact Us Message", recipients=[current_app.config['MAIL_CONTACT_PUBLIC']])
|
||||
mailItem.body = f"Dear Lord Edward Middleton-Smith,\n\n{message}\n{receive_marketing_text}\nKind regards,\n{contact_name}\n{company_name}\n{email}"
|
||||
mail.send(mailItem)
|
||||
# save to database
|
||||
datastore = DataStore_Command()
|
||||
command = Command.from_json(form.to_json())
|
||||
datastore.save_commands(
|
||||
comment = command.message
|
||||
, commands = [command]
|
||||
)
|
||||
return redirect(url_for(Model_View_Contact.ENDPOINT_PAGE_CONTACT_SUCCESS))
|
||||
except Exception as e:
|
||||
return API.get_standard_response(
|
||||
success = False,
|
||||
status_code = 500,
|
||||
message = f"Error: {e}",
|
||||
data = None,
|
||||
errors = [str(e)],
|
||||
meta = None
|
||||
)
|
||||
return API.get_standard_response(
|
||||
success = False,
|
||||
status_code = 500,
|
||||
message = f"Error: {form.errors}",
|
||||
data = None,
|
||||
errors = [str(form.errors)],
|
||||
meta = None
|
||||
)
|
||||
# html_body = render_template('pages/core/_contact.html', model = model)
|
||||
except Exception as e:
|
||||
return API.get_standard_response(
|
||||
success = False,
|
||||
status_code = 500,
|
||||
message = f"Error: {e}",
|
||||
data = None,
|
||||
errors = [str(e)],
|
||||
meta = None
|
||||
)
|
||||
|
||||
@routes_core_contact.route(Model_View_Contact.HASH_PAGE_CONTACT_SUCCESS, methods=['GET'])
|
||||
def contact_success():
|
||||
try:
|
||||
model = Model_View_Contact_Success()
|
||||
html_body = render_template('pages/core/_contact_success.html', model = model)
|
||||
return html_body
|
||||
except Exception as e:
|
||||
return API.get_standard_response(
|
||||
success = False,
|
||||
status_code = 500,
|
||||
message = f"Error: {e}",
|
||||
data = None,
|
||||
errors = [str(e)],
|
||||
meta = None
|
||||
)
|
||||
@@ -11,8 +11,8 @@ Home Page Controller.
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.api import API
|
||||
from models.model_view_home import Model_View_Home
|
||||
from dog_training.business_objects.api import API
|
||||
from dog_training.models.model_view_home import Model_View_Home
|
||||
# external
|
||||
from flask import render_template, jsonify, Blueprint
|
||||
|
||||
|
||||
Reference in New Issue
Block a user