From bb9a6c6a384e02364e4eb10ef560b4fd4f05e5f0 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 2 Feb 2016 04:32:34 +0100 Subject: forms: No need to supply request.form to the Forms The wtforms classes get the request data by default. --- accounts/views/admin/__init__.py | 5 +++-- accounts/views/default/__init__.py | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/accounts/views/admin/__init__.py b/accounts/views/admin/__init__.py index d008d98..5c908a1 100644 --- a/accounts/views/admin/__init__.py +++ b/accounts/views/admin/__init__.py @@ -32,7 +32,7 @@ def index(): @templated('admin/create_account.html') def create_account(): form = AdminCreateAccountForm() - if request.method == 'POST' and form.validate(): + if form.validate_on_submit(): current_app.mail_backend.send(form.mail.data, 'mail/register.txt', username=form.username.data) @@ -64,7 +64,8 @@ def disable_account(): form = AdminDisableAccountForm() if 'uid' in request.args: form = AdminDisableAccountForm(username=request.args['uid']) - if request.method == 'POST' and form.validate(): + + if form.validate_on_submit(): random_pw = str(uuid4()) form.user.change_password(random_pw) for service in current_app.all_services: diff --git a/accounts/views/default/__init__.py b/accounts/views/default/__init__.py index eec173e..a3e6c0e 100644 --- a/accounts/views/default/__init__.py +++ b/accounts/views/default/__init__.py @@ -21,7 +21,7 @@ bp = Blueprint('default', __name__) @templated('register.html') @logout_required def register(): - form = RegisterForm(request.form) + form = RegisterForm() if form.validate_on_submit(): current_app.mail_backend.send(form.mail.data, 'mail/register.txt', username=form.username.data) @@ -51,7 +51,7 @@ def register_complete(token): flash(u'Du hast den Benutzer bereits angelegt! Du kannst dich jetzt einfach einloggen:') return redirect(url_for('.index')) - form = RegisterCompleteForm(request.form) + form = RegisterCompleteForm() if form.validate_on_submit(): password = form.password.data @@ -79,7 +79,7 @@ def register_complete(token): @templated('lost_password.html') @logout_required def lost_password(): - form = LostPasswordForm(request.form) + form = LostPasswordForm() if form.validate_on_submit(): #TODO: make the link only usable once (e.g include a hash of the old pw) # atm the only thing we do is make the link valid for only little time @@ -100,7 +100,7 @@ def lost_password(): def lost_password_complete(token): username = Confirmation('lost_password').loads_http(token, max_age=4*60*60) - form = RegisterCompleteForm(request.form) + form = RegisterCompleteForm() if form.validate_on_submit(): user = current_app.user_backend.get_by_uid(username) user.change_password(form.password.data) @@ -121,7 +121,7 @@ def lost_password_complete(token): @templated('index.html') @login_required def index(): - form = SettingsForm(request.form, mail=current_user.mail) + form = SettingsForm(mail=current_user.mail) if form.validate_on_submit(): changed = False -- cgit v1.2.3-1-g7c22