diff options
| -rw-r--r-- | api/auth/login.py | 2 | ||||
| -rw-r--r-- | api/auth/login_token.py | 2 | ||||
| -rw-r--r-- | api/auth/signup.py | 2 | ||||
| -rw-r--r-- | api/auth/token.py | 2 | ||||
| -rw-r--r-- | api/db.py | 8 | ||||
| -rw-r--r-- | api/game/new.py | 2 | ||||
| -rw-r--r-- | api/game/socket.py | 10 | ||||
| -rw-r--r-- | api/main.py | 12 | ||||
| -rw-r--r-- | api/randid.py | 2 | ||||
| -rwxr-xr-x | api/tests.sh | 2 | ||||
| -rw-r--r-- | api/user/info.py | 2 | ||||
| -rw-r--r-- | requirements.txt | 6 | 
12 files changed, 37 insertions, 15 deletions
diff --git a/api/auth/login.py b/api/auth/login.py index e686b67..ae6ca96 100644 --- a/api/auth/login.py +++ b/api/auth/login.py @@ -1,5 +1,5 @@  from flask import Blueprint, request, make_response -from main import cursor +from db import cursor  import auth.token as token  import passwords diff --git a/api/auth/login_token.py b/api/auth/login_token.py index 1004543..5812189 100644 --- a/api/auth/login_token.py +++ b/api/auth/login_token.py @@ -1,5 +1,5 @@  from flask import Blueprint, request -from main import cursor +from db import cursor  from auth.token import validate_token, hash_token  def token_login(token): diff --git a/api/auth/signup.py b/api/auth/signup.py index e77f82d..69c786f 100644 --- a/api/auth/signup.py +++ b/api/auth/signup.py @@ -1,5 +1,5 @@  from flask import Blueprint, request, make_response -from main import cursor, connection +from db import cursor, connection  from randid import new_uuid  import auth.token as token  import passwords diff --git a/api/auth/token.py b/api/auth/token.py index a03d685..0085187 100644 --- a/api/auth/token.py +++ b/api/auth/token.py @@ -1,4 +1,4 @@ -from main import cursor, connection +from db import cursor, connection  import hashlib  import secrets  import json diff --git a/api/db.py b/api/db.py new file mode 100644 index 0000000..5448331 --- /dev/null +++ b/api/db.py @@ -0,0 +1,8 @@ +# dit bestand is hier om circular imports te vermijden +import os +import sqlite3 + +db_path = os.path.abspath("database/database.db") +connection = sqlite3.connect(db_path, check_same_thread=False) +#!                                    ^^^ Dit is onveilig en goede multithreading support moet nog geïmplementeerd worden +cursor = connection.cursor() diff --git a/api/game/new.py b/api/game/new.py index 6f777e3..fd65019 100644 --- a/api/game/new.py +++ b/api/game/new.py @@ -1,5 +1,5 @@  from flask import Blueprint, request, make_response -from main import cursor, connection +from db import cursor, connection  from randid import new_uuid  import time  import json diff --git a/api/game/socket.py b/api/game/socket.py new file mode 100644 index 0000000..405d9cd --- /dev/null +++ b/api/game/socket.py @@ -0,0 +1,10 @@ +from flask import Blueprint, request, make_response +from flask_socketio import SocketIO, emit, disconnect +from main import socketio +import time +import json + +@socketio.on("connect", namespace="/game/socket") +def connect(): +    print("connected") + diff --git a/api/main.py b/api/main.py index b9900f8..afa9871 100644 --- a/api/main.py +++ b/api/main.py @@ -1,13 +1,8 @@  from flask import Flask -import sqlite3 -import os +from flask_socketio import SocketIO  app = Flask(__name__) - -db_path = os.path.abspath("database/database.db") -connection = sqlite3.connect(db_path, check_same_thread=False) -#!                                    ^^^ Dit is onveilig en goede multithreading support moet nog geïmplementeerd worden -cursor = connection.cursor() +socketio = SocketIO(app)  from status import status  from user.info import info @@ -15,6 +10,7 @@ from auth.signup import signup  from auth.login import login  from auth.login_token import token  from game.new import new_game +import game.socket  app.register_blueprint(status, url_prefix='/')  app.register_blueprint(info, url_prefix='/user') @@ -23,3 +19,5 @@ app.register_blueprint(login, url_prefix='/auth')  app.register_blueprint(token, url_prefix='/auth')  app.register_blueprint(new_game, url_prefix='/game') +if __name__ == "__main__": +    socketio.run(app, host="127.0.0.1", port=5000, debug=True) diff --git a/api/randid.py b/api/randid.py index 645d0a0..837b0a1 100644 --- a/api/randid.py +++ b/api/randid.py @@ -1,4 +1,4 @@ -from main import cursor +from db import cursor  import uuid  tables = { diff --git a/api/tests.sh b/api/tests.sh index 3882699..1b2b216 100755 --- a/api/tests.sh +++ b/api/tests.sh @@ -41,7 +41,7 @@ user_info () {  		-d '{  		"username": "loekaars"  		}' \ -		localhost:5000/api/user/info +		localhost:5000/user/info  }  # login_token () { diff --git a/api/user/info.py b/api/user/info.py index 7bf3ee3..1339d8a 100644 --- a/api/user/info.py +++ b/api/user/info.py @@ -1,5 +1,5 @@  from flask import Blueprint, request -from main import cursor +from db import cursor  from auth.login_token import token_login  import json diff --git a/requirements.txt b/requirements.txt index 5e6511f..5a970c0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,11 @@  bcrypt==3.2.0 +bidict==0.21.2  cffi==1.14.4  click==7.1.2 +dnspython==1.16.0 +eventlet==0.30.1  Flask==1.1.2 +Flask-SocketIO==5.0.1  greenlet==1.0.0  itsdangerous==1.1.0  jedi==0.18.0 @@ -13,5 +17,7 @@ parso==0.8.1  pycparser==2.20  pynvim==0.4.2  python-dotenv==0.15.0 +python-engineio==4.0.0 +python-socketio==5.0.4  six==1.15.0  Werkzeug==1.0.1  |