Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,32 +11,34 @@ import time
|
|
| 11 |
from waitress import serve
|
| 12 |
from simple_salesforce import Salesforce
|
| 13 |
import requests # Import requests for exception handling
|
| 14 |
-
|
| 15 |
-
app = Flask(__name__)
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
from flask import Flask, request, jsonify
|
| 19 |
from flask_cors import CORS
|
| 20 |
-
from simple_salesforce import Salesforce
|
| 21 |
-
|
| 22 |
app = Flask(__name__)
|
| 23 |
-
CORS(app) # This enables CORS for all domains
|
| 24 |
|
|
|
|
| 25 |
|
|
|
|
|
|
|
| 26 |
|
|
|
|
| 27 |
@app.route('/validate-login', methods=['POST'])
|
| 28 |
def validate_login():
|
|
|
|
| 29 |
login_data = request.json
|
| 30 |
email = login_data.get('email')
|
| 31 |
mobile = login_data.get('mobile')
|
| 32 |
|
|
|
|
| 33 |
query = f"SELECT Id FROM Customer_Login__c WHERE Email__c = '{email}' AND Mobile_Number__c = '{mobile}' LIMIT 1"
|
| 34 |
result = sf.query(query)
|
| 35 |
|
|
|
|
| 36 |
if result['records']:
|
| 37 |
-
return jsonify({"valid": True})
|
| 38 |
else:
|
| 39 |
-
return jsonify({"valid": False})
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
if __name__ == '__main__':
|
| 42 |
app.run(debug=True, host='0.0.0.0', port=5000) # Ensuring the Flask app runs on port 5000
|
|
|
|
| 11 |
from waitress import serve
|
| 12 |
from simple_salesforce import Salesforce
|
| 13 |
import requests # Import requests for exception handling
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
from flask_cors import CORS
|
|
|
|
|
|
|
| 15 |
app = Flask(__name__)
|
|
|
|
| 16 |
|
| 17 |
+
CORS(app) # Enable Cross-Origin Resource Sharing (CORS
|
| 18 |
|
| 19 |
+
# Salesforce connection setup
|
| 20 |
+
sf = Salesforce(username='your_username', password='your_password', security_token='your_security_token')
|
| 21 |
|
| 22 |
+
# Define the validate-login route
|
| 23 |
@app.route('/validate-login', methods=['POST'])
|
| 24 |
def validate_login():
|
| 25 |
+
# Get the captured email and mobile number from the request
|
| 26 |
login_data = request.json
|
| 27 |
email = login_data.get('email')
|
| 28 |
mobile = login_data.get('mobile')
|
| 29 |
|
| 30 |
+
# Query Salesforce for the customer login record matching the email and mobile
|
| 31 |
query = f"SELECT Id FROM Customer_Login__c WHERE Email__c = '{email}' AND Mobile_Number__c = '{mobile}' LIMIT 1"
|
| 32 |
result = sf.query(query)
|
| 33 |
|
| 34 |
+
# Check if a matching record exists
|
| 35 |
if result['records']:
|
| 36 |
+
return jsonify({"valid": True}) # Valid login
|
| 37 |
else:
|
| 38 |
+
return jsonify({"valid": False}) # Invalid login
|
| 39 |
+
|
| 40 |
+
if __name__ == '__main__':
|
| 41 |
+
app.run(debug=True, host='0.0.0.0', port=5000) # Run Flask on port 5000
|
| 42 |
|
| 43 |
if __name__ == '__main__':
|
| 44 |
app.run(debug=True, host='0.0.0.0', port=5000) # Ensuring the Flask app runs on port 5000
|