-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edb9848
commit 3d67220
Showing
8 changed files
with
59 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.DS_Store | ||
.env | ||
.flaskenv | ||
*.pyc | ||
*.pyo | ||
env/ | ||
env* | ||
dist/ | ||
build/ | ||
*.egg | ||
*.egg-info/ | ||
_mailinglist | ||
.tox/ | ||
.cache/ | ||
.pytest_cache/ | ||
.idea/ | ||
docs/_build/ | ||
|
||
# Coverage reports | ||
htmlcov/ | ||
.coverage | ||
.coverage.* | ||
*,cover |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from flask import current_app, render_template | ||
from threading import Thread | ||
from flask_mail import Message | ||
from . import mail | ||
|
||
def send_async_email(app, msg): | ||
with app.app_context(): | ||
mail.send(msg) | ||
|
||
def send_email(to, subject, template, **kwargs): | ||
app = current_app._get_current_object() | ||
msg = Message(app.config['FLASKY_MAIL_SUBJECT_PREFIX'] + ' ' + subject, | ||
sender=app.config['FLASKY_MAIL_SENDER'], recipients=to) | ||
msg.body = render_template(template + '.txt', **kwargs) | ||
msg.html = render_template(template + '.html', **kwargs) | ||
thr = Thread(target=send_async_email, args=[app, msg]) | ||
thr.start() | ||
return thr |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,25 +4,8 @@ | |
from .forms import NameForm | ||
from .. import db, mail | ||
from ..models import User | ||
from flask_mail import Message | ||
from threading import Thread | ||
|
||
|
||
def send_async_email(app, msg): | ||
with app.app_context(): | ||
mail.send(msg) | ||
|
||
|
||
def send_mail(to, subject, template, **kwargs): | ||
msg = Message( | ||
main.config['MAIL_SUBJECT_PREFIX'] + subject, | ||
sender=main.config['FLASKY_MAIL_SENDER'], | ||
recipients=to) | ||
msg.body = render_template(template + '.txt', **kwargs) | ||
msg.html = render_template(template + '.html', **kwargs) | ||
thr = Thread(target=send_async_email, args=[main, msg]) | ||
thr.start() | ||
return thr | ||
from ..email import send_email | ||
from flask import current_app | ||
|
||
|
||
@main.route("/", methods=['GET', 'POST']) | ||
|
@@ -36,6 +19,21 @@ def index(): | |
db.session.add(user) | ||
db.session.commit() | ||
session['known'] = False | ||
if current_app._get_current_object().config['FLASKY_ADMIN']: | ||
send_email( | ||
[current_app._get_current_object().config['FLASKY_ADMIN']], | ||
'New user', | ||
'mail/new_user', | ||
user=user) | ||
else: | ||
send_email( | ||
[ | ||
'[email protected]', | ||
'[email protected]', | ||
], | ||
'New user', | ||
'mail/new_user', | ||
user=user) | ||
else: | ||
session['known'] = True | ||
session['name'] = form.name.data | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.