Update app.py
Browse files
app.py
CHANGED
|
@@ -27,20 +27,13 @@ except Exception as e:
|
|
| 27 |
sf = None
|
| 28 |
|
| 29 |
# Route for login page
|
| 30 |
-
@app.route('/')
|
| 31 |
-
def login():
|
| 32 |
-
print("Login route accessed") # Debug statement
|
| 33 |
-
return render_template('login.html')
|
| 34 |
-
|
| 35 |
-
# Route to process login
|
| 36 |
@app.route('/auth', methods=['POST'])
|
| 37 |
def auth():
|
| 38 |
-
print("Auth route accessed") # Debug statement
|
| 39 |
email = request.form['email']
|
| 40 |
password = request.form['password']
|
| 41 |
|
| 42 |
if not sf:
|
| 43 |
-
return "Salesforce connection failed. Please
|
| 44 |
|
| 45 |
try:
|
| 46 |
# Query Salesforce for user authentication
|
|
@@ -48,15 +41,17 @@ def auth():
|
|
| 48 |
result = sf.query(query)
|
| 49 |
|
| 50 |
if result['totalSize'] == 0:
|
| 51 |
-
return "Invalid
|
| 52 |
|
| 53 |
customer = result['records'][0]
|
| 54 |
reward_points = customer['Reward_Points__c']
|
| 55 |
|
| 56 |
-
# Redirect to rewards page
|
| 57 |
return redirect(url_for('rewards', customer_id=customer['Id'], points=reward_points))
|
|
|
|
| 58 |
except Exception as e:
|
| 59 |
-
return f"Error during authentication: {e}"
|
|
|
|
| 60 |
|
| 61 |
# Route to display rewards page
|
| 62 |
@app.route('/rewards/<customer_id>')
|
|
|
|
| 27 |
sf = None
|
| 28 |
|
| 29 |
# Route for login page
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
@app.route('/auth', methods=['POST'])
|
| 31 |
def auth():
|
|
|
|
| 32 |
email = request.form['email']
|
| 33 |
password = request.form['password']
|
| 34 |
|
| 35 |
if not sf:
|
| 36 |
+
return render_template('login.html', error_message="Salesforce connection failed. Please try again.")
|
| 37 |
|
| 38 |
try:
|
| 39 |
# Query Salesforce for user authentication
|
|
|
|
| 41 |
result = sf.query(query)
|
| 42 |
|
| 43 |
if result['totalSize'] == 0:
|
| 44 |
+
return render_template('login.html', error_message="Invalid login details. Please check your email and password.")
|
| 45 |
|
| 46 |
customer = result['records'][0]
|
| 47 |
reward_points = customer['Reward_Points__c']
|
| 48 |
|
| 49 |
+
# Redirect to rewards page or any other page
|
| 50 |
return redirect(url_for('rewards', customer_id=customer['Id'], points=reward_points))
|
| 51 |
+
|
| 52 |
except Exception as e:
|
| 53 |
+
return render_template('login.html', error_message=f"Error during authentication: {e}")
|
| 54 |
+
|
| 55 |
|
| 56 |
# Route to display rewards page
|
| 57 |
@app.route('/rewards/<customer_id>')
|