Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -80,35 +80,76 @@ except Exception as e:
|
|
80 |
print(f"Failed to connect to Salesforce: {str(e)}")
|
81 |
|
82 |
# Function to handle login & registration in Salesforce
|
83 |
-
@app.route(
|
84 |
-
def
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
-
|
90 |
-
|
|
|
|
|
91 |
|
|
|
|
|
92 |
try:
|
93 |
-
#
|
94 |
-
|
95 |
-
|
|
|
96 |
|
97 |
-
|
98 |
-
|
|
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
'name': user_data['Name']
|
106 |
-
}), 200
|
107 |
|
108 |
-
except requests.exceptions.RequestException as req_error:
|
109 |
-
return jsonify({'error': f'Salesforce connection error: {str(req_error)}'}), 500
|
110 |
except Exception as e:
|
111 |
-
|
|
|
|
|
112 |
|
113 |
@app.route("/")
|
114 |
def index():
|
|
|
80 |
print(f"Failed to connect to Salesforce: {str(e)}")
|
81 |
|
82 |
# Function to handle login & registration in Salesforce
|
83 |
+
@app.route("/validate_login", methods=["POST"])
|
84 |
+
def validate_login():
|
85 |
+
try:
|
86 |
+
# Get the email and mobile number from the request
|
87 |
+
data = request.json
|
88 |
+
email = data.get("email")
|
89 |
+
mobile = data.get("mobile")
|
90 |
+
|
91 |
+
# Salesforce query to check if the email and mobile exist
|
92 |
+
query = f"SELECT Id, Name FROM Customer_Login__c WHERE Email__c = '{email}' AND Phone_Number__c = '{mobile}'"
|
93 |
+
result = sf.query(query)
|
94 |
+
|
95 |
+
if result['totalSize'] > 0:
|
96 |
+
return jsonify({'success': True, 'message': 'User authenticated successfully.'}), 200
|
97 |
+
else:
|
98 |
+
return jsonify({'success': False, 'error': 'Invalid email or mobile number.'}), 400
|
99 |
+
except Exception as e:
|
100 |
+
logging.error(f"Error: {str(e)}")
|
101 |
+
return jsonify({'error': 'Something went wrong. Please try again later.'}), 500
|
102 |
+
|
103 |
+
if __name__ == "__main__":
|
104 |
+
app.run(host="0.0.0.0", port=7860, debug=True)
|
105 |
+
|
106 |
+
|
107 |
+
|
108 |
+
# Initialize Flask app
|
109 |
+
app = Flask(__name__)
|
110 |
+
|
111 |
+
# Set the secret key to handle sessions securely
|
112 |
+
app.secret_key = os.getenv("SECRET_KEY", "sSSjyhInIsUohKpG8sHzty2q") # Replace with a secure key
|
113 |
+
|
114 |
+
# Configure the session type
|
115 |
+
app.config["SESSION_TYPE"] = "filesystem" # Use filesystem for session storage
|
116 |
+
app.config["SESSION_COOKIE_NAME"] = "my_session" # Optional: Change session cookie name
|
117 |
+
app.config["SESSION_COOKIE_SECURE"] = True # Ensure cookies are sent over HTTPS
|
118 |
+
app.config["SESSION_COOKIE_SAMESITE"] = "None" # Allow cross-site cookies
|
119 |
+
|
120 |
+
# Initialize the session
|
121 |
+
Session(app)
|
122 |
+
|
123 |
+
# Set up logging
|
124 |
+
logging.basicConfig(level=logging.INFO)
|
125 |
|
126 |
+
@app.route("/")
|
127 |
+
def index():
|
128 |
+
# Serve the HTML page for the voice-based login
|
129 |
+
return render_template("index.html")
|
130 |
|
131 |
+
@app.route("/capture_email_and_mobile", methods=["POST"])
|
132 |
+
def capture_email_and_mobile():
|
133 |
try:
|
134 |
+
# Get the voice captured email and mobile number from the request
|
135 |
+
data = request.json
|
136 |
+
email = data.get("email")
|
137 |
+
mobile = data.get("mobile")
|
138 |
|
139 |
+
# Validate the captured email and mobile number
|
140 |
+
if not email or not mobile:
|
141 |
+
return jsonify({"error": "Email or mobile number is missing."}), 400
|
142 |
|
143 |
+
# Log the captured data for now (you can replace it with actual processing logic)
|
144 |
+
logging.info(f"Captured Email: {email}, Mobile: {mobile}")
|
145 |
+
|
146 |
+
# For simplicity, we'll assume the capture was successful.
|
147 |
+
return jsonify({"success": True, "message": "Email and mobile captured successfully."}), 200
|
|
|
|
|
148 |
|
|
|
|
|
149 |
except Exception as e:
|
150 |
+
logging.error(f"Error: {str(e)}")
|
151 |
+
return jsonify({"error": "Something went wrong while processing."}), 500
|
152 |
+
|
153 |
|
154 |
@app.route("/")
|
155 |
def index():
|