|
|
@ -32,13 +32,27 @@ def create_game(): |
|
|
|
form = CreateGameForm() |
|
|
|
form = CreateGameForm() |
|
|
|
if form.validate_on_submit(): |
|
|
|
if form.validate_on_submit(): |
|
|
|
game = Game(name=form.game_name.data, start_time=form.start_time.data, end_time=form.end_time.data) |
|
|
|
game = Game(name=form.game_name.data, start_time=form.start_time.data, end_time=form.end_time.data) |
|
|
|
game.game_players.append(GamePlayer(game_player=current_user, role=Role['owner'])) |
|
|
|
game.game_players.append(GamePlayer(user=current_user, role=Role['owner'])) |
|
|
|
db.session.add(game) |
|
|
|
db.session.add(game) |
|
|
|
db.session.commit() |
|
|
|
db.session.commit() |
|
|
|
flash(f"'{game.name}' had been created!") |
|
|
|
flash(f"'{game.name}' had been created!") |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
return render_template('create_game.html', title='Create Game', form=form) |
|
|
|
return render_template('create_game.html', title='Create Game', form=form) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/game/<game_name>/delete') |
|
|
|
|
|
|
|
@login_required |
|
|
|
|
|
|
|
def delete_game(game_name): |
|
|
|
|
|
|
|
game = Game.query.filter_by(name=game_name).first_or_404() |
|
|
|
|
|
|
|
if not game.owned_by(current_user): |
|
|
|
|
|
|
|
abort(403) |
|
|
|
|
|
|
|
db.session.delete(game) |
|
|
|
|
|
|
|
for user in game.players: |
|
|
|
|
|
|
|
if not user.last_login: |
|
|
|
|
|
|
|
db.session.delete(user) |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
flash(f"Game '{game.name}' has been deleted!") |
|
|
|
|
|
|
|
return redirect(url_for('main.index')) |
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/game/<game_name>/dashboard') |
|
|
|
@bp.route('/game/<game_name>/dashboard') |
|
|
|
@login_required |
|
|
|
@login_required |
|
|
|
def game_dashboard(game_name): |
|
|
|
def game_dashboard(game_name): |
|
|
@ -70,8 +84,9 @@ def add_player(game_name): |
|
|
|
form_create = UserCreateForm() |
|
|
|
form_create = UserCreateForm() |
|
|
|
|
|
|
|
|
|
|
|
if form_add.submit_add.data and form_add.validate_on_submit(): |
|
|
|
if form_add.submit_add.data and form_add.validate_on_submit(): |
|
|
|
user = User.query.filter_by(form_add.name.data).first_or_404() |
|
|
|
user = User.query.filter_by(name=form_add.name.data).first_or_404() |
|
|
|
game.game_players.append(GamePlayer(user=user, role=Role[form_create.role.data])) |
|
|
|
game.game_players.append(GamePlayer(user=user, role=Role[form_create.role.data])) |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
|
|
|
|
|
|
|
|
if form_create.submit_create.data and form_create.validate_on_submit(): |
|
|
|
if form_create.submit_create.data and form_create.validate_on_submit(): |
|
|
@ -92,9 +107,12 @@ def remove_player(game_name, username): |
|
|
|
abort(403) |
|
|
|
abort(403) |
|
|
|
user = User.query.filter(and_(User.name == username, User.games.contains(game))).first_or_404() |
|
|
|
user = User.query.filter(and_(User.name == username, User.games.contains(game))).first_or_404() |
|
|
|
game.players.remove(user) |
|
|
|
game.players.remove(user) |
|
|
|
|
|
|
|
if not user.last_login: |
|
|
|
|
|
|
|
db.session.delete(user) |
|
|
|
db.session.commit() |
|
|
|
db.session.commit() |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/game/<game_name>/user/<username>', methods=['GET', 'POST']) |
|
|
|
@bp.route('/game/<game_name>/player/<username>', methods=['GET', 'POST']) |
|
|
|
@bp.route('/game/<game_name>/player/<username>', methods=['GET', 'POST']) |
|
|
|
@login_required |
|
|
|
@login_required |
|
|
|
def game_player(game_name, username): |
|
|
|
def game_player(game_name, username): |
|
|
|