mirror of https://github.com/logos-co/open-law.git
issue How does username tags behave when a user creates a username with spaces in it? i.e. moni vs moni test #121
This commit is contained in:
parent
66ba559216
commit
e307964c0b
|
@ -38,6 +38,8 @@ class UserForm(FlaskForm):
|
|||
is not None
|
||||
):
|
||||
raise ValidationError("This username is taken.")
|
||||
elif " " in field.data:
|
||||
raise ValidationError("User name couldn't have spaces.")
|
||||
|
||||
|
||||
class NewUserForm(FlaskForm):
|
||||
|
@ -59,7 +61,7 @@ class NewUserForm(FlaskForm):
|
|||
|
||||
|
||||
class EditUserForm(FlaskForm):
|
||||
name = StringField("Name", [DataRequired()])
|
||||
username = StringField("Username", [DataRequired()])
|
||||
avatar_img = FileField("Avatar file (max 1mb, formats: jpg,jpeg,png)")
|
||||
submit = SubmitField("Save")
|
||||
|
||||
|
@ -70,6 +72,8 @@ class EditUserForm(FlaskForm):
|
|||
.first()
|
||||
):
|
||||
raise ValidationError("This username is taken.")
|
||||
elif " " in field.data:
|
||||
raise ValidationError("User name couldn't have spaces.")
|
||||
|
||||
def validate_avatar_img(self, field):
|
||||
if field.data:
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
{% include 'user/delete_profile_modal.html' %}
|
||||
|
||||
|
||||
<!-- component -->
|
||||
<section>
|
||||
<div class="w-full lg:w-4/12 px-4 mx-auto pt-6">
|
||||
|
@ -33,8 +32,8 @@
|
|||
{{ form.hidden_tag() }}
|
||||
<div>
|
||||
<!-- prettier-ignore -->
|
||||
{{form.name.label(class='block mb-2 text-sm font-medium text-gray-900 dark:text-white')}}
|
||||
{{form.name(autocomplete="off", class='bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500')}}
|
||||
{{form.username.label(class='block mb-2 text-sm font-medium text-gray-900 dark:text-white')}}
|
||||
{{form.username(autocomplete="off", class='bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500')}}
|
||||
</div>
|
||||
<!-- prettier-ignore -->
|
||||
{{form.avatar_img.label(class='block mb-2 text-sm font-medium text-gray-900 dark:text-white')}}
|
||||
|
|
|
@ -36,7 +36,7 @@ def edit_profile():
|
|||
form = f.EditUserForm()
|
||||
if form.validate_on_submit():
|
||||
user: m.User = current_user
|
||||
user.username = form.name.data
|
||||
user.username = form.username.data
|
||||
if form.avatar_img.data:
|
||||
current_user.avatar_img = (
|
||||
form.avatar_img.data
|
||||
|
@ -52,7 +52,7 @@ def edit_profile():
|
|||
flash(error.replace("Field", field_label), "danger")
|
||||
|
||||
if current_user.is_activated:
|
||||
form.name.data = current_user.username
|
||||
form.username.data = current_user.username
|
||||
return render_template("user/edit_profile.html", form=form)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue