forked from crunk/distribusi-verse
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.2 KiB
34 lines
1.2 KiB
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)
|
|
|