forked from miguelgrinberg/microblog
-
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
32a1feb
commit 4b6852b
Showing
10 changed files
with
158 additions
and
2 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
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,27 @@ | ||
from threading import Thread | ||
from flask import render_template | ||
from flask_mail import Message | ||
from app import app, mail | ||
|
||
|
||
def send_async_email(app, msg): | ||
with app.app_context(): | ||
mail.send(msg) | ||
|
||
|
||
def send_email(subject, sender, recipients, text_body, html_body): | ||
msg = Message(subject, sender=sender, recipients=recipients) | ||
msg.body = text_body | ||
msg.html = html_body | ||
Thread(target=send_async_email, args=(app, msg)).start() | ||
|
||
|
||
def send_password_reset_email(user): | ||
token = user.get_reset_password_token() | ||
send_email('[Microblog] Reset Your Password', | ||
sender=app.config['ADMINS'][0], | ||
recipients=[user.email], | ||
text_body=render_template('email/reset_password.txt', | ||
user=user, token=token), | ||
html_body=render_template('email/reset_password.html', | ||
user=user, token=token)) |
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
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
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
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,12 @@ | ||
<p>Dear {{ user.username }},</p> | ||
<p> | ||
To reset your password | ||
<a href="{{ url_for('reset_password', token=token, _external=True) }}"> | ||
click here | ||
</a>. | ||
</p> | ||
<p>Alternatively, you can paste the following link in your browser's address bar:</p> | ||
<p>{{ url_for('reset_password', token=token, _external=True) }}</p> | ||
<p>If you have not requested a password reset simply ignore this message.</p> | ||
<p>Sincerely,</p> | ||
<p>The Microblog Team</p> |
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,11 @@ | ||
Dear {{ user.username }}, | ||
|
||
To reset your password click on the following link: | ||
|
||
{{ url_for('reset_password', token=token, _external=True) }} | ||
|
||
If you have not requested a password reset simply ignore this message. | ||
|
||
Sincerely, | ||
|
||
The Microblog Team |
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
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 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1>Reset Your Password</h1> | ||
<form action="" method="post"> | ||
{{ form.hidden_tag() }} | ||
<p> | ||
{{ form.password.label }}<br> | ||
{{ form.password(size=32) }}<br> | ||
{% for error in form.password.errors %} | ||
<span style="color: red;">[{{ error }}]</span> | ||
{% endfor %} | ||
</p> | ||
<p> | ||
{{ form.password2.label }}<br> | ||
{{ form.password2(size=32) }}<br> | ||
{% for error in form.password2.errors %} | ||
<span style="color: red;">[{{ error }}]</span> | ||
{% endfor %} | ||
</p> | ||
<p>{{ form.submit() }}</p> | ||
</form> | ||
{% endblock %} |
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,16 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1>Reset Password</h1> | ||
<form action="" method="post"> | ||
{{ form.hidden_tag() }} | ||
<p> | ||
{{ form.email.label }}<br> | ||
{{ form.email(size=64) }}<br> | ||
{% for error in form.email.errors %} | ||
<span style="color: red;">[{{ error }}]</span> | ||
{% endfor %} | ||
</p> | ||
<p>{{ form.submit() }}</p> | ||
</form> | ||
{% endblock %} |