Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -95,11 +95,27 @@ def login():
|
|
| 95 |
return jsonify({'error': 'Missing required fields'}), 400
|
| 96 |
|
| 97 |
try:
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
except Exception as e:
|
| 101 |
-
return jsonify({'error': f'
|
|
|
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
@app.route("/submit", methods=["POST"])
|
| 104 |
def submit():
|
| 105 |
data = request.json
|
|
|
|
| 95 |
return jsonify({'error': 'Missing required fields'}), 400
|
| 96 |
|
| 97 |
try:
|
| 98 |
+
# Check if the user already exists in Salesforce using email or phone number
|
| 99 |
+
query = f"SELECT Id, Name, Email__c, Phone_Number__c FROM Customer_Login__c WHERE Email__c = '{email}' AND Phone_Number__c = '{phone_number}' LIMIT 1"
|
| 100 |
+
result = sf.query(query)
|
| 101 |
+
|
| 102 |
+
if result['totalSize'] > 0:
|
| 103 |
+
# User exists and credentials match, proceed to dashboard
|
| 104 |
+
return redirect("/menu") # Redirect to the menu page after successful login
|
| 105 |
+
else:
|
| 106 |
+
# User not found or credentials don't match
|
| 107 |
+
return jsonify({'error': 'Invalid email or phone number'}), 401 # Unauthorized
|
| 108 |
+
|
| 109 |
except Exception as e:
|
| 110 |
+
return jsonify({'error': f'Error during login or Salesforce query: {str(e)}'}), 500
|
| 111 |
+
|
| 112 |
|
| 113 |
+
@app.route('/logout')
|
| 114 |
+
def logout():
|
| 115 |
+
# Clear the session to log out the user
|
| 116 |
+
session.pop('user', None) # Removes the 'user' from session
|
| 117 |
+
return redirect(url_for('login')) # Redirect to login page
|
| 118 |
+
|
| 119 |
@app.route("/submit", methods=["POST"])
|
| 120 |
def submit():
|
| 121 |
data = request.json
|