diff --git a/undercover/routes.py b/undercover/routes.py index 65d6299..8c73330 100644 --- a/undercover/routes.py +++ b/undercover/routes.py @@ -108,8 +108,6 @@ def render_index( @writing_blueprint.route('/login', methods=['POST', 'GET']) def login() -> Response | str: - if request.form.get('confirm-password'): - return create_account() if request.method == 'POST': username = request.form['login'] if db.login(username, request.form['password']): @@ -120,6 +118,29 @@ def login() -> Response | str: return render_index(status=404) +@writing_blueprint.route('/create_account', methods=['POST']) +def create_account() -> Response: + email_address = request.form['login'] + password = request.form['password'] + + if password != request.form['confirm-password']: + return render_index(error="Password and confirm password must match!", status=400) + if 64 < len(password) < 8: + return render_index(error="Password must be between 8 and 64 characters", status=400) + + try: + validate_email(email_address, check_deliverability=True) + except EmailNotValidError as e: + return render_index(error=str(e), status=400) + + if db.get_user(email_address): + return render_index(error="A user with that email already exists!", status=400) + + db.add_user(email_address, password) + session['username'] = email_address + return redirect('/') + + @writing_blueprint.route('/logout', methods=['POST', 'GET']) def logout() -> Response: session.pop('username', None) @@ -185,22 +206,6 @@ def index_get() -> Response: return render_index(form=form) -@writing_blueprint.route('/create_account', methods=['POST']) -def create_account() -> Response: - email_address = request.form['login'] - try: - validate_email(email_address, check_deliverability=True) - except EmailNotValidError as e: - return render_index(error=str(e), status=401) - - if db.get_user(email_address): - return render_index(error="A user with that email already exists!", status=401) - - db.add_user(email_address, request.form['password']) - session['username'] = email_address - return redirect('/') - - @writing_blueprint.route('/reset', methods=['POST', 'GET']) def reset_password() -> Response | str: if request.method == 'POST': diff --git a/undercover/templates/_formhelpers.jinja2 b/undercover/templates/_formhelpers.jinja2 index 715e1fa..5cbc3fe 100644 --- a/undercover/templates/_formhelpers.jinja2 +++ b/undercover/templates/_formhelpers.jinja2 @@ -23,6 +23,18 @@ {% endmacro %} +{% macro form_submit_button(text, id, action, errors) %} + {{ text }} +{% endmacro %} + {% macro modal() %}