diff --git a/app/auth/forms.py b/app/auth/forms.py index 58496277..43c4ae4d 100644 --- a/app/auth/forms.py +++ b/app/auth/forms.py @@ -23,10 +23,14 @@ class RegistrationForm(FlaskForm): ) password = PasswordField( 'Password', - validators=[DataRequired(), - EqualTo('password2', message='Passwords must match.')] + validators=[DataRequired(), EqualTo('password_confirmation', + message='Passwords must match.')] + ) + password_confirmation = PasswordField( + 'Password confirmation', + validators=[DataRequired(), EqualTo('password', + message='Passwords must match.')] ) - password2 = PasswordField('Confirm password', validators=[DataRequired()]) submit = SubmitField('Register') def validate_email(self, field): @@ -40,12 +44,12 @@ class RegistrationForm(FlaskForm): class ResetPasswordForm(FlaskForm): password = PasswordField( - 'New Password', - validators=[DataRequired(), - EqualTo('password2', message='Passwords must match')] + 'New password', + validators=[DataRequired(), EqualTo('password_confirmation', + message='Passwords must match.')] ) - password2 = PasswordField( - 'Confirm password', + password_confirmation = PasswordField( + 'Password confirmation', validators=[DataRequired(), EqualTo('password', message='Passwords must match.')] ) diff --git a/app/auth/views.py b/app/auth/views.py index d1b9967b..1d6dcaeb 100644 --- a/app/auth/views.py +++ b/app/auth/views.py @@ -26,6 +26,8 @@ def before_request(): @auth.route('/login', methods=['GET', 'POST']) def login(): + if current_user.is_authenticated: + return redirect(url_for('main.dashboard')) login_form = LoginForm(prefix='login-form') if login_form.validate_on_submit(): user = User.query.filter_by(email=login_form.email.data).first() @@ -111,7 +113,9 @@ def resend_confirmation(): def reset_password_request(): if current_user.is_authenticated: return redirect(url_for('main.dashboard')) - reset_password_request_form = ResetPasswordRequestForm() + reset_password_request_form = ResetPasswordRequestForm( + prefix='reset-password-request-form' + ) if reset_password_request_form.validate_on_submit(): submitted_email = reset_password_request_form.email.data user = User.query.filter_by(email=submitted_email.lower()).first() @@ -133,7 +137,7 @@ def reset_password_request(): def reset_password(token): if current_user.is_authenticated: return redirect(url_for('main.dashboard')) - reset_password_form = ResetPasswordForm() + reset_password_form = ResetPasswordForm(prefix='reset-password-form') if reset_password_form.validate_on_submit(): if User.reset_password(token, reset_password_form.password.data): db.session.commit() diff --git a/app/templates/auth/login.html.j2 b/app/templates/auth/login.html.j2 index c51e5d13..5e793459 100644 --- a/app/templates/auth/login.html.j2 +++ b/app/templates/auth/login.html.j2 @@ -36,7 +36,7 @@