Skip to content

Commit

Permalink
Enforce HTTPS in website and rss fields
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Moura <[email protected]>
  • Loading branch information
phsmoura committed Jun 14, 2024
1 parent 2222c91 commit a02d11d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions noggin/form/edit_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ def _validate(form, field):
raise ValidationError(_("This does not look like a valid server name."))


def https_required(form, field):
if not field.data.startswith('https://'):
raise ValidationError('URL should start with "https://".')


class UserSettingsProfileForm(BaseForm):
firstname = StringField(
_('First Name'),
Expand Down Expand Up @@ -122,14 +127,25 @@ class UserSettingsProfileForm(BaseForm):
_('GitLab Username'), validators=[Optional()], filters=[strip_at]
)

website_url = URLField(
_('Website or Blog URL'),
validators=[Optional(), URL(message=_('Valid URL required'))],
website_url = FieldList(
URLField(
validators=[
Optional(),
URL(message=_('Valid URL required')),
https_required,
],
widget=FieldWithClearButtonWidget(URLField.widget),
),
label=_('Blog URL'),
)

rss_url = FieldList(
URLField(
validators=[Optional(), URL(message=_('Valid URL required'))],
validators=[
Optional(),
URL(message=_('Valid URL required')),
https_required,
],
widget=FieldWithClearButtonWidget(URLField.widget),
),
label=_('RSS URL'),
Expand Down

0 comments on commit a02d11d

Please sign in to comment.