launch process completed!
This commit is contained in:
@@ -973,4 +973,221 @@ def apply_company_information():
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.error(f"Error applying company information: {str(e)}")
|
current_app.logger.error(f"Error applying company information: {str(e)}")
|
||||||
|
return jsonify({'error': str(e)}), 500
|
||||||
|
|
||||||
|
@launch_api.route('/apply-colors', methods=['POST'])
|
||||||
|
@csrf.exempt
|
||||||
|
def apply_colors():
|
||||||
|
"""Apply colors to a launched instance"""
|
||||||
|
try:
|
||||||
|
if not request.is_json:
|
||||||
|
return jsonify({'error': 'Request must be JSON'}), 400
|
||||||
|
|
||||||
|
data = request.get_json()
|
||||||
|
required_fields = ['instance_url', 'colors_data']
|
||||||
|
|
||||||
|
if not all(field in data for field in required_fields):
|
||||||
|
missing_fields = [field for field in required_fields if field not in data]
|
||||||
|
return jsonify({'error': f'Missing required fields: {", ".join(missing_fields)}'}), 400
|
||||||
|
|
||||||
|
instance_url = data['instance_url']
|
||||||
|
colors_data = data['colors_data']
|
||||||
|
|
||||||
|
# Get the instance from database to get the connection token
|
||||||
|
instance = Instance.query.filter_by(main_url=instance_url).first()
|
||||||
|
|
||||||
|
if not instance:
|
||||||
|
return jsonify({'error': 'Instance not found in database'}), 404
|
||||||
|
|
||||||
|
if not instance.connection_token:
|
||||||
|
return jsonify({'error': 'Instance not authenticated'}), 400
|
||||||
|
|
||||||
|
# First get JWT token from the instance
|
||||||
|
jwt_response = requests.post(
|
||||||
|
f"{instance_url.rstrip('/')}/api/admin/management-token",
|
||||||
|
headers={
|
||||||
|
'X-API-Key': instance.connection_token,
|
||||||
|
'Accept': 'application/json'
|
||||||
|
},
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
|
|
||||||
|
if jwt_response.status_code != 200:
|
||||||
|
return jsonify({'error': f'Failed to get JWT token: {jwt_response.text}'}), 400
|
||||||
|
|
||||||
|
jwt_data = jwt_response.json()
|
||||||
|
jwt_token = jwt_data.get('token')
|
||||||
|
|
||||||
|
if not jwt_token:
|
||||||
|
return jsonify({'error': 'No JWT token received'}), 400
|
||||||
|
|
||||||
|
# Prepare colors data for the API
|
||||||
|
api_colors_data = {
|
||||||
|
'primary_color': colors_data.get('primary'),
|
||||||
|
'secondary_color': colors_data.get('secondary')
|
||||||
|
}
|
||||||
|
|
||||||
|
# Apply colors to the instance
|
||||||
|
colors_response = requests.put(
|
||||||
|
f"{instance_url.rstrip('/')}/api/admin/settings",
|
||||||
|
headers={
|
||||||
|
'Authorization': f'Bearer {jwt_token}',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json'
|
||||||
|
},
|
||||||
|
json=api_colors_data,
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
|
|
||||||
|
if colors_response.status_code != 200:
|
||||||
|
return jsonify({'error': f'Failed to apply colors: {colors_response.text}'}), 400
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'message': 'Colors applied successfully',
|
||||||
|
'data': {
|
||||||
|
'primary_color': colors_data.get('primary'),
|
||||||
|
'secondary_color': colors_data.get('secondary'),
|
||||||
|
'instance_url': instance_url
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.error(f"Error applying colors: {str(e)}")
|
||||||
|
return jsonify({'error': str(e)}), 500
|
||||||
|
|
||||||
|
@launch_api.route('/update-admin-credentials', methods=['POST'])
|
||||||
|
@csrf.exempt
|
||||||
|
def update_admin_credentials():
|
||||||
|
"""Update admin credentials on a launched instance"""
|
||||||
|
try:
|
||||||
|
if not request.is_json:
|
||||||
|
return jsonify({'error': 'Request must be JSON'}), 400
|
||||||
|
|
||||||
|
data = request.get_json()
|
||||||
|
required_fields = ['instance_url', 'email']
|
||||||
|
|
||||||
|
if not all(field in data for field in required_fields):
|
||||||
|
missing_fields = [field for field in required_fields if field not in data]
|
||||||
|
return jsonify({'error': f'Missing required fields: {", ".join(missing_fields)}'}), 400
|
||||||
|
|
||||||
|
instance_url = data['instance_url']
|
||||||
|
email = data['email']
|
||||||
|
|
||||||
|
# Get the instance from database to get the connection token
|
||||||
|
instance = Instance.query.filter_by(main_url=instance_url).first()
|
||||||
|
|
||||||
|
if not instance:
|
||||||
|
return jsonify({'error': 'Instance not found in database'}), 404
|
||||||
|
|
||||||
|
if not instance.connection_token:
|
||||||
|
return jsonify({'error': 'Instance not authenticated'}), 400
|
||||||
|
|
||||||
|
# First get JWT token from the instance
|
||||||
|
jwt_response = requests.post(
|
||||||
|
f"{instance_url.rstrip('/')}/api/admin/management-token",
|
||||||
|
headers={
|
||||||
|
'X-API-Key': instance.connection_token,
|
||||||
|
'Accept': 'application/json'
|
||||||
|
},
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
|
|
||||||
|
if jwt_response.status_code != 200:
|
||||||
|
return jsonify({'error': f'Failed to get JWT token: {jwt_response.text}'}), 400
|
||||||
|
|
||||||
|
jwt_data = jwt_response.json()
|
||||||
|
jwt_token = jwt_data.get('token')
|
||||||
|
|
||||||
|
if not jwt_token:
|
||||||
|
return jsonify({'error': 'No JWT token received'}), 400
|
||||||
|
|
||||||
|
# Generate a secure password
|
||||||
|
import secrets
|
||||||
|
import string
|
||||||
|
alphabet = string.ascii_letters + string.digits + "!@#$%^&*"
|
||||||
|
new_password = ''.join(secrets.choice(alphabet) for i in range(16))
|
||||||
|
|
||||||
|
# First, login with default credentials to get admin token
|
||||||
|
login_response = requests.post(
|
||||||
|
f"{instance_url.rstrip('/')}/api/admin/login",
|
||||||
|
headers={
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json'
|
||||||
|
},
|
||||||
|
json={
|
||||||
|
'email': 'administrator@docupulse.com',
|
||||||
|
'password': 'changeme'
|
||||||
|
},
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
|
|
||||||
|
if login_response.status_code != 200:
|
||||||
|
return jsonify({'error': f'Failed to login with default credentials: {login_response.text}'}), 400
|
||||||
|
|
||||||
|
login_data = login_response.json()
|
||||||
|
if login_data.get('status') != 'success' or not login_data.get('token'):
|
||||||
|
return jsonify({'error': 'Failed to get admin token'}), 400
|
||||||
|
|
||||||
|
admin_token = login_data.get('token')
|
||||||
|
|
||||||
|
# Get the admin user ID first
|
||||||
|
users_response = requests.get(
|
||||||
|
f"{instance_url.rstrip('/')}/api/admin/contacts",
|
||||||
|
headers={
|
||||||
|
'Authorization': f'Bearer {admin_token}',
|
||||||
|
'Accept': 'application/json'
|
||||||
|
},
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
|
|
||||||
|
if users_response.status_code != 200:
|
||||||
|
return jsonify({'error': f'Failed to get users: {users_response.text}'}), 400
|
||||||
|
|
||||||
|
users_data = users_response.json()
|
||||||
|
admin_user = None
|
||||||
|
|
||||||
|
# Find the administrator user
|
||||||
|
for user in users_data:
|
||||||
|
if user.get('email') == 'administrator@docupulse.com':
|
||||||
|
admin_user = user
|
||||||
|
break
|
||||||
|
|
||||||
|
if not admin_user:
|
||||||
|
return jsonify({'error': 'Administrator user not found'}), 404
|
||||||
|
|
||||||
|
admin_user_id = admin_user.get('id')
|
||||||
|
|
||||||
|
# Update the admin user with new email and password
|
||||||
|
update_response = requests.put(
|
||||||
|
f"{instance_url.rstrip('/')}/api/admin/contacts/{admin_user_id}",
|
||||||
|
headers={
|
||||||
|
'Authorization': f'Bearer {admin_token}',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json'
|
||||||
|
},
|
||||||
|
json={
|
||||||
|
'email': email,
|
||||||
|
'password': new_password,
|
||||||
|
'username': 'administrator',
|
||||||
|
'last_name': 'Administrator',
|
||||||
|
'role': 'admin'
|
||||||
|
},
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
|
|
||||||
|
if update_response.status_code != 200:
|
||||||
|
return jsonify({'error': f'Failed to update admin credentials: {update_response.text}'}), 400
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'message': 'Admin credentials updated successfully',
|
||||||
|
'data': {
|
||||||
|
'email': email,
|
||||||
|
'password': new_password,
|
||||||
|
'username': 'administrator',
|
||||||
|
'instance_url': instance_url
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.error(f"Error updating admin credentials: {str(e)}")
|
||||||
return jsonify({'error': str(e)}), 500
|
return jsonify({'error': str(e)}), 500
|
||||||
@@ -147,6 +147,30 @@ function initializeSteps() {
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
stepsContainer.appendChild(companyStep);
|
stepsContainer.appendChild(companyStep);
|
||||||
|
|
||||||
|
// Add Apply Colors step
|
||||||
|
const colorsStep = document.createElement('div');
|
||||||
|
colorsStep.className = 'step-item';
|
||||||
|
colorsStep.innerHTML = `
|
||||||
|
<div class="step-icon"><i class="fas fa-palette"></i></div>
|
||||||
|
<div class="step-content">
|
||||||
|
<h5>Apply Colors</h5>
|
||||||
|
<p class="step-status">Configuring color scheme...</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
stepsContainer.appendChild(colorsStep);
|
||||||
|
|
||||||
|
// Add Update Admin Credentials step
|
||||||
|
const credentialsStep = document.createElement('div');
|
||||||
|
credentialsStep.className = 'step-item';
|
||||||
|
credentialsStep.innerHTML = `
|
||||||
|
<div class="step-icon"><i class="fas fa-user-shield"></i></div>
|
||||||
|
<div class="step-content">
|
||||||
|
<h5>Update Admin Credentials</h5>
|
||||||
|
<p class="step-status">Setting up admin account...</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
stepsContainer.appendChild(credentialsStep);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startLaunch(data) {
|
async function startLaunch(data) {
|
||||||
@@ -548,9 +572,120 @@ async function startLaunch(data) {
|
|||||||
`;
|
`;
|
||||||
companyStep.querySelector('.step-content').appendChild(companyDetails);
|
companyStep.querySelector('.step-content').appendChild(companyDetails);
|
||||||
|
|
||||||
|
// Step 12: Apply Colors
|
||||||
|
await updateStep(12, 'Apply Colors', 'Configuring color scheme...');
|
||||||
|
const colorsResult = await applyColors(`https://${data.webAddresses[0]}`, data.colors);
|
||||||
|
|
||||||
|
if (!colorsResult.success) {
|
||||||
|
throw new Error(`Colors application failed: ${colorsResult.error}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the colors step to show success
|
||||||
|
const colorsStep = document.querySelectorAll('.step-item')[11];
|
||||||
|
colorsStep.classList.remove('active');
|
||||||
|
colorsStep.classList.add('completed');
|
||||||
|
colorsStep.querySelector('.step-status').textContent = 'Successfully applied color scheme';
|
||||||
|
|
||||||
|
// Add colors details
|
||||||
|
const colorsDetails = document.createElement('div');
|
||||||
|
colorsDetails.className = 'mt-3';
|
||||||
|
colorsDetails.innerHTML = `
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h6 class="card-title mb-3">Color Scheme Applied</h6>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Property</th>
|
||||||
|
<th>Value</th>
|
||||||
|
<th>Preview</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Primary Color</td>
|
||||||
|
<td>${data.colors.primary || 'Not set'}</td>
|
||||||
|
<td><div style="width: 30px; height: 20px; background-color: ${data.colors.primary || '#ccc'}; border: 1px solid #ddd;"></div></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Secondary Color</td>
|
||||||
|
<td>${data.colors.secondary || 'Not set'}</td>
|
||||||
|
<td><div style="width: 30px; height: 20px; background-color: ${data.colors.secondary || '#ccc'}; border: 1px solid #ddd;"></div></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
colorsStep.querySelector('.step-content').appendChild(colorsDetails);
|
||||||
|
|
||||||
|
// Step 13: Update Admin Credentials
|
||||||
|
await updateStep(13, 'Update Admin Credentials', 'Setting up admin account...');
|
||||||
|
const credentialsResult = await updateAdminCredentials(`https://${data.webAddresses[0]}`, data.company.email);
|
||||||
|
|
||||||
|
if (!credentialsResult.success) {
|
||||||
|
throw new Error(`Admin credentials update failed: ${credentialsResult.error}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the credentials step to show success
|
||||||
|
const credentialsStep = document.querySelectorAll('.step-item')[12];
|
||||||
|
credentialsStep.classList.remove('active');
|
||||||
|
credentialsStep.classList.add('completed');
|
||||||
|
credentialsStep.querySelector('.step-status').textContent = 'Successfully updated admin credentials';
|
||||||
|
|
||||||
|
// Add credentials details
|
||||||
|
const credentialsDetails = document.createElement('div');
|
||||||
|
credentialsDetails.className = 'mt-3';
|
||||||
|
credentialsDetails.innerHTML = `
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h6 class="card-title mb-3">Admin Credentials Updated</h6>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Property</th>
|
||||||
|
<th>Value</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Email Address</td>
|
||||||
|
<td>${credentialsResult.data.email || 'Not set'}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Password</td>
|
||||||
|
<td><code class="text-primary">${credentialsResult.data.password || 'Not set'}</code></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Username</td>
|
||||||
|
<td>${credentialsResult.data.username || 'administrator'}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Role</td>
|
||||||
|
<td><span class="badge bg-primary">Administrator</span></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="alert alert-warning mt-3">
|
||||||
|
<i class="fas fa-exclamation-triangle me-2"></i>
|
||||||
|
<strong>Important:</strong> Please save these credentials securely. The password will not be shown again.
|
||||||
|
</div>
|
||||||
|
<div class="alert alert-info mt-2">
|
||||||
|
<i class="fas fa-info-circle me-2"></i>
|
||||||
|
<strong>Login URL:</strong> <a href="https://${data.webAddresses[0]}" target="_blank">https://${data.webAddresses[0]}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
credentialsStep.querySelector('.step-content').appendChild(credentialsDetails);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Launch failed:', error);
|
console.error('Launch failed:', error);
|
||||||
await updateStep(11, 'Apply Company Information', `Error: ${error.message}`);
|
await updateStep(13, 'Update Admin Credentials', `Error: ${error.message}`);
|
||||||
showError(error.message);
|
showError(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1156,8 +1291,8 @@ function updateStep(stepNumber, title, description) {
|
|||||||
document.getElementById('currentStep').textContent = title;
|
document.getElementById('currentStep').textContent = title;
|
||||||
document.getElementById('stepDescription').textContent = description;
|
document.getElementById('stepDescription').textContent = description;
|
||||||
|
|
||||||
// Calculate progress based on total number of steps (11 steps total)
|
// Calculate progress based on total number of steps (13 steps total)
|
||||||
const totalSteps = 11;
|
const totalSteps = 13;
|
||||||
const progress = ((stepNumber - 1) / (totalSteps - 1)) * 100;
|
const progress = ((stepNumber - 1) / (totalSteps - 1)) * 100;
|
||||||
const progressBar = document.getElementById('launchProgress');
|
const progressBar = document.getElementById('launchProgress');
|
||||||
progressBar.style.width = `${progress}%`;
|
progressBar.style.width = `${progress}%`;
|
||||||
@@ -1599,4 +1734,80 @@ async function applyCompanyInformation(instanceUrl, company) {
|
|||||||
error: error.message
|
error: error.message
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function applyColors(instanceUrl, colors) {
|
||||||
|
try {
|
||||||
|
console.log('Applying colors to:', instanceUrl);
|
||||||
|
|
||||||
|
const response = await fetch('/api/admin/apply-colors', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
instance_url: instanceUrl,
|
||||||
|
colors_data: colors
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text();
|
||||||
|
throw new Error(`Failed to apply colors: ${errorText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
console.log('Colors applied successfully:', result);
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: result.message,
|
||||||
|
data: result.data
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error applying colors:', error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error.message
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateAdminCredentials(instanceUrl, email) {
|
||||||
|
try {
|
||||||
|
console.log('Updating admin credentials for:', instanceUrl);
|
||||||
|
|
||||||
|
const response = await fetch('/api/admin/update-admin-credentials', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
instance_url: instanceUrl,
|
||||||
|
email: email
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text();
|
||||||
|
throw new Error(`Failed to update admin credentials: ${errorText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
console.log('Admin credentials updated successfully:', result);
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: result.message,
|
||||||
|
data: result.data
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error updating admin credentials:', error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error.message
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user