2d842abe5b
Unit Tests / test (push) Successful in 15m39s
Reverts 8d1ef39. The installer must collect cell name, domain mode, and
provider tokens before 'make install' so that DDNS registration,
availability checks, and Caddy TLS can be configured at first boot.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
import logging
|
|
from flask import Blueprint, request, jsonify
|
|
|
|
logger = logging.getLogger('picell')
|
|
|
|
setup_bp = Blueprint('setup', __name__, url_prefix='/api/setup')
|
|
|
|
|
|
def _get_setup_manager():
|
|
from app import setup_manager
|
|
return setup_manager
|
|
|
|
|
|
@setup_bp.route('/status', methods=['GET'])
|
|
def get_setup_status():
|
|
"""Return wizard status and available options."""
|
|
sm = _get_setup_manager()
|
|
if sm.is_setup_complete():
|
|
return jsonify({'error': 'Setup already complete'}), 410
|
|
return jsonify(sm.get_setup_status())
|
|
|
|
|
|
@setup_bp.route('/validate', methods=['POST'])
|
|
def validate_setup_step():
|
|
"""Validate a single wizard step.
|
|
|
|
Expects JSON body: ``{'step': '<step_name>', 'data': {...}}``.
|
|
Supported steps: ``cell_name``, ``password``.
|
|
"""
|
|
sm = _get_setup_manager()
|
|
if sm.is_setup_complete():
|
|
return jsonify({'error': 'Setup already complete'}), 410
|
|
|
|
body = request.get_json(silent=True) or {}
|
|
step = body.get('step', '')
|
|
data = body.get('data', {})
|
|
|
|
if step == 'cell_name':
|
|
errors = sm.validate_cell_name(data.get('cell_name', ''))
|
|
elif step == 'password':
|
|
errors = sm.validate_password(data.get('password', ''))
|
|
else:
|
|
return jsonify({'valid': False, 'errors': [f"Unknown step: {step!r}"]}), 400
|
|
|
|
return jsonify({'valid': len(errors) == 0, 'errors': errors})
|
|
|
|
|
|
@setup_bp.route('/complete', methods=['POST'])
|
|
def complete_setup():
|
|
"""Complete the first-run wizard and create the admin account."""
|
|
sm = _get_setup_manager()
|
|
if sm.is_setup_complete():
|
|
return jsonify({'error': 'Setup already complete'}), 410
|
|
|
|
payload = request.get_json(silent=True) or {}
|
|
result = sm.complete_setup(payload)
|
|
status_code = 200 if result.get('success') else 400
|
|
return jsonify(result), status_code
|