diff --git a/server.py b/server.py index 4084baeac..2406bbfc5 100644 --- a/server.py +++ b/server.py @@ -26,8 +26,12 @@ def index(): @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) + matching_clubs = [c for c in clubs if c['email'] == request.form['email']] + if not matching_clubs: + flash("Sorry, that email was not found.") + return redirect(url_for('index')) + club = matching_clubs[0] + return render_template('welcome.html', club=club, competitions=competitions) @app.route('/book//') diff --git a/templates/index.html b/templates/index.html index 926526b7d..ecfe61c61 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,6 +5,15 @@ GUDLFT Registration + {% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} + {% endwith %}

Welcome to the GUDLFT Registration Portal!

Please enter your secretary email to continue:
diff --git a/tests/integration/test_login.py b/tests/integration/test_login.py new file mode 100644 index 000000000..c7cc014af --- /dev/null +++ b/tests/integration/test_login.py @@ -0,0 +1,19 @@ +def test_login_with_valid_email_shows_summary(client): + """Happy path : un email connu doit afficher la page de résumé.""" + response = client.post( + "/showSummary", + data={"email": "john@simplylift.co"}, + ) + assert response.status_code == 200 + assert b"john@simplylift.co" in response.data + + +def test_login_with_unknown_email_does_not_crash(client): + """Sad path (bug #1) : un email inconnu ne doit pas faire planter l'appli.""" + response = client.post( + "/showSummary", + data={"email": "inconnu@test.com"}, + follow_redirects=True, + ) + assert response.status_code == 200 + assert b"Sorry, that email was not found." in response.data \ No newline at end of file