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)
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() url = url_for( "frontend.change_password", email=user.email, activation_key=user.activation_key, _external=True ) html = render_template( "emails/reset_password.html", project=current_app.config["PROJECT"], username=user.name, url=url ) message = Message( subject=_("Reset your password in " + current_app.config["PROJECT"]), html=html, recipients=[user.email] ) mail.send(message) return render_template("reset_password.html", form=form) else: flash(_("Sorry, no user found for that email address"), "error") return render_template("reset_password.html", form=form)
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)