Skip to content

Commit cd96835

Browse files
Update settings.py
1 parent fcab7bf commit cd96835

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

app/settings.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,27 @@ def index():
1212
return render_template('settings.html')
1313

1414
@settings_bp.route('/api/da-config', methods=['GET'])
15-
@login_required
15+
@login_required
1616
def get_da_config():
17-
return jsonify({
18-
'da_server': current_user.da_server or '',
19-
'da_username': current_user.da_username or '',
20-
'da_domain': current_user.da_domain or '',
21-
'has_password': bool(current_user.da_password_encrypted)
22-
})
17+
try:
18+
return jsonify({
19+
'da_server': current_user.da_server or '',
20+
'da_username': current_user.da_username or '',
21+
'da_domain': current_user.da_domain or '',
22+
'has_password': bool(current_user.da_password_encrypted)
23+
})
24+
except Exception as e:
25+
print(f"Error getting DA config: {e}")
26+
return jsonify({'error': str(e)}), 500
2327

2428
@settings_bp.route('/api/da-config', methods=['POST'])
2529
@login_required
2630
def update_da_config():
2731
try:
32+
# Ensure we have JSON data
33+
if not request.is_json:
34+
return jsonify({'error': 'Content-Type must be application/json'}), 400
35+
2836
data = request.json
2937
print(f"Received settings update: {data}") # Debug log
3038

@@ -34,6 +42,10 @@ def update_da_config():
3442
if not data.get(field):
3543
return jsonify({'error': f'{field} is required'}), 400
3644

45+
# Ensure user has encryption key
46+
if not current_user.encryption_key:
47+
current_user.generate_encryption_key()
48+
3749
# Update DirectAdmin settings
3850
current_user.da_server = data['da_server'].rstrip('/')
3951
current_user.da_username = data['da_username']
@@ -60,6 +72,10 @@ def update_da_config():
6072
def test_connection():
6173
"""Test DirectAdmin connection with provided credentials"""
6274
try:
75+
# Ensure we have JSON data
76+
if not request.is_json:
77+
return jsonify({'error': 'Content-Type must be application/json'}), 400
78+
6379
data = request.json
6480
print(f"Testing connection with: {data.get('da_server')}") # Debug log
6581

@@ -71,6 +87,10 @@ def test_connection():
7187
if not all([server, username, password]):
7288
return jsonify({'error': 'Missing credentials'}), 400
7389

90+
# Ensure server URL is properly formatted
91+
if not server.startswith(('http://', 'https://')):
92+
server = 'https://' + server
93+
7494
# Test connection
7595
api = DirectAdminAPI(server, username, password)
7696
success, message = api.test_connection()

0 commit comments

Comments
 (0)