middle added
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import os
|
||||
import psycopg2
|
||||
from dotenv import load_dotenv
|
||||
from functools import wraps
|
||||
import datetime
|
||||
import jwt
|
||||
|
||||
from flask import (
|
||||
Flask,
|
||||
@@ -16,7 +19,22 @@ load_dotenv()
|
||||
app = Flask(__name__)
|
||||
app.config.from_object("project.config.Config")
|
||||
db = SQLAlchemy(app)
|
||||
app.config['SECRET_KEY'] ='thisisourwondefulkey'
|
||||
|
||||
def token_required(f):
|
||||
@wraps(f)
|
||||
def decorated(*args, **kwargs):
|
||||
token = request.args.get('token')
|
||||
|
||||
if not token:
|
||||
return jsonify({'message': 'Error - missing token'}), 403
|
||||
try:
|
||||
data = jwt.decode(token, app.config['SECRET_KEY'])
|
||||
except:
|
||||
return jsonify({'message': 'Token is invalid'}),403
|
||||
|
||||
return f(*args, **kwargs)
|
||||
return decorated
|
||||
|
||||
class User(db.Model):
|
||||
__tablename__ = "users"
|
||||
@@ -42,27 +60,66 @@ def hello_world():
|
||||
return {"account": account}
|
||||
|
||||
|
||||
@app.route("/auth/login")
|
||||
def statrt_login():
|
||||
@app.route("/panel/auth/login", methods=["POST"])
|
||||
def start_login():
|
||||
try:
|
||||
data = request.json
|
||||
if not data:
|
||||
return {
|
||||
"message": "Please provide user details",
|
||||
"data": None,
|
||||
"error": "Bad request"
|
||||
}, 400
|
||||
|
||||
return jsonify(hello="ameye 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")
|
||||
token = jwt.encode({'user': 'account', 'exp' : datetime.datetime.utcnow() + datetime.timedelta(minutes=30)},app.config['SECRET_KEY'] )
|
||||
# return {"account": account}
|
||||
return {"token": token}
|
||||
|
||||
@app.route("/auth/register")
|
||||
except Exception as e:
|
||||
return {
|
||||
"message": "Something went wrong!",
|
||||
"error": str(e),
|
||||
"data": None
|
||||
}, 500
|
||||
|
||||
|
||||
|
||||
@app.route("/panel/auth/register")
|
||||
def start_register():
|
||||
return jsonify(hello="ameye world")
|
||||
|
||||
@app.route("/auth/resetpass")
|
||||
@app.route("/panel/auth/resetpass")
|
||||
def start_resetpass():
|
||||
return jsonify(hello="ameye world")
|
||||
|
||||
@app.route("/account")
|
||||
|
||||
|
||||
@app.route("/panel/account")
|
||||
@token_required
|
||||
def account():
|
||||
return jsonify(hello="ameye world")
|
||||
|
||||
@app.route("/account/dash")
|
||||
@app.route("/panel/account/dash")
|
||||
@token_required
|
||||
def dashboard():
|
||||
return jsonify(hello="ameye world")
|
||||
|
||||
@app.route("/panel/account/products")
|
||||
@token_required
|
||||
def panel_products():
|
||||
return jsonify(hello="ameye world")
|
||||
|
||||
@app.route("/panel/account/actions")
|
||||
@token_required
|
||||
def recent_actions():
|
||||
return jsonify(hello="ameye world")
|
||||
|
||||
|
||||
@app.route("/static/<path:filename>")
|
||||
def staticfiles(filename):
|
||||
|
||||
Reference in New Issue
Block a user