some more preparational work done
This commit is contained in:
parent
1bca77bf12
commit
d4cad33513
@ -13,9 +13,11 @@ from .api import participant
|
||||
from .api import times
|
||||
from .api import notifications
|
||||
from .api import berths
|
||||
from .impl import util
|
||||
|
||||
|
||||
def create_app(test_config=None):
|
||||
global connection_pool
|
||||
app = Flask(__name__, instance_relative_config=True)
|
||||
app.config.from_mapping(
|
||||
SECRET_KEY='dev'
|
||||
@ -42,14 +44,26 @@ def create_app(test_config=None):
|
||||
logging.basicConfig(filename='brecal.log', level=logging.DEBUG, format='%(asctime)s | %(name)s | %(levelname)s | %(message)s')
|
||||
logging.info('App started')
|
||||
|
||||
conn_from_pool = mysql.connector.connect(
|
||||
pool_name="brecal_pool", pool_size=10, port=3306, user="ds", password="HalloWach23", database="bremen_calling"
|
||||
)
|
||||
try:
|
||||
connection_pool = mysql.connector.connect(
|
||||
host="lager",
|
||||
port=3306,
|
||||
user="ds",
|
||||
password="HalloWach23",
|
||||
pool_name="brecal_pool",
|
||||
pool_size=20,
|
||||
database="bremen_calling"
|
||||
)
|
||||
|
||||
# test connection
|
||||
commands = pydapper.using(conn_from_pool)
|
||||
data = commands.query_single("SELECT id from `user`")
|
||||
print(data)
|
||||
commands = pydapper.using(connection_pool)
|
||||
data = commands.query_single("SELECT id from `user`")
|
||||
print(data)
|
||||
|
||||
except mysql.connector.PoolError as e:
|
||||
logging.error(f"Failed to create connection pool: {e}")
|
||||
print(e)
|
||||
|
||||
sessions = dict()
|
||||
|
||||
return app
|
||||
|
||||
|
||||
@ -9,5 +9,5 @@ bp = Blueprint('verify', __name__)
|
||||
|
||||
@bp.route('/verify', methods=['get'])
|
||||
def GetVerify():
|
||||
|
||||
return impl.verify.GetVerify()
|
||||
apikey = request.headers.get('X-Api-Key')
|
||||
return impl.verify.GetVerify(apikey)
|
||||
|
||||
@ -1,22 +1,30 @@
|
||||
import json
|
||||
import logging
|
||||
import pydapper
|
||||
import mysql.connector
|
||||
|
||||
from ..schemas import model
|
||||
from ..schemas import __init__
|
||||
|
||||
def GetVerify(options):
|
||||
"""
|
||||
def GetVerify(apikey):
|
||||
"""
|
||||
:param apikey: the api-key registered with the user
|
||||
"""
|
||||
|
||||
"""
|
||||
print(options)
|
||||
sentinel = object()
|
||||
# 'mysql+pymysql://' + username + ':' + password + '@' + server + database
|
||||
# with connect("mysql+mysql://root:pydapper@localhost:3307/pydapper", autocommit=True) as commands:
|
||||
# data = commands.query_single_or_default("SELECT id from `user` WHERE api_key=?", )
|
||||
# Implement your business logic here
|
||||
# All the parameters are present in the options argument
|
||||
if not apikey
|
||||
return json.dumps("missing api key"), 400
|
||||
|
||||
return json.dumps("<integer>"), 200
|
||||
sentinel = object()
|
||||
try:
|
||||
commands = pydapper.using(__init__.connection_pool)
|
||||
data = commands.query_single_or_default("SELECT id from `user` WHERE api_key=?api_key?", default=sentinel, model=model.User, param={"api_key" : apikey})
|
||||
if(data is sentinel):
|
||||
return json.dumps("wrong api key", 403)
|
||||
|
||||
except Exception as ex:
|
||||
return json.dumps("logon failed"), 500
|
||||
logging.error(e)
|
||||
|
||||
return json.dumps("<integer>"), 200
|
||||
|
||||
|
||||
|
||||
|
||||
@ -77,3 +77,12 @@ class Shipcalls(Shipcall):
|
||||
|
||||
class TimesList(Times):
|
||||
pass
|
||||
|
||||
class User(Schema):
|
||||
id = fields.Int()
|
||||
participant_id = fields.Int()
|
||||
first_name = fields.String()
|
||||
last_name = fields.String()
|
||||
user_name = fields.String()
|
||||
password_hash = fields.String()
|
||||
api_key = fields.String()
|
||||
|
||||
Reference in New Issue
Block a user