Fix up forms to grab values in certain cases

This commit is contained in:
Matt Wright
2012-08-16 18:31:32 -04:00
parent 96e11916af
commit 704af1011a
3 changed files with 12 additions and 7 deletions
+1 -1
View File
@@ -342,7 +342,7 @@ class AuthenticationProvider(object):
raise exceptions.BadCredentialsError('Specified user does not exist.')
if requires_confirmation(user):
raise exceptions.ConfirmationError('Email requires confirmation.')
raise exceptions.ConfirmationError('Email requires confirmation.', user)
# compare passwords
if verify_password(password, user.password,
+8 -2
View File
@@ -51,11 +51,16 @@ class PasswordConfirmFormMixin():
validators=[EqualTo('password', message="Passwords do not match")])
class ResendConfirmationForm(Form, UserEmailFormMixin):
class SendConfirmationForm(Form, UserEmailFormMixin):
"""The default forgot password form"""
submit = SubmitField("Resend Confirmation Instructions")
def __init__(self, *args, **kwargs):
super(SendConfirmationForm, self).__init__(*args, **kwargs)
if request.method == 'GET':
self.email.data = request.args.get('email', None)
def to_dict(self):
return dict(email=self.email.data)
@@ -77,7 +82,8 @@ class PasswordlessLoginForm(Form, EmailFormMixin):
def __init__(self, *args, **kwargs):
super(PasswordlessLoginForm, self).__init__(*args, **kwargs)
self.next.data = request.args.get('next', None)
if request.method == 'GET':
self.next.data = request.args.get('next', None)
def to_dict(self):
return dict(email=self.email.data)
+3 -4
View File
@@ -15,12 +15,11 @@ from werkzeug.datastructures import MultiDict
from werkzeug.local import LocalProxy
from flask_security.confirmable import confirm_by_token, reset_confirmation_token
from flask_security.core import current_user
from flask_security.decorators import login_required
from flask_security.exceptions import ConfirmationError, BadCredentialsError, \
ResetPasswordError, PasswordlessLoginError
from flask_security.forms import LoginForm, RegisterForm, ForgotPasswordForm, \
ResetPasswordForm, ResendConfirmationForm, PasswordlessLoginForm
ResetPasswordForm, SendConfirmationForm, PasswordlessLoginForm
from flask_security.passwordless import send_login_instructions, login_by_token
from flask_security.recoverable import reset_by_token, \
reset_password_reset_token
@@ -84,7 +83,7 @@ def authenticate():
except ConfirmationError, e:
msg = str(e)
confirm_url = url_for_security('send_confirmation')
confirm_url = url_for_security('send_confirmation', email=e.user.email)
except BadCredentialsError, e:
msg = str(e)
@@ -189,7 +188,7 @@ def token_login(token):
def send_confirmation():
"""View function which sends confirmation instructions."""
form = ResendConfirmationForm(csrf_enabled=not app.testing)
form = SendConfirmationForm(csrf_enabled=not app.testing)
if form.validate_on_submit():
user = _datastore.find_user(**form.to_dict())