Allow specifying display name on register
This commit is contained in:
parent
04f659bc2b
commit
da6b4b210f
|
@ -100,16 +100,19 @@ def logout():
|
|||
|
||||
|
||||
class RegisterForm(FlaskForm):
|
||||
display_name = StringField("Display Name", [Optional(), Length(1, 20)], filters=[lambda x: nonEmptyOrNone(x)])
|
||||
username = StringField("Username", [InputRequired(),
|
||||
Regexp("^[a-zA-Z0-9._ -]+$", message="Only a-zA-Z0-9._ allowed")])
|
||||
email = StringField("Email", [InputRequired(), Email()])
|
||||
password = PasswordField("Password", [InputRequired(), Length(6, 100)])
|
||||
agree = BooleanField("I agree", [Required()])
|
||||
submit = SubmitField("Register")
|
||||
|
||||
|
||||
def handle_register(form):
|
||||
user_by_name = User.query.filter(or_(
|
||||
User.username == form.username.data,
|
||||
User.display_name == form.display_name.data,
|
||||
User.forums_username == form.username.data,
|
||||
User.github_username == form.username.data)).first()
|
||||
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")
|
||||
return redirect(url_for("users.claim_forums", username=user_by_name.forums_username))
|
||||
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
|
||||
|
||||
|
||||
|
@ -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.notification_preferences = UserNotificationPreferences(user)
|
||||
if form.display_name.data:
|
||||
user.display_name = form.display_name.data
|
||||
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))
|
||||
|
||||
token = randomString(32)
|
||||
|
|
|
@ -22,13 +22,9 @@
|
|||
{{ form.hidden_tag() }}
|
||||
|
||||
{% if form.email and not current_user.email %}
|
||||
{{ render_field(form.email, tabindex=220) }}
|
||||
|
||||
<p>
|
||||
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>
|
||||
{{ 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. ") +
|
||||
_("Your email will never be shared with a third-party.")) }}
|
||||
{% endif %}
|
||||
|
||||
{% if form.old_password %}
|
||||
|
|
|
@ -13,22 +13,32 @@ Register
|
|||
<form action="" method="POST" class="form card-body" role="form">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
{{ render_field(form.username, pattern="[a-zA-Z0-9._ -]+", title="Only a-zA-Z0-9._ allowed") }}
|
||||
{{ render_field(form.email) }}
|
||||
{{ render_field(form.password) }}
|
||||
{{ render_field(form.username, pattern="[a-zA-Z0-9._ -]+", title=_("Only a-zA-Z0-9._ allowed"),
|
||||
hint=_("Only alphanumeric characters, periods, underscores, and minuses are allowed (a-zA-Z0-9._)")) }}
|
||||
|
||||
{{ 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>
|
||||
Password suggestion
|
||||
(<a href="https://xkcd.com/936/">Why?</a>):
|
||||
<code>{{ suggested_password }}</code>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Please read the <a href="{{ url_for('flatpage', path='privacy_policy') }}">{{ _("Privacy Policy") }}</a>.
|
||||
</p>
|
||||
{% set label %}
|
||||
{{ _("I agree to the ") }}
|
||||
<a href="{{ url_for('flatpage', path='privacy_policy') }} ">
|
||||
{{ _("Privacy Policy") }}
|
||||
</a>
|
||||
{% endset %}
|
||||
{{ render_checkbox_field(form.agree, label=label, class_="my-4") }}
|
||||
|
||||
{# Submit button #}
|
||||
<p>
|
||||
|
|
Loading…
Reference in New Issue