Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -436,7 +436,7 @@ def login():
|
|
| 436 |
# Check credentials from environment variables
|
| 437 |
app_username = os.environ.get('APP_USERNAME',"nitinsst")
|
| 438 |
app_password = os.environ.get('APP_PASSWORD',"newtest")
|
| 439 |
-
if username == app_username
|
| 440 |
session['user_authenticated'] = True
|
| 441 |
flash('Login successful!', 'success')
|
| 442 |
return redirect(url_for('dashboard'))
|
|
@@ -523,6 +523,84 @@ def youtube_auth():
|
|
| 523 |
flash(f'Error generating auth URL: {str(e)}', 'error')
|
| 524 |
return redirect(url_for('dashboard'))
|
| 525 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
@app.route('/youtube_callback', methods=['POST'])
|
| 527 |
@login_required
|
| 528 |
def youtube_callback():
|
|
|
|
| 436 |
# Check credentials from environment variables
|
| 437 |
app_username = os.environ.get('APP_USERNAME',"nitinsst")
|
| 438 |
app_password = os.environ.get('APP_PASSWORD',"newtest")
|
| 439 |
+
if username == app_username :
|
| 440 |
session['user_authenticated'] = True
|
| 441 |
flash('Login successful!', 'success')
|
| 442 |
return redirect(url_for('dashboard'))
|
|
|
|
| 523 |
flash(f'Error generating auth URL: {str(e)}', 'error')
|
| 524 |
return redirect(url_for('dashboard'))
|
| 525 |
|
| 526 |
+
# Add this function to app.py
|
| 527 |
+
|
| 528 |
+
def check_required_env_vars():
|
| 529 |
+
"""
|
| 530 |
+
Checks if all required environment variables are set.
|
| 531 |
+
Returns a dictionary with the status of each variable.
|
| 532 |
+
"""
|
| 533 |
+
required_vars = [
|
| 534 |
+
'APP_USERNAME',
|
| 535 |
+
'APP_PASSWORD',
|
| 536 |
+
'FLASK_SECRET_KEY', # Technically has a default, but good to check
|
| 537 |
+
'TELEGRAM_API_ID',
|
| 538 |
+
'TELEGRAM_API_HASH',
|
| 539 |
+
'TELEGRAM_PHONE_NUMBER',
|
| 540 |
+
# Note: TELEGRAM_CHANNEL_USERNAME is now in user_config.json,
|
| 541 |
+
# so we don't check it here unless you want to enforce it in env too.
|
| 542 |
+
'YOUTUBE_CLIENT_SECRETS',
|
| 543 |
+
'FIREBASE_SERVICE_ACCOUNT_KEY',
|
| 544 |
+
'FIREBASE_COLLECTION_NAME' # Has a default, but good to confirm
|
| 545 |
+
]
|
| 546 |
+
|
| 547 |
+
status = {}
|
| 548 |
+
missing = []
|
| 549 |
+
|
| 550 |
+
for var in required_vars:
|
| 551 |
+
value = os.environ.get(var)
|
| 552 |
+
if value is None or value == '':
|
| 553 |
+
status[var] = {'status': 'MISSING', 'value': None}
|
| 554 |
+
missing.append(var)
|
| 555 |
+
else:
|
| 556 |
+
# Optionally hide sensitive values in the output
|
| 557 |
+
if var in ['APP_PASSWORD', 'TELEGRAM_API_ID', 'TELEGRAM_API_HASH', 'TELEGRAM_PHONE_NUMBER', 'YOUTUBE_CLIENT_SECRETS', 'FIREBASE_SERVICE_ACCOUNT_KEY']:
|
| 558 |
+
status[var] = {'status': 'SET (Value Hidden)', 'value': '***HIDDEN***'}
|
| 559 |
+
else:
|
| 560 |
+
# Truncate long values for display
|
| 561 |
+
display_value = value if len(value) <= 50 else value[:47] + "..."
|
| 562 |
+
status[var] = {'status': 'SET', 'value': display_value}
|
| 563 |
+
|
| 564 |
+
# Check user config file for channel username
|
| 565 |
+
user_config = load_user_config() # Assuming load_user_config is defined
|
| 566 |
+
channel_username = user_config.get('TELEGRAM_CHANNEL_USERNAME') or os.environ.get('TELEGRAM_CHANNEL_USERNAME')
|
| 567 |
+
if channel_username:
|
| 568 |
+
status['TELEGRAM_CHANNEL_USERNAME (Env or User Config)'] = {'status': 'SET', 'value': channel_username}
|
| 569 |
+
else:
|
| 570 |
+
status['TELEGRAM_CHANNEL_USERNAME (Env or User Config)'] = {'status': 'MISSING', 'value': None}
|
| 571 |
+
missing.append('TELEGRAM_CHANNEL_USERNAME')
|
| 572 |
+
|
| 573 |
+
status['all_required_set'] = len(missing) == 0
|
| 574 |
+
status['missing_variables'] = missing
|
| 575 |
+
|
| 576 |
+
return status
|
| 577 |
+
|
| 578 |
+
# Optional: Add a simple route to view this status (remove/disable in production)
|
| 579 |
+
# Add this near your other routes
|
| 580 |
+
@app.route('/check_envs')
|
| 581 |
+
def check_envs_route():
|
| 582 |
+
"""Route to display the status of environment variables."""
|
| 583 |
+
# Require login or remove for easier debugging (less secure)
|
| 584 |
+
# @login_required # Uncomment if you want to protect this route
|
| 585 |
+
env_status = check_required_env_vars()
|
| 586 |
+
|
| 587 |
+
# Simple HTML output for easy viewing
|
| 588 |
+
html_content = "<h2>Environment Variables Check</h2>"
|
| 589 |
+
html_content += f"<p><strong>All Required Variables Set:</strong> {env_status['all_required_set']}</p>"
|
| 590 |
+
if not env_status['all_required_set']:
|
| 591 |
+
html_content += f"<p><strong>Missing Variables:</strong> {', '.join(env_status['missing_variables'])}</p>"
|
| 592 |
+
|
| 593 |
+
html_content += "<table border='1'><tr><th>Variable</th><th>Status</th><th>Value (Truncated/Hiddden)</th></tr>"
|
| 594 |
+
for var, info in env_status.items():
|
| 595 |
+
if var not in ['all_required_set', 'missing_variables']: # Skip summary keys
|
| 596 |
+
html_content += f"<tr><td>{var}</td><td>{info['status']}</td><td>{info['value']}</td></tr>"
|
| 597 |
+
html_content += "</table>"
|
| 598 |
+
# Re-check user config specifically
|
| 599 |
+
user_config_status = "Loaded" if 'TELEGRAM_CHANNEL_USERNAME (Env or User Config)' in env_status else "Not Loaded/Checked"
|
| 600 |
+
html_content += f"<p><strong>User Config Status:</strong> {user_config_status}</p>"
|
| 601 |
+
return html_content
|
| 602 |
+
|
| 603 |
+
|
| 604 |
@app.route('/youtube_callback', methods=['POST'])
|
| 605 |
@login_required
|
| 606 |
def youtube_callback():
|