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 @@
@@ -44,7 +44,7 @@
- {{ login_form.submit(class='btn') }} +
diff --git a/app/templates/auth/register.html.j2 b/app/templates/auth/register.html.j2 index 0b73ecbe..7153f78b 100644 --- a/app/templates/auth/register.html.j2 +++ b/app/templates/auth/register.html.j2 @@ -29,9 +29,9 @@
vpn_key - {{ registration_form.password2(class='validate') }} - {{ registration_form.password2.label }} - {% for error in registration_form.password2.errors %} + {{ registration_form.password_confirmation(class='validate') }} + {{ registration_form.password_confirmation.label }} + {% for error in registration_form.password_confirmation.errors %} {{ error }} {% endfor %}
diff --git a/app/templates/auth/reset_password.html.j2 b/app/templates/auth/reset_password.html.j2 index d913ec5f..aaa918dd 100644 --- a/app/templates/auth/reset_password.html.j2 +++ b/app/templates/auth/reset_password.html.j2 @@ -12,22 +12,22 @@
{{ reset_password_form.hidden_tag() }}
- {{ reset_password_form.password(type='password') }} + {{ reset_password_form.password(class='validate') }} {{ reset_password_form.password.label }} {% for error in reset_password_form.password.errors %} {{ error }} {% endfor %}
- {{ reset_password_form.password2(type='password') }} - {{ reset_password_form.password2.label }} - {% for error in reset_password_form.password2.errors %} + {{ reset_password_form.password_confirmation(class='validate') }} + {{ reset_password_form.password_confirmation.label }} + {% for error in reset_password_form.password_confirmation.errors %} {{ error }} {% endfor %}
- {{ reset_password_form.submit(class='btn') }} +
diff --git a/app/templates/auth/reset_password_request.html.j2 b/app/templates/auth/reset_password_request.html.j2 index 5abb50b6..3eff233c 100644 --- a/app/templates/auth/reset_password_request.html.j2 +++ b/app/templates/auth/reset_password_request.html.j2 @@ -20,7 +20,7 @@
- {{ reset_password_request_form.submit(class='btn') }} +