@ -115,11 +115,22 @@ def game_player(game_name, player_name):
@@ -115,11 +115,22 @@ def game_player(game_name, player_name):
gameplayer . role = Role [ form . role . data ]
db . session . commit ( )
return redirect ( url_for ( ' game_dashboard ' , game_name = game . name ) )
return render_template ( ' player.html ' , title = f ' { player . name } in { game_name } ' , game = game , player = player , form = form )
return render_template ( ' player.html ' , title = f ' { player . name } in { game_name } ' , game = game , player = player , form = form , json = json , location_encoder = LocationEncoder )
@app . route ( ' /player/<auth_hash>/qrcode.png ' )
@login_required
def player_qrcode ( auth_hash ) :
player = Player . query . filter_by ( auth_hash = auth_hash ) . first_or_404 ( )
if not is_player_game_owner ( player ) : abort ( 403 )
img = generate_qr_code ( url_for ( ' objective ' , objective_hash = objective . hash , _external = True ) )
return serve_pil_image ( img )
def is_game_owner ( game ) :
return current_user in [ gameplayer . player for gameplayer in game . game_players if gameplayer . role == Role . owner ]
def is_player_game_owner ( player ) :
return current_user in [ gameplayer . player for gameplayer in [ game for game in player . games ] . game_players if game_player . role == Role . owner ]
def is_objective_owner ( objective ) :
return current_user in [ gameplayer . player for gameplayer in objective . game . game_players if gameplayer . role == Role . owner ]
@ -149,14 +160,14 @@ def delete_objective(objective_hash):
@@ -149,14 +160,14 @@ def delete_objective(objective_hash):
db . session . commit ( )
return redirect ( url_for ( ' game_dashboard ' , game_name = objective . game . name ) )
def generate_objective_ qr_code ( objective ) :
def generate_qr_code ( url ) :
qr = qrcode . QRCode (
version = None ,
error_correction = qrcode . constants . ERROR_CORRECT_M ,
box_size = 30 ,
border = 4 ,
)
qr . add_data ( url_for ( ' objective ' , objective_hash = objective . hash , _external = True ) )
qr . add_data ( url )
qr . make ( fit = True )
return qr . make_image ( fill_color = ' black ' , back_color = ' white ' )
@ -172,7 +183,7 @@ def serve_pil_image(pil_img):
@@ -172,7 +183,7 @@ def serve_pil_image(pil_img):
def objective_qrcode ( objective_hash ) :
objective = Objective . query . filter_by ( hash = objective_hash ) . first_or_404 ( )
if not is_objective_owner ( objective ) : abort ( 403 )
img = generate_objective_qr_code ( objective )
img = generate_qr_code ( url_for ( ' objective ' , objective_hash = objective . hash , _external = True ) )
return serve_pil_image ( img )
@app . route ( ' /objective/<objective_hash> ' , methods = [ ' GET ' , ' POST ' ] )
@ -180,7 +191,7 @@ def objective_qrcode(objective_hash):
@@ -180,7 +191,7 @@ def objective_qrcode(objective_hash):
def objective ( objective_hash ) :
objective = Objective . query . filter_by ( hash = objective_hash ) . first_or_404 ( )
owner = is_objective_owner ( objective )
qrcode = generate_objective_ qr_code ( objective ) if owner else None
qrcode = generate_qr_code ( objective ) if owner else None
form = ObjectiveForm ( )
if form . submit . data and form . validate ( ) and owner :
objective . name = form . objective_name . data