Allow specifying display name on register
This commit is contained in:
parent
04f659bc2b
commit
da6b4b210f
|
@ -100,16 +100,19 @@ def logout():
|
||||||
|
|
||||||
|
|
||||||
class RegisterForm(FlaskForm):
|
class RegisterForm(FlaskForm):
|
||||||
|
display_name = StringField("Display Name", [Optional(), Length(1, 20)], filters=[lambda x: nonEmptyOrNone(x)])
|
||||||
username = StringField("Username", [InputRequired(),
|
username = StringField("Username", [InputRequired(),
|
||||||
Regexp("^[a-zA-Z0-9._ -]+$", message="Only a-zA-Z0-9._ allowed")])
|
Regexp("^[a-zA-Z0-9._ -]+$", message="Only a-zA-Z0-9._ allowed")])
|
||||||
email = StringField("Email", [InputRequired(), Email()])
|
email = StringField("Email", [InputRequired(), Email()])
|
||||||
password = PasswordField("Password", [InputRequired(), Length(6, 100)])
|
password = PasswordField("Password", [InputRequired(), Length(6, 100)])
|
||||||
|
agree = BooleanField("I agree", [Required()])
|
||||||
submit = SubmitField("Register")
|
submit = SubmitField("Register")
|
||||||
|
|
||||||
|
|
||||||
def handle_register(form):
|
def handle_register(form):
|
||||||
user_by_name = User.query.filter(or_(
|
user_by_name = User.query.filter(or_(
|
||||||
User.username == form.username.data,
|
User.username == form.username.data,
|
||||||
|
User.display_name == form.display_name.data,
|
||||||
User.forums_username == form.username.data,
|
User.forums_username == form.username.data,
|
||||||
User.github_username == form.username.data)).first()
|
User.github_username == form.username.data)).first()
|
||||||
if user_by_name:
|
if user_by_name:
|
||||||
|
@ -117,7 +120,7 @@ def handle_register(form):
|
||||||
flash("An account already exists for that username but hasn't been claimed yet.", "danger")
|
flash("An account already exists for that username but hasn't been claimed yet.", "danger")
|
||||||
return redirect(url_for("users.claim_forums", username=user_by_name.forums_username))
|
return redirect(url_for("users.claim_forums", username=user_by_name.forums_username))
|
||||||
else:
|
else:
|
||||||
flash("That username is already in use, please choose another.", "danger")
|
flash("That username/display name is already in use, please choose another.", "danger")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,9 +137,11 @@ def handle_register(form):
|
||||||
|
|
||||||
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))
|
||||||
user.notification_preferences = UserNotificationPreferences(user)
|
user.notification_preferences = UserNotificationPreferences(user)
|
||||||
|
if form.display_name.data:
|
||||||
|
user.display_name = form.display_name.data
|
||||||
db.session.add(user)
|
db.session.add(user)
|
||||||
|
|
||||||
addAuditLog(AuditSeverity.USER, user, "Registered with email",
|
addAuditLog(AuditSeverity.USER, user, "Registered with email, display name=" + user.display_name,
|
||||||
url_for("users.profile", username=user.username))
|
url_for("users.profile", username=user.username))
|
||||||
|
|
||||||
token = randomString(32)
|
token = randomString(32)
|
||||||
|
|
|
@ -22,13 +22,9 @@
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
|
|
||||||
{% if form.email and not current_user.email %}
|
{% if form.email and not current_user.email %}
|
||||||
{{ render_field(form.email, tabindex=220) }}
|
{{ render_field(form.email, tabindex=220,
|
||||||
|
hint=_("Your email is needed to recover your account if you forget your password and to send (configurable) notifications. ") +
|
||||||
<p>
|
_("Your email will never be shared with a third-party.")) }}
|
||||||
Your email is needed to recover your account if you forget your
|
|
||||||
password and to send (configurable) notifications.
|
|
||||||
Your email will never be shared with a third-party.
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if form.old_password %}
|
{% if form.old_password %}
|
||||||
|
|
|
@ -13,22 +13,32 @@ Register
|
||||||
<form action="" method="POST" class="form card-body" role="form">
|
<form action="" method="POST" class="form card-body" role="form">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
|
|
||||||
{{ render_field(form.username, pattern="[a-zA-Z0-9._ -]+", title="Only a-zA-Z0-9._ allowed") }}
|
{{ render_field(form.username, pattern="[a-zA-Z0-9._ -]+", title=_("Only a-zA-Z0-9._ allowed"),
|
||||||
{{ render_field(form.email) }}
|
hint=_("Only alphanumeric characters, periods, underscores, and minuses are allowed (a-zA-Z0-9._)")) }}
|
||||||
{{ render_field(form.password) }}
|
|
||||||
|
{{ render_field(form.display_name,
|
||||||
|
hint=_("Human readable name, defaults to username if not specified. This can be changed later."),
|
||||||
|
placeholder=_("Same as username")) }}
|
||||||
|
|
||||||
|
{{ render_field(form.email,
|
||||||
|
hint=_("Your email is needed to recover your account if you forget your password and to send (configurable) notifications. ") +
|
||||||
|
_("Your email will never be shared with a third-party.")) }}
|
||||||
|
|
||||||
|
{{ render_field(form.password, hint=_("Must be at least 8 characters long.")) }}
|
||||||
|
|
||||||
<p>
|
|
||||||
Must be at least 8 characters long.
|
|
||||||
</p>
|
|
||||||
<p>
|
<p>
|
||||||
Password suggestion
|
Password suggestion
|
||||||
(<a href="https://xkcd.com/936/">Why?</a>):
|
(<a href="https://xkcd.com/936/">Why?</a>):
|
||||||
<code>{{ suggested_password }}</code>
|
<code>{{ suggested_password }}</code>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
{% set label %}
|
||||||
Please read the <a href="{{ url_for('flatpage', path='privacy_policy') }}">{{ _("Privacy Policy") }}</a>.
|
{{ _("I agree to the ") }}
|
||||||
</p>
|
<a href="{{ url_for('flatpage', path='privacy_policy') }} ">
|
||||||
|
{{ _("Privacy Policy") }}
|
||||||
|
</a>
|
||||||
|
{% endset %}
|
||||||
|
{{ render_checkbox_field(form.agree, label=label, class_="my-4") }}
|
||||||
|
|
||||||
{# Submit button #}
|
{# Submit button #}
|
||||||
<p>
|
<p>
|
||||||
|
|
Loading…
Reference in New Issue