def resetpasswordrequest(token): if current_user.is_authenticated: return redirect(url_for('main.home')) user = User.validate_token(token) if user is None: flash('Your token is either invalid or expired.', 'info') return redirect('users.resetrequest') form = Resetpasswordform() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash('Your password has been successfully reset', 'success') return redirect('users.login') return render_template('reset_password.html', form=form)
def reset_password(token): if current_user.is_authenticated: return redirect(url_for('home')) user = User.validate_token(token) print(user) if user is None: flash('Invalid token or expired.Please reset again', 'warning') return redirect(url_for('reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('UTF-8') user.password = hashed_password db.session.commit() flash('Password change successfully for {}'.format(user.username), 'success') return redirect(url_for('login')) return render_template('reset_password.html', title="Change Password", form=form)