Skip to content

Commit

Permalink
Apply resered names check to display names
Browse files Browse the repository at this point in the history
  • Loading branch information
Tina-otoge committed Aug 18, 2024
1 parent 5744b0f commit 0741901
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
21 changes: 19 additions & 2 deletions app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,28 @@ def validate(self, *args, **kwargs) -> bool:

class LoginField(StringField):
def __init__(self, **kwargs):
validators = kwargs.pop("validators", [])
super().__init__(
validators=[
AlnumPlusValidator(),
DataRequired(),
Length(max=30),
LoginTakenValidator(),
NotReservedNameValidator(),
*validators,
],
**kwargs,
)


class DisplayNameField(StringField):
def __init__(self, **kwargs):
validators = kwargs.pop("validators", [])
super().__init__(
validators=[
Length(max=30),
NotReservedNameValidator(),
*validators,
],
**kwargs,
)
Expand All @@ -37,9 +52,11 @@ def __init__(self, **kwargs):
class PasswordField(PasswordField):
def __init__(self, **kwargs):
validators = kwargs.pop("validators", [])
validators.append(Length(min=4))
super().__init__(
validators=validators,
validators=[
Length(min=4),
*validators,
],
**kwargs,
)

Expand Down
5 changes: 2 additions & 3 deletions app/routes/user/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
EmailField,
FileField,
SelectField,
StringField,
SubmitField,
TextAreaField,
)

from app import app
from app.db import User
from app.forms import Form, Length, LoginField, PasswordField
from app.forms import DisplayNameField, Form, Length, LoginField, PasswordField
from app.services import audit, avatar
from app.services import user as service

Expand All @@ -26,7 +25,7 @@ def translate_image_type(image_type):

class EditProfileForm(Form):
login = LoginField()
display_name = StringField(validators=[Length(max=30)])
display_name = DisplayNameField()
email = EmailField()
bio = TextAreaField(validators=[Length(max=1000)])
image = FileField()
Expand Down

0 comments on commit 0741901

Please sign in to comment.