def reset_password(): form = RecoverPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: flash( _('Please see your email for instructions on ' 'how to access your account'), 'success') user.activation_key = str(uuid4()) db.session.add(user) db.session.commit() body = render_template('emails/reset_password.html', user=user) message = Message(subject=_('Recover your password'), body=body, recipients=[user.email]) mail.send(message) return redirect(url_for('frontend.index')) else: flash(_('Sorry, no user found for that email address'), 'error') return render_template('reset_password.html', form=form)