def reset_token(token): if current_user.is_authenticated: return redirect(url_for('welcome')) user = User.verify_reset_token(token) if user is None: flash('That is invalid or expired token', 'warning') return redirect(url_for('reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): try: hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash( 'Your Your Password has been updated, You are now able to Log In', 'success') return redirect(url_for('login')) except: db.session.rollback() finally: db.session.close() return render_template('reset_token.html', title='Reset Password', form=form)
def reset_password(token): if current_user.is_authenticated: return redirect(url_for('index')) user = User.verify_reset_password_token(token) if not user: return redirect(url_for('index')) form = ResetPasswordForm() if form.validate_on_submit(): user.set_password(form.password.data) db.session.commit() flash('Your password has been resetted') return redirect(url_for('login')) return render_template('reset_password.html', form=form)
def reset_password(): if current_user.is_authenticated: return redirect(url_for('login')) form = ResetPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') # hash the user password user = User(password=hashed_password) db.session.commit() flash(f'Your password has been updated successfully', 'success') return redirect(url_for('login')) else: flash( f'This email is incorrect or does not exist, please check or register for an account' ) return redirect(url_for('register')) return render_template('reset_password.html', title='Reset Password', form=form)
def reset_token(token): if current_user.is_authenticated: return redirect(url_for('homePage')) user = User.verify_reset_token(token) if user is None: # If the token is wrong or expired flash('That is an invalid or expired token', 'warning') return redirect(url_for('reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = form.password.data user.password = hashed_password db.session.commit() flash('Your password updated!') return redirect(url_for('homePage')) return render_template('ResetToken.html', title='Reset Password', form=form)