This commit is contained in:
moerp 2024-01-30 18:47:57 +01:00
parent 5583bc2b60
commit 794b50e041
2 changed files with 21 additions and 0 deletions

View File

@ -20,6 +20,7 @@ app.config.update({
oidc = OpenIDConnect(app)
def calculate_nutrition(food, weight):
try:
conn = psycopg2.connect()
@ -133,6 +134,12 @@ def add_nutrition():
def nutrition():
return render_template('nutrition.html')
@app.route('/get_token')
@oidc.require_login
def get_token():
return jsonify(token=oidc.get_access_token())
app = ProxyFix(app, x_for=1, x_host=1)

View File

@ -13,6 +13,17 @@
document.getElementById('submit-button').disabled = !allFilled;
}
function getBearerToken(callback) {
fetch('/get_token')
.then(response => response.json())
.then(data => {
callback(data.token);
})
.catch(error => {
console.error('Fehler beim Abrufen des Tokens:', error);
});
}
function addNutritionEntry() {
const form = document.getElementById('nutrition-form');
@ -20,6 +31,9 @@
fetch('/add_nutrition', {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + token
},
body: formData
}).then(response => {
// Behandlung der Serverantwort