confimration mail at end of launch process
This commit is contained in:
@@ -4,11 +4,15 @@ from models import (
|
||||
Instance
|
||||
)
|
||||
from extensions import db, csrf
|
||||
from routes.admin_api import token_required
|
||||
import json
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.utils import formatdate
|
||||
from datetime import datetime
|
||||
import requests
|
||||
import base64
|
||||
from routes.admin_api import token_required
|
||||
import json
|
||||
|
||||
launch_api = Blueprint('launch_api', __name__)
|
||||
|
||||
@@ -1117,9 +1121,9 @@ def update_admin_credentials():
|
||||
users_data = users_response.json()
|
||||
admin_user = None
|
||||
|
||||
# Find the administrator user
|
||||
# Find the administrator user by role (since email was already updated)
|
||||
for user in users_data:
|
||||
if user.get('email') == email:
|
||||
if user.get('is_admin') == True:
|
||||
admin_user = user
|
||||
break
|
||||
|
||||
@@ -1291,9 +1295,9 @@ def send_completion_email():
|
||||
users_data = users_response.json()
|
||||
admin_user = None
|
||||
|
||||
# Find the administrator user by email
|
||||
# Find the administrator user by role (since email was already updated)
|
||||
for user in users_data:
|
||||
if user.get('email') == credentials_data.get('email'):
|
||||
if user.get('is_admin') == True:
|
||||
admin_user = user
|
||||
break
|
||||
|
||||
@@ -1307,8 +1311,10 @@ def send_completion_email():
|
||||
f"{instance_url.rstrip('/')}/api/admin/generate-password-reset/{admin_user_id}",
|
||||
headers={
|
||||
'Authorization': f'Bearer {jwt_token}',
|
||||
'Accept': 'application/json'
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
json={'instance_url': instance_url},
|
||||
timeout=10
|
||||
)
|
||||
|
||||
@@ -1364,8 +1370,8 @@ def send_completion_email():
|
||||
|
||||
<div class="credentials">
|
||||
<h3>🔐 Account Access</h3>
|
||||
<p><strong>Email Address:</strong> {credentials_data.get('email', 'Not set')}</p>
|
||||
<p><strong>Username:</strong> {credentials_data.get('username', 'administrator')}</p>
|
||||
<p><strong>Email Address:</strong> {admin_user.get('email', 'Not set')}</p>
|
||||
<p><strong>Username:</strong> {admin_user.get('username', 'administrator')}</p>
|
||||
|
||||
<div class="security-notice">
|
||||
<h4>🔒 Security Setup Required</h4>
|
||||
@@ -1424,8 +1430,8 @@ INSTANCE DETAILS:
|
||||
- Deployment Date: {datetime.utcnow().strftime('%B %d, %Y at %I:%M %p UTC')}
|
||||
|
||||
ACCOUNT ACCESS:
|
||||
- Email Address: {credentials_data.get('email', 'Not set')}
|
||||
- Username: {credentials_data.get('username', 'administrator')}
|
||||
- Email Address: {admin_user.get('email', 'Not set')}
|
||||
- Username: {admin_user.get('username', 'administrator')}
|
||||
|
||||
SECURITY SETUP REQUIRED:
|
||||
For your security, you need to set up your password.
|
||||
@@ -1454,15 +1460,36 @@ Thank you for choosing DocuPulse!
|
||||
"""
|
||||
|
||||
# Send email using master instance's email system
|
||||
from utils.email_templates import send_email
|
||||
|
||||
try:
|
||||
send_email(
|
||||
to_email=company_data.get('email'),
|
||||
subject=subject,
|
||||
html_content=html_content,
|
||||
text_content=text_content
|
||||
)
|
||||
# Get SMTP settings
|
||||
smtp_settings = KeyValueSettings.get_value('smtp_settings')
|
||||
if not smtp_settings:
|
||||
return jsonify({'error': 'SMTP settings not configured'}), 400
|
||||
|
||||
# Create message
|
||||
msg = MIMEMultipart()
|
||||
msg['From'] = f"{smtp_settings.get('smtp_from_name', 'DocuPulse')} <{smtp_settings.get('smtp_from_email')}>"
|
||||
msg['To'] = company_data.get('email')
|
||||
msg['Subject'] = subject
|
||||
msg['Date'] = formatdate(localtime=True)
|
||||
|
||||
# Add HTML content
|
||||
msg.attach(MIMEText(html_content, 'html'))
|
||||
|
||||
# Send email
|
||||
if smtp_settings.get('smtp_security') == 'ssl':
|
||||
server = smtplib.SMTP_SSL(smtp_settings.get('smtp_host'), smtp_settings.get('smtp_port'))
|
||||
else:
|
||||
server = smtplib.SMTP(smtp_settings.get('smtp_host'), smtp_settings.get('smtp_port'))
|
||||
|
||||
if smtp_settings.get('smtp_security') == 'tls':
|
||||
server.starttls()
|
||||
|
||||
if smtp_settings.get('smtp_username') and smtp_settings.get('smtp_password'):
|
||||
server.login(smtp_settings.get('smtp_username'), smtp_settings.get('smtp_password'))
|
||||
|
||||
server.send_message(msg)
|
||||
server.quit()
|
||||
|
||||
# Log the email sending
|
||||
current_app.logger.info(f"Completion email sent to {company_data.get('email')} for instance {instance_url}")
|
||||
@@ -1476,7 +1503,7 @@ Thank you for choosing DocuPulse!
|
||||
'password_reset_sent': True
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
except Exception as email_error:
|
||||
current_app.logger.error(f"Failed to send completion email: {str(email_error)}")
|
||||
return jsonify({'error': f'Failed to send email: {str(email_error)}'}), 500
|
||||
|
||||
Reference in New Issue
Block a user