Browse Source

Share session across domains and show game list with countdown

mistress
Daniel Muckerman 3 years ago
parent
commit
b1de54280a
2 changed files with 25 additions and 27 deletions
  1. +25
    -26
      app.py
  2. +0
    -1
      templates/card_list.j2

+ 25
- 26
app.py View File

@ -37,6 +37,7 @@ app.config['LDAP_OPENLDAP'] = True
app.config['LDAP_USER_OBJECT_FILTER'] = '(&(objectclass=posixAccount)(uid=%s))'
# Login cookies
app.config['SESSION_COOKIE_DOMAIN'] = os.environ.get('COOKIE_DOMAIN')
app.config['REMEMBER_COOKIE_DOMAIN'] = os.environ.get('COOKIE_DOMAIN')
db = SQLAlchemy(app)
@ -170,9 +171,11 @@ def game():
if (final_time - current_time).days > -1:
return render_template('final_countdown.j2', final_countdown = final_countdown_data)
if countdown_data != None:
if current_user.is_authenticated:
return render_template('games.j2', apps = games, search = search, account_url = account_url, description = game_description, countdown = countdown_data, game_list = generate_game_list(current_user.username))
return render_template('games.j2', apps = games, search = search, account_url = account_url, description = game_description, countdown = countdown_data)
if current_user.is_authenticated:
return render_template('games.j2', apps = games, search = search, account_url = account_url, description = game_description, user = current_user.get_user_dict(), game_list = generate_game_list())
return render_template('games.j2', apps = games, search = search, account_url = account_url, description = game_description, game_list = generate_game_list(current_user.username))
return render_template('games.j2', apps = games, search = search, account_url = account_url, description = game_description)
@ -180,7 +183,7 @@ def game():
def login():
if current_user.is_authenticated:
flash('You are already logged in.')
return redirect(url_for('auth.home'))
return redirect(url_for('index'))
form = LoginForm(request.form)
print(form)
@ -225,17 +228,17 @@ def add_game():
if request.method == 'POST':
game_title = request.form['game_title']
game_link = request.form['game_link']
conn = sqlite3.connect('config/games_in_progress.db')
c = conn.cursor()
games_conn = sqlite3.connect('config/games_in_progress.db')
c = games_conn.cursor()
if game_title is not None and len(game_title) > 0 and game_link is not None and len(game_link) > 0:
c.execute("INSERT INTO games (user_id, game_title, game_link) VALUES (?, ?, ?)", (current_user.username, game_title, game_link,))
conn.commit()
conn.close()
games_conn.commit()
games_conn.close()
return 'Success'
conn.commit()
conn.close()
games_conn.commit()
games_conn.close()
return 'Error'
@ -244,33 +247,29 @@ def add_game():
def delete_game():
if request.method == 'POST':
game_id = request.form['game_id']
conn = sqlite3.connect('config/games_in_progress.db')
c = conn.cursor()
games_conn = sqlite3.connect('config/games_in_progress.db')
c = games_conn.cursor()
if game_id is not None and len(game_id) > 0:
c.execute("DELETE FROM games WHERE id=? AND user_id=?", (game_id, session['user_id'],))
conn.commit()
conn.close()
c.execute("DELETE FROM games WHERE id=? AND user_id=?", (game_id, current_user.username,))
games_conn.commit()
games_conn.close()
return 'Success'
conn.commit()
conn.close()
games_conn.commit()
games_conn.close()
return 'Error'
def generate_game_list():
conn = sqlite3.connect('config/games_in_progress.db')
c = conn.cursor()
def generate_game_list(username):
games_conn = sqlite3.connect('config/games_in_progress.db')
c = games_conn.cursor()
if current_user.is_authenticated:
c.execute('SELECT * FROM games WHERE user_id=?', (current_user.username, ))
rows = c.fetchall()
conn.close()
return rows
c.execute('SELECT * FROM games WHERE user_id=?', (username, ))
rows = c.fetchall()
games_conn.close()
conn.close()
return []
return rows
@app.route('/logout')

+ 0
- 1
templates/card_list.j2 View File

@ -2,7 +2,6 @@
<div class="card" id="game-list">
<div class="card-body" style="padding-bottom: 0 !important;">
<h5 class="card-title" style="margin-bottom: 1.25rem !important;">Games In Progress</h5>
{{ current_user }}
{% if current_user.is_authenticated %}
<table class="table table-borderless" id="game-table">
<thead>

Loading…
Cancel
Save