-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ | |
from .. import db | ||
from ..models import User | ||
from ..email import send_email | ||
from .forms import LoginForm, RegistrationForm, ChangePasswordForm | ||
from .forms import LoginForm, RegistrationForm, ChangePasswordForm,\ | ||
PasswordResetRequestForm, PasswordResetForm | ||
|
||
|
||
@auth.before_app_request | ||
|
@@ -102,3 +103,36 @@ def change_password(): | |
else: | ||
flash('Invalid password.') | ||
return render_template("auth/change_password.html", form=form) | ||
|
||
|
||
@auth.route('/reset', methods=['GET', 'POST']) | ||
def password_reset_request(): | ||
if not current_user.is_anonymous: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ezebunandu
|
||
return redirect(url_for('main.index')) | ||
form = PasswordResetRequestForm() | ||
if form.validate_on_submit(): | ||
user = User.query.filter_by(email=form.email.data.lower()).first() | ||
if user: | ||
token = user.generate_reset_token() | ||
send_email(user.email, 'Reset Your Password', | ||
'auth/email/reset_password', | ||
user=user, token=token) | ||
flash('An email with instructions to reset your password has been ' | ||
'sent to you.') | ||
return redirect(url_for('auth.login')) | ||
return render_template('auth/reset_password.html', form=form) | ||
|
||
|
||
@auth.route('/reset/<token>', methods=['GET', 'POST']) | ||
def password_reset(token): | ||
if not current_user.is_anonymous: | ||
return redirect(url_for('main.index')) | ||
form = PasswordResetForm() | ||
if form.validate_on_submit(): | ||
if User.reset_password(token, form.password.data): | ||
db.session.commit() | ||
flash('Your password has been updated.') | ||
return redirect(url_for('auth.login')) | ||
else: | ||
return redirect(url_for('main.index')) | ||
return render_template('auth/reset_password.html', form=form) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<p>Dear {{ user.username }},</p> | ||
<p>To reset your password <a href="{{ url_for('auth.password_reset', 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('auth.password_reset', token=token, _external=True) }}</p> | ||
<p>If you have not requested a password reset simply ignore this message.</p> | ||
<p>Sincerely,</p> | ||
<p>The Flasky Team</p> | ||
<p><small>Note: replies to this email address are not monitored.</small></p> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Dear {{ user.username }}, | ||
|
||
To reset your password click on the following link: | ||
|
||
{{ url_for('auth.password_reset', token=token, _external=True) }} | ||
|
||
If you have not requested a password reset simply ignore this message. | ||
|
||
Sincerely, | ||
|
||
The Flasky Team | ||
|
||
Note: replies to this email address are not monitored. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% extends "base.html" %} | ||
{% import "bootstrap/wtf.html" as wtf %} | ||
|
||
{% block title %}Flasky - Password Reset{% endblock %} | ||
|
||
{% block page_content %} | ||
<div class="page-header"> | ||
<h1>Reset Your Password</h1> | ||
</div> | ||
<div class="col-md-4"> | ||
{{ wtf.quick_form(form) }} | ||
</div> | ||
{% endblock %} |
that need add not ?