You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
from flask import render_template, Blueprint, request
|
|
from flask_login import login_user, current_user, logout_user, login_required
|
|
from flask_wtf import FlaskForm
|
|
from wtforms import StringField
|
|
import iot.theme as theme
|
|
from iot.blueprints.user.models import Users, User_Roles
|
|
import iot.blueprints.database.utils as dbUtils
|
|
import json
|
|
import os
|
|
|
|
main = Blueprint('main', __name__, template_folder='templates')
|
|
|
|
DATA_FILE = 'data.json'
|
|
|
|
class LoginForm(FlaskForm):
|
|
username = StringField('username')
|
|
password = StringField('password')
|
|
|
|
|
|
@main.route('/', methods=['GET', 'POST'])
|
|
def index():
|
|
return render_template('/main/index.html', info="", theme=theme)
|
|
|
|
|
|
@main.route('/callback', methods=['POST'])
|
|
def callback():
|
|
data = request.json
|
|
|
|
if not data:
|
|
return jsonify({"error": "Invalid data"}), 400
|
|
|
|
# Read existing data
|
|
if os.path.exists(DATA_FILE):
|
|
with open(DATA_FILE, 'r') as f:
|
|
stored_data = json.load(f)
|
|
else:
|
|
stored_data = []
|
|
|
|
# Append new data
|
|
stored_data.append(data)
|
|
|
|
# Write data back to file
|
|
with open(DATA_FILE, 'w') as f:
|
|
json.dump(stored_data, f, indent=4)
|
|
|
|
return 'Callback received', 200
|
|
|
|
@main.route('/data', methods=['GET'])
|
|
def get_data():
|
|
if os.path.exists(DATA_FILE):
|
|
with open(DATA_FILE, 'r') as f:
|
|
stored_data = json.load(f)
|
|
else:
|
|
stored_data = []
|
|
|
|
return jsonify(stored_data)
|