mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-11-14 21:37:17 +00:00
Fix form validation in webservice
This commit is contained in:
parent
cf464c1987
commit
fbd7bff85a
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user