initial commit

This commit is contained in:
2021-05-08 05:29:32 +02:00
commit 2707fad57f
1630 changed files with 125667 additions and 0 deletions

View File

View File

@@ -0,0 +1,22 @@
from flask import Blueprint, render_template
from flaskapp.lib.login import check_is_logged_in
from flaskapp.lib.toornament import get_toornament
bp = Blueprint('index', __name__)
@bp.route('/')
def index():
if check_is_logged_in():
toornament = get_toornament()
participations = toornament.get_participation_data()
tournaments = list()
for participation in participations:
tournament = toornament.get_tournament(participation['tournament_id'])
if tournament['discipline'] != 'leagueoflegends':
continue
tournament['participant_id'] = participation['id']
tournaments.append(tournament)
tournaments.reverse()
return render_template('home.html', tournaments=tournaments)
return render_template('home.html')

View File

@@ -0,0 +1,60 @@
from flask import Blueprint, redirect, url_for, request, flash, session
from flaskapp.lib.login import check_is_logged_in
from flaskapp.lib.toornament import get_toornament
from flaskapp.config import secret
import secrets
import urllib.parse
bp = Blueprint('login', __name__)
@bp.route('/login')
def login():
# if the user is logged in, redirect him to the next-URL or to the index page
if request.args.get('next'):
session['next_url'] = request.args.get('next')
if check_is_logged_in():
if request.args.get('next'):
return redirect(request.args.get('next'))
return redirect(url_for('index.index'))
state = secrets.token_hex(32)
session['state'] = state
params = {
'response_type': 'code',
'client_id': secret['oauth_client_id'],
'redirect_uri': secret['oauth_redirect_uri'],
'state': state,
'scope': 'user:info participant:manage_participations'
}
url = urllib.parse.urlencode(params)
url = 'https://account.toornament.com/oauth2/authorize?' + url
return redirect(url)
@bp.route('/oauth/toornament')
def oauth_callback():
state = request.args.get('state')
if state != session.get('state'):
flash('Login fehlgeschlagen! - Ungültiger OAuth2 State!', 'danger')
return redirect(url_for('index.index'))
code = request.args.get('code')
if not code:
flash('Login fehlgeschlagen!')
return redirect(url_for('index.index'))
toornament = get_toornament(code)
user_data = toornament.get_user_data()
session['is_logged_in'] = True
session['username'] = user_data['name']
session['user_id'] = user_data['id']
next_url = session.get('next_url')
if next_url:
session.pop('next_url')
return redirect(next_url)
return redirect(url_for('index.index'))
@bp.route('/logout')
def logout():
session.clear()
flash('Logout erfolgreich!', 'success')
return redirect(url_for('index.index'))

View File

@@ -0,0 +1,35 @@
from flask import Blueprint, render_template, request
from flaskapp.lib.toornament import get_toornament
import urllib.parse
bp = Blueprint('tournament', __name__)
@bp.route('/tournament/<int:tournament_id>')
def list_matches(tournament_id):
toornament = get_toornament()
tournament = toornament.get_tournament(tournament_id)
if request.args.get('participant_id'):
matches = toornament.get_matches(tournament_id, participant_id=request.args.get('participant_id'))
else:
matches = toornament.get_matches(tournament_id)
return render_template('match_list.html', matches=matches, tournament=tournament)
@bp.route('/tournament/<int:tournament_id>/match/<int:match_id>')
def show_match(tournament_id, match_id):
toornament = get_toornament()
tournament = toornament.get_tournament(tournament_id)
match = toornament.get_match(tournament_id, match_id)
participants = list()
for opponent in match['opponents']:
participant = toornament.get_participant(tournament_id, opponent['participant']['id'])
summoner_names = list()
for player in participant['lineup']:
summoner_names.append(player['custom_fields']['summoner_name'])
multilink_params = {
'query': ','.join(summoner_names)
}
participant['opgg_multilink'] = urllib.parse.urlencode(multilink_params)
participants.append(participant)
return render_template('match.html', match=match, participants=participants, tournament=tournament)