def send_email(): form = EmailForm() if request.method == 'POST': if not form.validate_on_submit(): return username = session.get('username', 'null') title = form.title.data content = form.content.data new_title = '%s--%s' % (username, title) msg = Message(new_title, sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = content flash('发送成功!') thread = Thread(target=send_async_email, args=[app, msg]) thread.start() return render_template('datas/send_email.html', form=form)
def forgot(): if current_user.is_authenticated: return redirect(url_for('index')) form = EmailForm() if form.validate_on_submit(): customer = Customer.query.filter_by(email=form.email.data).first() if customer is None: flash('There is no Account with this email. Please Register.', 'warning') return redirect(url_for('forgot')) user = User.query.filter_by(id=customer.id).first() reset_email(user) flash( 'An email has been sent with instructions to reset your password.', 'success') return redirect(url_for('login')) return render_template('reset_request.html', form=form)