Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from flask import Flask, render_template, request, jsonify
|
|
3 |
from flask_session import Session
|
4 |
import json
|
5 |
import os
|
|
|
6 |
from transformers import pipeline
|
7 |
from gtts import gTTS
|
8 |
from pydub import AudioSegment
|
@@ -73,15 +74,22 @@ except Exception as e:
|
|
73 |
@app.route('/login', methods=['POST'])
|
74 |
def login():
|
75 |
data = request.json
|
76 |
-
email = data.get('email').strip().lower()
|
77 |
phone_number = data.get('phone_number').strip()
|
78 |
|
|
|
|
|
|
|
|
|
79 |
if not email or not phone_number:
|
80 |
return jsonify({'error': 'Missing email or phone number'}), 400
|
81 |
|
82 |
try:
|
83 |
-
#
|
84 |
query = f"SELECT Id, Name FROM Customer_Login__c WHERE LOWER(Email__c) = '{email}' AND Phone_Number__c = '{phone_number}' LIMIT 1"
|
|
|
|
|
|
|
85 |
result = sf.query(query)
|
86 |
|
87 |
if result['totalSize'] == 0:
|
@@ -91,8 +99,10 @@ def login():
|
|
91 |
return jsonify({'success': True, 'message': 'Login successful', 'user_id': user_data['Id'], 'name': user_data['Name']}), 200
|
92 |
|
93 |
except requests.exceptions.RequestException as req_error:
|
|
|
94 |
return jsonify({'error': f'Salesforce connection error: {str(req_error)}'}), 500
|
95 |
except Exception as e:
|
|
|
96 |
return jsonify({'error': f'Unexpected error: {str(e)}'}), 500
|
97 |
|
98 |
# ✅ REGISTRATION ENDPOINT (Creates New User)
|
|
|
3 |
from flask_session import Session
|
4 |
import json
|
5 |
import os
|
6 |
+
import re
|
7 |
from transformers import pipeline
|
8 |
from gtts import gTTS
|
9 |
from pydub import AudioSegment
|
|
|
74 |
@app.route('/login', methods=['POST'])
|
75 |
def login():
|
76 |
data = request.json
|
77 |
+
email = data.get('email').strip().lower() # Ensure no leading/trailing spaces
|
78 |
phone_number = data.get('phone_number').strip()
|
79 |
|
80 |
+
# Sanitize phone number by removing non-numeric characters
|
81 |
+
phone_number = re.sub(r'\D', '', phone_number)
|
82 |
+
|
83 |
+
# Check if email or phone number is missing
|
84 |
if not email or not phone_number:
|
85 |
return jsonify({'error': 'Missing email or phone number'}), 400
|
86 |
|
87 |
try:
|
88 |
+
# Log the query for debugging
|
89 |
query = f"SELECT Id, Name FROM Customer_Login__c WHERE LOWER(Email__c) = '{email}' AND Phone_Number__c = '{phone_number}' LIMIT 1"
|
90 |
+
logging.info(f"Executing query: {query}")
|
91 |
+
|
92 |
+
# Query Salesforce to check if user exists
|
93 |
result = sf.query(query)
|
94 |
|
95 |
if result['totalSize'] == 0:
|
|
|
99 |
return jsonify({'success': True, 'message': 'Login successful', 'user_id': user_data['Id'], 'name': user_data['Name']}), 200
|
100 |
|
101 |
except requests.exceptions.RequestException as req_error:
|
102 |
+
logging.error(f"Salesforce connection error: {str(req_error)}")
|
103 |
return jsonify({'error': f'Salesforce connection error: {str(req_error)}'}), 500
|
104 |
except Exception as e:
|
105 |
+
logging.error(f"Unexpected error: {str(e)}")
|
106 |
return jsonify({'error': f'Unexpected error: {str(e)}'}), 500
|
107 |
|
108 |
# ✅ REGISTRATION ENDPOINT (Creates New User)
|