Compare commits

..

No commits in common. "5703458586198c178f5b5f6561ccb3ca04bba8c7" and "4899bfedc21b23fdd9bc36be2b50cc3548ae9a42" have entirely different histories.

6 changed files with 22 additions and 32 deletions

View File

@ -1,4 +1,5 @@
from flask import Flask from flask import Flask
from flask_cors import CORS
from flask_mail import Mail from flask_mail import Mail
from werkzeug.middleware.proxy_fix import ProxyFix from werkzeug.middleware.proxy_fix import ProxyFix
@ -19,4 +20,12 @@ def create_app(cfg=config):
app.register_blueprint(bp_api) app.register_blueprint(bp_api)
CORS(
app,
resources={r'/api/*': {
'methods': ['POST', 'OPTIONS'],
'allow_origins': app.config['CORS_ALLOWED_ORIGINS'].split(','),
'allow_headers': app.config['CORS_ALLOWED_HEADERS'].split(','),
}})
return app return app

View File

@ -8,13 +8,6 @@ from app.api import bp
from app import mail from app import mail
@bp.after_request
def after(response):
response.headers["Access-Control-Allow-Origin"] = "*"
response.headers["Access-Control-Allow-Headers"] = "*"
return response
@bp.route("/rfq", methods=["POST"]) @bp.route("/rfq", methods=["POST"])
def send_rfq(): def send_rfq():
payload = request.json payload = request.json
@ -32,36 +25,16 @@ def send_rfq():
resp = jsonify(error="missing body") resp = jsonify(error="missing body")
return make_response(resp, 400) return make_response(resp, 400)
if "configuration" not in payload:
resp = jsonify(error="missing configuration")
return make_response(resp, 400)
recipient = current_app.config["MAIL_RECIPIENT"] recipient = current_app.config["MAIL_RECIPIENT"]
msg = Message( msg = Message(
"[ORDER HARDWARE - RFQ from %s]" % payload['email'], "[ORDER HARDWARE - RFQ from %s]" % payload['email'],
reply_to=recipient,
sender=payload["email"], sender=payload["email"],
recipients=[recipient]) recipients=[recipient])
msg.body = payload["body"] msg.body = payload["body"]
msg.html = payload["body"] msg.html = payload["body"]
msg_client_confirmation = Message( mail.send(msg)
"[M-Labs - Order Hardware]",
reply_to=recipient,
sender=recipient,
recipients=[payload["email"]])
msg_client_confirmation.body = "Hello! We've received your request and " \
"will be in contact soon. " \
"Here is a reminder of your configuration: {}" \
"Thank you!".format(payload["configuration"])
msg_client_confirmation.html = "Hello!<br />" \
"We've received your request and will be in contact soon.<br />" \
"Here is a reminder of your configuration: {}<br /><br />" \
"Thank you!".format(payload["configuration"])
with mail.connect() as conn:
conn.send(msg)
conn.send(msg_client_confirmation)
return jsonify("ok") return jsonify("ok")

View File

@ -16,3 +16,6 @@ MAIL_USERNAME = getenv("FLASK_MAIL_USERNAME")
MAIL_PASSWORD = getenv("FLASK_MAIL_PASSWORD") MAIL_PASSWORD = getenv("FLASK_MAIL_PASSWORD")
MAIL_RECIPIENT = getenv("FLASK_MAIL_RECIPIENT") MAIL_RECIPIENT = getenv("FLASK_MAIL_RECIPIENT")
CORS_ALLOWED_ORIGINS = getenv("FLASK_CORS_ORIGINS")
CORS_ALLOWED_HEADERS = getenv("FLASK_CORS_ALLOW_HEADERS")

View File

@ -1,6 +1,7 @@
blinker==1.4 blinker==1.4
click==7.1.1 click==7.1.1
Flask==1.1.2 Flask==1.1.2
Flask-Cors==3.0.7
Flask-Mail==0.9.1 Flask-Mail==0.9.1
itsdangerous==1.1.0 itsdangerous==1.1.0
Jinja2==2.11.1 Jinja2==2.11.1

View File

@ -1220,7 +1220,9 @@ class OrderForm extends React.PureComponent {
value="Show configurations" value="Show configurations"
onClick={onClickShow} /> onClick={onClickShow} />
<input className="btn btn-primary w-100 m-0 ml-sm-2" type="submit" value={`${isProcessing ? 'Processing ...' : 'Request quote'}`} /> <input className="btn btn-primary w-100 m-0 ml-sm-2" style={Object.assign({}, isProcessingComplete ? {
'backgroundColor': 'gray',
} : {})} disabled={isProcessingComplete} type="submit" value={`${isProcessing ? 'Processing ...' : 'Request quote'}`} />
</div> </div>
{/*This will open an email window. Send the email to make your request.*/} {/*This will open an email window. Send the email to make your request.*/}
</form> </form>
@ -1860,7 +1862,6 @@ class Shop extends React.PureComponent {
axios.post(data.API_RFQ, { axios.post(data.API_RFQ, {
email, email,
body, body,
configuration: JSON.stringify(crate),
headers: {'X-MLABS-OH': 'rlebcleu'} headers: {'X-MLABS-OH': 'rlebcleu'}
}).then(response => { }).then(response => {
this.setState({ this.setState({

View File

@ -1274,6 +1274,10 @@ function (_React$PureComponent9) {
onClick: onClickShow onClick: onClickShow
}), React.createElement("input", { }), React.createElement("input", {
className: "btn btn-primary w-100 m-0 ml-sm-2", className: "btn btn-primary w-100 m-0 ml-sm-2",
style: Object.assign({}, isProcessingComplete ? {
'backgroundColor': 'gray'
} : {}),
disabled: isProcessingComplete,
type: "submit", type: "submit",
value: "".concat(isProcessing ? 'Processing ...' : 'Request quote') value: "".concat(isProcessing ? 'Processing ...' : 'Request quote')
})))); }))));
@ -1895,7 +1899,6 @@ function (_React$PureComponent12) {
axios.post(data.API_RFQ, { axios.post(data.API_RFQ, {
email: email, email: email,
body: body, body: body,
configuration: JSON.stringify(crate),
headers: { headers: {
'X-MLABS-OH': 'rlebcleu' 'X-MLABS-OH': 'rlebcleu'
} }