mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-25 15:31:37 +01:00
Register: Fix behaviour on email conflict, add password suggestion
This commit is contained in:
parent
43aab057c8
commit
f7d90f2f53
@ -23,8 +23,10 @@ from wtforms import *
|
|||||||
from wtforms.validators import *
|
from wtforms.validators import *
|
||||||
|
|
||||||
from app.models import *
|
from app.models import *
|
||||||
from app.tasks.emails import sendVerifyEmail
|
from app.tasks.emails import sendVerifyEmail, sendEmailRaw
|
||||||
from app.utils import randomString, make_flask_login_password, is_safe_url, check_password_hash
|
from app.utils import randomString, make_flask_login_password, is_safe_url, check_password_hash
|
||||||
|
from passlib.pwd import genphrase
|
||||||
|
|
||||||
from . import bp
|
from . import bp
|
||||||
|
|
||||||
|
|
||||||
@ -102,6 +104,11 @@ class RegisterForm(FlaskForm):
|
|||||||
def register():
|
def register():
|
||||||
form = RegisterForm(request.form)
|
form = RegisterForm(request.form)
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
|
user = User.query.filter_by(email=form.email.data).first()
|
||||||
|
if user:
|
||||||
|
sendEmailRaw([form.email.data], "Email already in use",
|
||||||
|
"We were unable to create the account as the email is already in use by {}. Try a different email address.".format(user.display_name))
|
||||||
|
else:
|
||||||
user = User(form.username.data, False, form.email.data, make_flask_login_password(form.password.data))
|
user = User(form.username.data, False, form.email.data, make_flask_login_password(form.password.data))
|
||||||
db.session.add(user)
|
db.session.add(user)
|
||||||
|
|
||||||
@ -119,7 +126,7 @@ def register():
|
|||||||
flash("Check your email address to verify your account", "success")
|
flash("Check your email address to verify your account", "success")
|
||||||
return redirect(url_for("homepage.home"))
|
return redirect(url_for("homepage.home"))
|
||||||
|
|
||||||
return render_template("users/register.html", form=form)
|
return render_template("users/register.html", form=form, suggested_password=genphrase(entropy=52, wordset="bip39"))
|
||||||
|
|
||||||
|
|
||||||
class ForgotPassword(FlaskForm):
|
class ForgotPassword(FlaskForm):
|
||||||
|
@ -41,11 +41,11 @@ def sendVerifyEmail(newEmail, token):
|
|||||||
mail.send(msg)
|
mail.send(msg)
|
||||||
|
|
||||||
@celery.task()
|
@celery.task()
|
||||||
def sendEmailRaw(to, subject, text, html):
|
def sendEmailRaw(to, subject, text, html=None):
|
||||||
from flask_mail import Message
|
from flask_mail import Message
|
||||||
msg = Message(subject, recipients=to)
|
msg = Message(subject, recipients=to)
|
||||||
|
|
||||||
msg.body = text or html
|
msg.body = text
|
||||||
html = html or text
|
html = html or text
|
||||||
msg.html = render_template("emails/base.html", subject=subject, content=html)
|
msg.html = render_template("emails/base.html", subject=subject, content=html)
|
||||||
mail.send(msg)
|
mail.send(msg)
|
||||||
|
@ -20,6 +20,11 @@ Register
|
|||||||
<p>
|
<p>
|
||||||
Must be at least 8 characters long.
|
Must be at least 8 characters long.
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
Password suggestion
|
||||||
|
(<a href="https://xkcd.com/936/">Why?</a>):
|
||||||
|
<code>{{ suggested_password }}</code>
|
||||||
|
</p>
|
||||||
|
|
||||||
{# Submit button #}
|
{# Submit button #}
|
||||||
<p>
|
<p>
|
||||||
|
Loading…
Reference in New Issue
Block a user