From fbd7bff85ac51587d2783d1f248f3c8baf7d4be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sat, 28 Apr 2018 18:31:50 +0200 Subject: [PATCH] Fix form validation in webservice --- solvable/src/webservice/server.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/solvable/src/webservice/server.py b/solvable/src/webservice/server.py index d7d1361..cde4b42 100644 --- a/solvable/src/webservice/server.py +++ b/solvable/src/webservice/server.py @@ -36,7 +36,10 @@ def index(): @app.route('/register', methods=['GET', 'POST']) def register(): if request.method == 'POST': - validate_register_fields(request.form.to_dict()) + if not all([request.form.get('username'), request.form.get('password'), request.form.get('passwordconfirm')]): + return render_template('register.html', alert='You need to fill everything.') + if request.form['password'] != request.form['passwordconfirm']: + return render_template('register.html', alert='Passwords do not match! Please try again.') with Session() as db: if db.query(User).filter(User.username == request.form['username']).all(): @@ -51,13 +54,6 @@ def register(): return render_template('register.html') -def validate_register_fields(request): - if not request.form['username'] or not request.form['password'] or not request.form['passwordconfirm']: - return render_template('register.html', alert='You need to fill everything.') - if request.form['password'] != request.form['passwordconfirm']: - return render_template('register.html', alert='Passwords do not match! Please try again.') - - @app.route('/logout') def logout(): try: