def change_password(): """ The view a user uses to change their password. This will change their password straight away once they have authenticated, it will then send them a confirmation e-mail. """ form = ChangePasswordForm(request.form) if request.method == 'POST': if form.validate(): # User authenticates in the form # Update the users password! be_change_password(current_user['uid'], form.new_password.data) flash('We\'ve updated your password', 'success') # Inform the user via e-mail that their password has changed send_mail( 'Pjuu Account Notification - Password Changed', [current_user['email']], text_body=render_template('emails/password_change.txt'), html_body=render_template('emails/password_change.html') ) else: flash('Oh no! There are errors in your form', 'error') return render_template('change_password.html', form=form)
def reset(token): """ This view allows the user to create a new password so long as the token is valid. """ form = ResetForm(request.form) # Check the token but do not delete it. data = check_token(token, preserve=True) if data is not None and data.get('action') == 'reset': if request.method == 'POST': if form.validate(): # If the form was successful recheck the token but expire it. check_token(token) # Update the password and inform the users be_change_password(data['uid'], form.password.data) flash('Your password has now been reset', 'success') return redirect(url_for('signin')) else: flash('Oh no! There are errors in your form', 'error') else: flash('Invalid token', 'error') return redirect(url_for('signin')) return render_template('reset.html', form=form)
def reset(token): """ This view allows the user to create a new password so long as the token is valid. """ form = ResetForm(request.form) # Check the token but do not delete it. data = check_token(token, preserve=True) if data is not None and data.get('action') == 'reset': if request.method == 'POST': if form.validate(): # If the form was successful recheck the token but expire it. check_token(token) # Update the password and inform the users be_change_password(data['uid'], form.password.data) flash('Your password has now been reset', 'success') return redirect(url_for('auth.signin')) else: flash('Oh no! There are errors in your form', 'error') else: flash('Invalid token', 'error') return redirect(url_for('auth.signin')) return render_template('reset.html', form=form)
def change_password(): """ The view a user uses to change their password. This will change their password straight away once they have authenticated, it will then send them a confirmation e-mail. """ form = ChangePasswordForm(request.form) if request.method == 'POST': if form.validate(): # User authenticates in the form # Update the users password! be_change_password(current_user['_id'], form.new_password.data) flash('We\'ve updated your password', 'success') # Inform the user via e-mail that their password has changed send_mail('Pjuu Account Notification - Password Changed', [current_user['email']], text_body=render_template('emails/password_change.txt'), html_body=render_template('emails/password_change.html')) else: flash('Oh no! There are errors in your form', 'error') return render_template('change_password.html', form=form)