def send_verification_email(user): """Send verification email to user """ # create email verification request r = EmailVerificationRequest(key=os.urandom(32).encode('hex'), user=user) db.session.add(r) db.session.flush() # send email subject = 'Flaskapp Account: Please Confirm Email' msg = Message(subject, recipients=[user.email]) verify_url = url_for('.verify_email', key=r.key, email=user.email, \ _external=True) f = '/auth/verify-email-email' msg.body = render_template(f + '.txt', verify_url=verify_url) html = render_template(f + '.html', verify_url=verify_url) base_url = url_for('content.home', _external=True) msg.html = transform(html, base_url=base_url) mail.send(msg)
def forgot(): """GET|POST /forgot: forgot password form handler """ form = ForgotPasswordForm() if form.validate_on_submit(): # get user u = User.query.filter_by(email=form.email.data).one() # create reset password # Todo: delete all previous entries r = PasswordResetRequest(key=os.urandom(32).encode('hex'), user=u) # save to db db.session.add(r) db.session.flush() # generate email msg = Message('Password Reset Request', recipients=[u.email]) reset_url = url_for('auth.reset_password', key=r.key, email=u.email, \ _external=True) # txt msg.body = render_template('/auth/reset-password-email.txt', reset_url=reset_url) # html html = render_template('/auth/reset-password-email.html', reset_url=reset_url) msg.html = transform(html, base_url=url_for('content.home', _external=True)) # send email mail.send(msg) return render_template('/auth/forgot-followup.html', email=u.email) return render_template('/auth/forgot.html', form=form)
def forgot(): """GET|POST /forgot: forgot password form handler """ form = ForgotPasswordForm() if form.validate_on_submit(): # get user u = User.query.filter_by(email=form.email.data).one() # create reset password # Todo: delete all previous entries r = PasswordResetRequest(key=binascii.hexlify(os.urandom(32)).decode(), user=u) # save to db db.session.add(r) db.session.flush() # generate email msg = Message('Password Reset Request', recipients=[u.email]) reset_url = url_for('auth.reset_password', key=r.key, email=u.email, _external=True) # txt msg.body = render_template('/auth/reset-password-email.txt', reset_url=reset_url) # html html = render_template('/auth/reset-password-email.html', reset_url=reset_url) msg.html = transform(html, base_url=url_for('content.home', _external=True)) # send email mail.send(msg) return render_template('/auth/forgot-followup.html', email=u.email) return render_template('/auth/forgot.html', form=form)