diff --git a/app/forms/user.py b/app/forms/user.py index 271cffa..bb4d7a8 100644 --- a/app/forms/user.py +++ b/app/forms/user.py @@ -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: diff --git a/app/templates/user/edit_profile.html b/app/templates/user/edit_profile.html index 201de6d..d1dca8a 100644 --- a/app/templates/user/edit_profile.html +++ b/app/templates/user/edit_profile.html @@ -7,7 +7,6 @@ {% include 'user/delete_profile_modal.html' %} -
@@ -33,8 +32,8 @@ {{ form.hidden_tag() }}
- {{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')}}
{{form.avatar_img.label(class='block mb-2 text-sm font-medium text-gray-900 dark:text-white')}} diff --git a/app/views/user.py b/app/views/user.py index 20bbee3..de86c87 100644 --- a/app/views/user.py +++ b/app/views/user.py @@ -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)