Skip to content

Commit

Permalink
password logic in ProjectCommonForm
Browse files Browse the repository at this point in the history
  • Loading branch information
n00rsy committed Sep 24, 2024
1 parent 35f7f09 commit 7d27ef5
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions pybossa/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ def v(form, field):


class ProjectCommonForm(Form):
def __init__(self, *args, **kwargs):
super(ProjectCommonForm, self).__init__(*args, **kwargs)
if current_app.config.get('PROJECT_PASSWORD_REQUIRED'):
self.password_required = True
self.password.validators = [pb_validator.CheckPasswordStrength(
min_len=PROJECT_PWD_MIN_LEN,
special=False,
password_required=True), validators.Required()]
else:
self.password_required = False
self.password.validators = [pb_validator.CheckPasswordStrength(
min_len=PROJECT_PWD_MIN_LEN,
special=False,
password_required=False), validators.Optional()]

name = TextField(lazy_gettext('Name'),
[validators.Required(),
pb_validator.Unique(project_repo.get_by, 'name',
Expand All @@ -104,26 +119,9 @@ class ProjectCommonForm(Form):
validators=[validators.Required()], choices=[], default='')
output_data_class = SelectFieldWithProps(lazy_gettext('Output Data Classification'),
validators=[validators.Required()], choices=[], default='')
def __init__(self, *args, **kwargs):
Form.__init__(self, *args, **kwargs)

class ProjectForm(ProjectCommonForm):

def __init__(self, *args, **kwargs):
super(ProjectForm, self).__init__(*args, **kwargs)
if current_app.config.get('PROJECT_PASSWORD_REQUIRED'):
self.password_required = True
self.password.validators = [pb_validator.CheckPasswordStrength(
min_len=PROJECT_PWD_MIN_LEN,
special=False,
password_required=True), validators.Required()]
else:
self.password_required = False
self.password.validators = [pb_validator.CheckPasswordStrength(
min_len=PROJECT_PWD_MIN_LEN,
special=False,
password_required=False), validators.Optional()]

class ProjectForm(ProjectCommonForm):
long_description = TextAreaField(lazy_gettext('Long Description'),
[validators.Required()])
description = TextAreaField(lazy_gettext('Description'),
Expand Down

0 comments on commit 7d27ef5

Please sign in to comment.