Compare commits
5 Commits
4899bfedc2
...
5703458586
Author | SHA1 | Date |
---|---|---|
sovanna | 5703458586 | |
sovanna | 0758e2d2ba | |
sovanna | a61ebbdff6 | |
sovanna | 44b361893f | |
sovanna | e116bbf028 |
|
@ -1,5 +1,4 @@
|
||||||
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
|
||||||
|
|
||||||
|
@ -20,12 +19,4 @@ 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
|
||||||
|
|
|
@ -8,6 +8,13 @@ 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
|
||||||
|
@ -25,16 +32,36 @@ 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"]
|
||||||
|
|
||||||
mail.send(msg)
|
msg_client_confirmation = Message(
|
||||||
|
"[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")
|
||||||
|
|
|
@ -16,6 +16,3 @@ 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")
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
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
|
||||||
|
|
|
@ -1220,9 +1220,7 @@ 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" style={Object.assign({}, isProcessingComplete ? {
|
<input className="btn btn-primary w-100 m-0 ml-sm-2" type="submit" value={`${isProcessing ? 'Processing ...' : 'Request quote'}`} />
|
||||||
'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>
|
||||||
|
@ -1862,6 +1860,7 @@ 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({
|
||||||
|
|
|
@ -1274,10 +1274,6 @@ 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')
|
||||||
}))));
|
}))));
|
||||||
|
@ -1899,6 +1895,7 @@ 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'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue