100 lines
3.8 KiB
Python
100 lines
3.8 KiB
Python
|
from flask import Flask, jsonify
|
||
|
from flask_cors import CORS, cross_origin
|
||
|
from flask_jwt_extended import JWTManager
|
||
|
from flask_bcrypt import Bcrypt
|
||
|
import datetime
|
||
|
from reqhandlers import dbpan,dbusers,dbtype,dbacl,dbauth,dbbilling,dbcategory,dbcharges,dbcity,dbcnnstring,dbcollection,dbcountry,dbcustomer,dbdelnote,dbdeploye,dbemail,dbencoding,dbgeninv,dbgst,dbhash,dbinstance,dbinvoice,dbinvoicelineitem,dbipaddress,dbkyc,dbname,dborders,dborganization,dbpackage,dbpassword,dbpermission,dbphone,dbpincode,dbplan,dbplanbilling,dbplans,dbpo,dbportnumber,dbprod,dbrole,dbschema,dbstate,dbuac,dbuname,dbusagelimit
|
||
|
from reqhandlers.blocklist import BLOCKLIST
|
||
|
# from OpenSSL import SSL
|
||
|
|
||
|
x = datetime.datetime.now()
|
||
|
|
||
|
# context = SSL.Context(SSL.TLSv1_2_METHOD)
|
||
|
# context = ('certs/certificate.crt', 'certs/private.key')
|
||
|
|
||
|
# Initializing flask app
|
||
|
app = Flask(__name__)
|
||
|
#Cors headers
|
||
|
cors = CORS(app)
|
||
|
jwt=JWTManager(app)
|
||
|
#bcrypt=Bcrypt(app)
|
||
|
# Set default cors headers
|
||
|
app.config['CORS_HEADERS'] = 'Content-Type'
|
||
|
#Set Secret Key must and should for JWTManager of flask-jwt-extend
|
||
|
app.config['JWT_SECRET_KEY'] = "my top sceret don't see"
|
||
|
|
||
|
# Register blueprints for the api routes based on the required parameters and tables
|
||
|
app.register_blueprint(dbpan.dbpan)
|
||
|
app.register_blueprint(dbusers.users)
|
||
|
app.register_blueprint(dbtype.dbtype)
|
||
|
app.register_blueprint(dbacl.dbacl)
|
||
|
app.register_blueprint(dbauth.dbauth)
|
||
|
app.register_blueprint(dbbilling.dbbilling)
|
||
|
app.register_blueprint(dbcategory.dbcategory)
|
||
|
app.register_blueprint(dbcharges.dbcharges)
|
||
|
app.register_blueprint(dbcity.dbcity)
|
||
|
app.register_blueprint(dbcnnstring.dbcnnstring)
|
||
|
app.register_blueprint(dbcollection.dbcollection)
|
||
|
app.register_blueprint(dbcountry.dbcountry)
|
||
|
app.register_blueprint(dbcustomer.dbcustomer)
|
||
|
app.register_blueprint(dbdelnote.dbdelnote)
|
||
|
app.register_blueprint(dbdeploye.dbdeploye)
|
||
|
app.register_blueprint(dbemail.dbemail)
|
||
|
app.register_blueprint(dbencoding.dbencoding)
|
||
|
app.register_blueprint(dbgeninv.dbgeninv)
|
||
|
app.register_blueprint(dbgst.dbgst)
|
||
|
app.register_blueprint(dbhash.dbhash)
|
||
|
app.register_blueprint(dbinstance.dbinstance)
|
||
|
app.register_blueprint(dbinvoice.dbinvoice)
|
||
|
app.register_blueprint(dbinvoicelineitem.dbinvoicelineitem)
|
||
|
app.register_blueprint(dbipaddress.dbipaddress)
|
||
|
app.register_blueprint(dbkyc.dbkyc)
|
||
|
app.register_blueprint(dbname.dbname)
|
||
|
app.register_blueprint(dborders.dborders)
|
||
|
app.register_blueprint(dborganization.dborganization)
|
||
|
app.register_blueprint(dbpackage.dbpackage)
|
||
|
app.register_blueprint(dbpassword.dbpassword)
|
||
|
app.register_blueprint(dbpermission.dbpermission)
|
||
|
app.register_blueprint(dbpincode.dbpincode)
|
||
|
app.register_blueprint(dbphone.dbphone)
|
||
|
app.register_blueprint(dbplan.dbplan)
|
||
|
app.register_blueprint(dbplanbilling.dbplanbilling)
|
||
|
app.register_blueprint(dbplans.dbplans)
|
||
|
app.register_blueprint(dbpo.dbpo)
|
||
|
app.register_blueprint(dbportnumber.dbportnumber)
|
||
|
app.register_blueprint(dbprod.dbprod)
|
||
|
app.register_blueprint(dbrole.dbrole)
|
||
|
app.register_blueprint(dbschema.dbschema)
|
||
|
app.register_blueprint(dbstate.dbstate)
|
||
|
app.register_blueprint(dbuac.dbuac)
|
||
|
app.register_blueprint(dbuname.dbuname)
|
||
|
app.register_blueprint(dbusagelimit.dbusagelimit)
|
||
|
|
||
|
|
||
|
|
||
|
# Route for seeing a data
|
||
|
@app.route('/sampleapi', methods=["POST"])
|
||
|
@cross_origin()
|
||
|
def get_time():
|
||
|
# Returning an api for showing in reactjs
|
||
|
return {
|
||
|
'Name':"geek",
|
||
|
"Age":"22",
|
||
|
"Date":x,
|
||
|
"programming":"python"
|
||
|
}
|
||
|
#This is to implement Logout feature of flask-jwt-extend
|
||
|
@jwt.token_in_blocklist_loader
|
||
|
def check_if_token_in_blocklist(jwt_header, jwt_payload):
|
||
|
return jwt_payload["jti"] in BLOCKLIST
|
||
|
|
||
|
#Callback function used to return custom response of flask-jwt-extend
|
||
|
@jwt.revoked_token_loader
|
||
|
def revoked_token_callback(jwt_header, jwt_payload):
|
||
|
return jsonify({"Description": "User has been Loggedout", "err or": "Token Revoked"})
|
||
|
|
||
|
# Running app
|
||
|
if __name__ == '__main__':
|
||
|
app.run(host="0.0.0.0",debug=True)
|
||
|
# app.run(host="0.0.0.0",debug=True,ssl_context=context)
|