Sometimes, you will want to give the user some feedback on an action they took. e.g. Was there an issue with login in? Are they typing in the wrong password or does their email not exist? It would be a good user experience if, in these situations, we told them what was wrong, instead of just constantly redirecting them back to the login page.
The easiest way to do this is through Flask Flash messages. They are messages that are sent to the template to be rendered just once. And they disappear when the page is reloaded.
https://flask.palletsprojects.com/en/2.3.x/patterns/flashing/
1. Update the /login
route so that if the user's email doesn't exist in the database, you send them a Flash message to let them know and redirect them back to the /login
route. e.g.
HINT: A <p>
tag in the login page will show up as red text.
2. Update the /login
route so that if the check_password()
function returns False
, you send a Flash message to the user when you redirect them back to the login page. e.g.
3. Update the /register
route so that if the user enters an email that already exists in the database, you redirect them to the login page and show a flash message to let them know they have already registered. e.g.