forked from crunk/distribusi-verse
crunk
3 years ago
7 changed files with 108 additions and 6 deletions
@ -0,0 +1,19 @@ |
|||||
|
"""Forgotten password form to help user.""" |
||||
|
from wtforms import ( |
||||
|
StringField, |
||||
|
SubmitField, |
||||
|
) |
||||
|
|
||||
|
from wtforms import validators |
||||
|
from wtforms.validators import Length, Email |
||||
|
from flask_wtf import FlaskForm |
||||
|
|
||||
|
|
||||
|
class ForgotPasswordForm(FlaskForm): |
||||
|
"""Forgotten password distribusiverse form class.""" |
||||
|
|
||||
|
email = StringField( |
||||
|
"Email address:", |
||||
|
validators=[validators.InputRequired(), Email(), Length(6, 64)], |
||||
|
) |
||||
|
submit = SubmitField("Send email") |
@ -0,0 +1,34 @@ |
|||||
|
from flask import render_template |
||||
|
from usermodel import User |
||||
|
from forms.forgotpasswordform import ForgotPasswordForm |
||||
|
from flask_mail import Message |
||||
|
|
||||
|
|
||||
|
def ForgotPassword(mail): |
||||
|
forgotpasswordform = ForgotPasswordForm() |
||||
|
if forgotpasswordform.validate_on_submit(): |
||||
|
user = User.query.filter_by( |
||||
|
email=forgotpasswordform.email.data |
||||
|
).first() |
||||
|
if user is not None: |
||||
|
ResetPassWordMessage(user, mail) |
||||
|
forgotpasswordform.email.errors.append( |
||||
|
f"""If {forgotpasswordform.email.data} exists, an email is send with |
||||
|
a password reset link. (If your inbox doesn't |
||||
|
contain any new mail, please check your spam folder.)""" |
||||
|
) |
||||
|
return render_template( |
||||
|
"forgotpassword.html", forgotpasswordform=forgotpasswordform |
||||
|
) |
||||
|
|
||||
|
|
||||
|
def ResetPassWordMessage(user, mail): |
||||
|
msg = Message( |
||||
|
"Distribusiverse Forgotten Password ", |
||||
|
sender=("Distribusiverse mailer", "test@this.com"), |
||||
|
recipients=[user.email], |
||||
|
) |
||||
|
msg.html = f"""You have requested a password reset for Distribusiverse.<br> |
||||
|
<a href='http://localhost:5000/resetpassword/{user.email}'>Click here to |
||||
|
reset your password and make a new one.</a>""" |
||||
|
mail.send(msg) |
@ -0,0 +1,29 @@ |
|||||
|
{% extends "base.html" %} |
||||
|
{% block main %} |
||||
|
<div id="mainworkflow"> |
||||
|
<div class="workflow"> |
||||
|
<h2>Forgot your password?</h2> |
||||
|
<p> |
||||
|
Enter the email address that was used to register with Distribusiverse. |
||||
|
</p> |
||||
|
<form class="form" action="{{ url_for('forgotpassword') }}" method="post"> |
||||
|
{{ forgotpasswordform.csrf_token }} |
||||
|
<fieldset class="required"> |
||||
|
{{ forgotpasswordform.email.label }} |
||||
|
{{ forgotpasswordform.email }} |
||||
|
{% for message in forgotpasswordform.email.errors %} |
||||
|
<div class="error">{{ message }}</div> |
||||
|
{% endfor %} |
||||
|
</fieldset> |
||||
|
<fieldset class="button required error"> |
||||
|
{{ forgotpasswordform.submit }} |
||||
|
<div class="overview"> |
||||
|
<a href="/"> |
||||
|
<input type="button" name="button" value="Back to main page"></input> |
||||
|
</a> |
||||
|
</div> |
||||
|
</fieldset> |
||||
|
</form> |
||||
|
</div> |
||||
|
</div |
||||
|
{% endblock main %} |
Loading…
Reference in new issue