feat: implement authentication for adding and retrieving games
This commit is contained in:
parent
f078c27cb5
commit
99fc0e2cf8
@ -1,8 +1,8 @@
|
||||
from flask import Flask, request, jsonify
|
||||
from flask import Flask, request, jsonify, g
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from database import init_db
|
||||
from models import db, Game
|
||||
from user_management import user_bp
|
||||
from user_management import user_bp, authenticate
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
@ -19,6 +19,8 @@ with app.app_context():
|
||||
|
||||
@app.route('/games', methods=['POST'])
|
||||
def add_game():
|
||||
if not authenticate():
|
||||
return jsonify({'message': 'Unauthorized access!'}), 401
|
||||
data = request.json
|
||||
new_game = Game(
|
||||
image=data['image'],
|
||||
@ -33,6 +35,8 @@ def add_game():
|
||||
|
||||
@app.route('/games', methods=['GET'])
|
||||
def get_games():
|
||||
if not authenticate():
|
||||
return jsonify({'message': 'Unauthorized access!'}), 401
|
||||
games = Game.query.all()
|
||||
return jsonify([{
|
||||
'id': game.id,
|
||||
|
Loading…
Reference in New Issue
Block a user