Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -131,6 +131,36 @@ def submit():
|
|
| 131 |
print(f"Server Error: {str(e)}") # Log general errors
|
| 132 |
return jsonify({"success": False, "message": "Internal server error", "error": str(e)}), 500
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
@app.route("/menu", methods=["GET"])
|
| 135 |
def menu_page():
|
| 136 |
menu_items = get_menu_items(sf)
|
|
|
|
| 131 |
print(f"Server Error: {str(e)}") # Log general errors
|
| 132 |
return jsonify({"success": False, "message": "Internal server error", "error": str(e)}), 500
|
| 133 |
|
| 134 |
+
|
| 135 |
+
@app.route('/validate-login', methods=['POST'])
|
| 136 |
+
def validate_login():
|
| 137 |
+
try:
|
| 138 |
+
# Ensure JSON is being received
|
| 139 |
+
data = request.get_json()
|
| 140 |
+
login_email = data.get("email")
|
| 141 |
+
login_mobile = data.get("mobile")
|
| 142 |
+
|
| 143 |
+
# Validate if email and mobile are present
|
| 144 |
+
if not login_email or not login_mobile:
|
| 145 |
+
return jsonify({"success": False, "message": "Missing email or mobile number"}), 400
|
| 146 |
+
|
| 147 |
+
# Query Salesforce to check if the record exists
|
| 148 |
+
query = f"SELECT Id, Name, Email__c, Phone_Number__c FROM Customer_Login__c WHERE Email__c = '{login_email}' AND Phone_Number__c = '{login_mobile}'"
|
| 149 |
+
result = sf.query(query)
|
| 150 |
+
|
| 151 |
+
if result['records']:
|
| 152 |
+
# If a matching record is found, return success and the name
|
| 153 |
+
user_name = result['records'][0]['Name'] # Assuming the 'Name' field is present in the Salesforce object
|
| 154 |
+
return jsonify({"success": True, "message": "Login successful", "name": user_name})
|
| 155 |
+
else:
|
| 156 |
+
# If no matching record is found
|
| 157 |
+
return jsonify({"success": False, "message": "Invalid email or mobile number"}), 401
|
| 158 |
+
|
| 159 |
+
except Exception as e:
|
| 160 |
+
print(f"Error validating login: {str(e)}")
|
| 161 |
+
return jsonify({"success": False, "message": "Internal server error", "error": str(e)}), 500
|
| 162 |
+
|
| 163 |
+
|
| 164 |
@app.route("/menu", methods=["GET"])
|
| 165 |
def menu_page():
|
| 166 |
menu_items = get_menu_items(sf)
|