Files
MermsCoreBackendFlask/services/web/project/__init__.py
T
CHIEFSOFT\ameye 321b4fb49c Added more backend
2024-12-08 07:18:59 -05:00

90 lines
2.2 KiB
Python

import os
import psycopg2
from dotenv import load_dotenv
from flask import (
Flask,
jsonify,
send_from_directory,
request,
)
from flask_sqlalchemy import SQLAlchemy
from werkzeug.utils import secure_filename
load_dotenv()
app = Flask(__name__)
app.config.from_object("project.config.Config")
db = SQLAlchemy(app)
class User(db.Model):
__tablename__ = "users"
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(128), unique=True, nullable=False)
active = db.Column(db.Boolean(), default=True, nullable=False)
def __init__(self, email):
self.email = email
dataUrl = os.getenv("DATABASE_URL")
connection = psycopg2.connect(dataUrl)
@app.route("/")
def hello_world():
GLOBAL_AVG = """SELECT * FROM members WHERE id = 1;"""
with connection:
with connection.cursor() as cursor:
cursor.execute(GLOBAL_AVG)
account = cursor.fetchone()
#return jsonify(hello="ameye world")
return {"account": account}
@app.route("/auth/login")
def statrt_login():
return jsonify(hello="ameye world")
@app.route("/auth/register")
def start_register():
return jsonify(hello="ameye world")
@app.route("/auth/resetpass")
def start_resetpass():
return jsonify(hello="ameye world")
@app.route("/account")
def account():
return jsonify(hello="ameye world")
@app.route("/account/dash")
def dashboard():
return jsonify(hello="ameye world")
@app.route("/static/<path:filename>")
def staticfiles(filename):
return send_from_directory(app.config["STATIC_FOLDER"], filename)
@app.route("/media/<path:filename>")
def mediafiles(filename):
return send_from_directory(app.config["MEDIA_FOLDER"], filename)
@app.route("/upload", methods=["GET", "POST"])
def upload_file():
if request.method == "POST":
file = request.files["file"]
filename = secure_filename(file.filename)
file.save(os.path.join(app.config["MEDIA_FOLDER"], filename))
return """
<!doctype html>
<title>upload new File</title>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file><input type=submit value=Upload>
</form>
"""