config page

This commit is contained in:
Karl 2025-07-19 08:56:13 +01:00
parent 6cf291f857
commit e76a54854b
4 changed files with 79 additions and 27 deletions

20
app.py
View File

@ -298,6 +298,26 @@ def stream_names() -> Union[Response, str]:
return jsonify(get_stream_names(base_url, session["auth_credentials"]))
@app.route('/config', methods=['GET', 'POST'])
def config():
"""Handles access to the configuration page."""
if request.method == 'POST':
password = request.form.get('password')
if password == app.config['CONFIG_PASSWORD']:
session['config_logged_in'] = True
return redirect(url_for('config_dashboard'))
else:
return render_template('config.html', error='Invalid password')
return render_template('config.html')
@app.route('/config/dashboard')
def config_dashboard():
"""Renders the configuration dashboard."""
if not session.get('config_logged_in'):
return redirect(url_for('config'))
return render_template('config_dashboard.html')
if __name__ == "__main__":
app.run(
debug=app.config["DEBUG"],

View File

@ -46,7 +46,7 @@
</main>
<footer class="bg-dark text-white text-center py-3 mt-5">
<p>Version: <a href="#" id="version-link">{{ version }}</a></p>
<p>Version: <a href="{{ url_for('config') }}" style="color: inherit; text-decoration: none;">{{ version }}</a></p>
</footer>
<input type="hidden" id="is-logged-in" value="{{ 'true' if session.get('logged_in') else 'false' }}">
@ -82,32 +82,6 @@
}, function(err) {
console.log('ServiceWorker registration failed: ', err);
});
document.getElementById('version-link').addEventListener('click', function(event) {
event.preventDefault();
fetch('{{ url_for("send_test_notification") }}', {
method: 'POST'
}).then(response => {
console.log('Response status:', response.status);
console.log('Response headers:', response.headers);
return response.text().then(text => {
console.log('Response body:', text);
try {
return JSON.parse(text);
} catch (e) {
console.error('Failed to parse JSON:', e);
throw new Error('Server returned non-JSON response');
}
});
}).then(data => {
console.log('Parsed data:', data);
if (data.message) {
console.log(data.message);
}
}).catch(err => {
console.error('Error sending test notification:', err);
});
});
}
function askPermission(registration) {

27
templates/config.html Normal file
View File

@ -0,0 +1,27 @@
{% extends "base.html" %}
{% block title %}Config Access{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h3 class="text-center">Enter Password</h3>
</div>
<div class="card-body">
{% if error %}
<div class="alert alert-danger">{{ error }}</div>
{% endif %}
<form method="post" action="{{ url_for('config') }}">
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<button type="submit" class="btn btn-primary btn-block">Login</button>
</form>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,31 @@
{% extends "base.html" %}
{% block title %}Config Dashboard{% endblock %}
{% block content %}
<div class="container">
<h2>Configuration Dashboard</h2>
<p>Welcome to the configuration page.</p>
<button id="send-test-notification-btn" class="btn btn-primary">Send Test Notification</button>
</div>
{% endblock %}
{% block scripts %}
{{ super() }}
<script>
document.getElementById('send-test-notification-btn').addEventListener('click', function() {
fetch('{{ url_for("send_test_notification") }}', {
method: 'POST'
}).then(response => {
if (response.ok) {
alert('Test notification sent successfully!');
} else {
alert('Failed to send test notification.');
}
}).catch(err => {
console.error('Error sending test notification:', err);
alert('An error occurred while sending the test notification.');
});
});
</script>
{% endblock %}