Skip to content

Commit

Permalink
ERROR: Entering a unknown email crashes the app OpenClassrooms-Studen…
Browse files Browse the repository at this point in the history
  • Loading branch information
massouathyassine committed May 6, 2022
1 parent 81e09c8 commit 72e948b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 24 additions & 13 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import json
from flask import Flask,render_template,request,redirect,flash,url_for
from flask import Flask, render_template, request, redirect, flash, url_for


def loadClubs():
with open('clubs.json') as c:
listOfClubs = json.load(c)['clubs']
return listOfClubs
listOfClubs = json.load(c)['clubs']
return listOfClubs


def loadCompetitions():
with open('competitions.json') as comps:
listOfCompetitions = json.load(comps)['competitions']
return listOfCompetitions
listOfCompetitions = json.load(comps)['competitions']
return listOfCompetitions


app = Flask(__name__)
Expand All @@ -20,33 +20,44 @@ def loadCompetitions():
competitions = loadCompetitions()
clubs = loadClubs()


@app.route('/')
def index():
return render_template('index.html')

@app.route('/showSummary',methods=['POST'])

@app.route('/showSummary', methods=['POST'])
def showSummary():
club = [club for club in clubs if club['email'] == request.form['email']][0]
return render_template('welcome.html',club=club,competitions=competitions)
email = request.form['email']
club = [club for club in clubs if club['email'] == email]
if email:
if club:
return render_template('welcome.html', club=club, competitions=competitions)
else:
flash("Adresse email non autorisée ! Merci de contacter l'admin de site")
return redirect(url_for('index'))
else:
flash("Veuillez saisir une adresse email !")
return redirect(url_for('index'))


@app.route('/book/<competition>/<club>')
def book(competition,club):
def book(competition, club):
foundClub = [c for c in clubs if c['name'] == club][0]
foundCompetition = [c for c in competitions if c['name'] == competition][0]
if foundClub and foundCompetition:
return render_template('booking.html',club=foundClub,competition=foundCompetition)
return render_template('booking.html', club=foundClub, competition=foundCompetition)
else:
flash("Something went wrong-please try again")
return render_template('welcome.html', club=club, competitions=competitions)


@app.route('/purchasePlaces',methods=['POST'])
@app.route('/purchasePlaces', methods=['POST'])
def purchasePlaces():
competition = [c for c in competitions if c['name'] == request.form['competition']][0]
club = [c for c in clubs if c['name'] == request.form['club']][0]
placesRequired = int(request.form['places'])
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired
flash('Great-booking complete!')
return render_template('welcome.html', club=club, competitions=competitions)

Expand All @@ -56,4 +67,4 @@ def purchasePlaces():

@app.route('/logout')
def logout():
return redirect(url_for('index'))
return redirect(url_for('index'))
9 changes: 9 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@ <h1>Welcome to the GUDLFT Registration Portal!</h1>
<input type="email" name="email" id=""/>
<button type="submit">Enter</button>
</form>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul class=flashes>
{% for message in messages %}
<li style="color: #ff5b00">{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
</body>
</html>

0 comments on commit 72e948b

Please sign in to comment.