diff --git a/app/auth/forms.py b/app/auth/forms.py index 584962775c47cbbf1a745b9c80865587e5d0110c..43c4ae4d566b8ba341cf01673c880fefe41c5c9c 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 d1b9967b86e6aa625192e42f0870a2061f592848..1d6dcaeb6ee9886e38c72d97942802f949281834 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 c51e5d13c780d82ee3bc00f8597a98fa3ab4aef1..5e79345936eb94a4c51f363acb1b9693e4871402 100644 --- a/app/templates/auth/login.html.j2 +++ b/app/templates/auth/login.html.j2 @@ -36,7 +36,7 @@ <div class="switch"> <label> Remember me - {{ login_form.remember_me() }} + {{ login_form.remember_me(class='validate') }} <span class="lever"></span> </label> </div> @@ -44,7 +44,7 @@ </div> </div> <div class="card-action right-align"> - {{ login_form.submit(class='btn') }} + <button class="btn waves-effect waves-light" id="login-form-submit" name="login-form-submit" type="submit">Log in<i class="material-icons right">send</i></button> </div> </form> </div> diff --git a/app/templates/auth/register.html.j2 b/app/templates/auth/register.html.j2 index 0b73ecbe966eb9e78a1462cfe33255dedad4d501..7153f78baae9fb6c0eda41ed315c332af3e84f0b 100644 --- a/app/templates/auth/register.html.j2 +++ b/app/templates/auth/register.html.j2 @@ -29,9 +29,9 @@ </div> <div class="input-field"> <i class="material-icons prefix">vpn_key</i> - {{ 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 %} <span class="helper-text red-text">{{ error }}</span> {% endfor %} </div> diff --git a/app/templates/auth/reset_password.html.j2 b/app/templates/auth/reset_password.html.j2 index d913ec5f38b3ae9b8bcabe2ed39405a2e26151a0..aaa918dd81cc2b4ddc47856e86763c4e13c7b2e3 100644 --- a/app/templates/auth/reset_password.html.j2 +++ b/app/templates/auth/reset_password.html.j2 @@ -12,22 +12,22 @@ <div class="card-content"> {{ reset_password_form.hidden_tag() }} <div class="input-field"> - {{ 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 %} <span class="helper-text red-text">{{ error }}</span> {% endfor %} </div> <div class="input-field"> - {{ 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 %} <span class="helper-text red-text">{{ error }}</span> {% endfor %} </div> </div> <div class="card-action right-align"> - {{ reset_password_form.submit(class='btn') }} + <button class="btn waves-effect waves-light" id="reset-password-form-submit" name="reset-password-form-submit" type="submit">Reset Password<i class="material-icons right">send</i></button> </div> </form> </div> diff --git a/app/templates/auth/reset_password_request.html.j2 b/app/templates/auth/reset_password_request.html.j2 index 5abb50b64473f7666c4a9df22c9e0bde05b8b11f..3eff233c220ca804fd223be202a72347ded8996e 100644 --- a/app/templates/auth/reset_password_request.html.j2 +++ b/app/templates/auth/reset_password_request.html.j2 @@ -20,7 +20,7 @@ </div> </div> <div class="card-action right-align"> - {{ reset_password_request_form.submit(class='btn') }} + <button class="btn waves-effect waves-light" id="reset-password-request-form-submit" name="reset-password-request-form-submit" type="submit">Reset Password<i class="material-icons right">send</i></button> </div> </form> </div>