diff --git a/app/main/routes.py b/app/main/routes.py index c70ad9e..bb56734 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -255,6 +255,24 @@ def objective_qrcode(objective_hash): @login_required def objective(objective_hash): objective = Objective.query.filter_by(hash=objective_hash).first_or_404() + if current_user.role_in_game(objective.game) == Role.bunny: + player = current_user.player_in(objective.game) + if not objective in player.found_objectives: + player.found_objectives.append(objective) + db.session.commit() + if objective.name: + flash(f'You found objective: {objective.name}!') + else: + flash('You found an objective!') + elif objective.name: + flash(f"You have already found objective '{objective.name}'") + else: + flash('You have already found this objective') + return redirect(url_for('main.game_dashboard', game_name=objective.game.name)) + elif not objective.owned_by(current_user): + flash("Only bunnies in an objective's game can find objectives!") + abort(403) + owner = objective.owned_by(current_user) qrcode = generate_qr_code(objective) if owner else None form = ObjectiveForm() diff --git a/app/templates/objective.html b/app/templates/objective.html index 47ac616..fc8c5ce 100644 --- a/app/templates/objective.html +++ b/app/templates/objective.html @@ -42,7 +42,9 @@ {% if objective.hash %}