class RegisterForm(Form): """Register Form Class for creating an account in PyBossa.""" err_msg = lazy_gettext("Full name must be between 3 and 35 " "characters long") fullname = TextField(lazy_gettext('Full name'), [validators.Length(min=3, max=35, message=err_msg)]) err_msg = lazy_gettext("User name must be between 3 and 35 " "characters long") err_msg_2 = lazy_gettext("The user name is already taken") name = TextField(lazy_gettext('User name'), [validators.Length(min=3, max=35, message=err_msg), pb_validator.NotAllowedChars(), pb_validator.Unique(db.session, User, User.name, err_msg_2)]) err_msg = lazy_gettext("Email must be between 3 and 35 characters long") err_msg_2 = lazy_gettext("Email is already taken") email_addr = TextField(lazy_gettext('Email Address'), [validators.Length(min=3, max=35, message=err_msg), validators.Email(), pb_validator.Unique( db.session, User, User.email_addr, err_msg_2)]) err_msg = lazy_gettext("Password cannot be empty") err_msg_2 = lazy_gettext("Passwords must match") password = PasswordField(lazy_gettext('New Password'), [validators.Required(err_msg), validators.EqualTo('confirm', err_msg_2)]) confirm = PasswordField(lazy_gettext('Repeat Password'))
class ProjectForm(Form): name = TextField(lazy_gettext('Name'), [ validators.Required(), pb_validator.Unique(project_repo.get_by, 'name', message=lazy_gettext("Name is already taken.")) ]) short_name = TextField(lazy_gettext('Short Name'), [ validators.Required(), pb_validator.NotAllowedChars(), pb_validator.Unique( project_repo.get_by, 'short_name', message=lazy_gettext("Short Name is already taken.")), pb_validator.ReservedName('project', current_app) ]) long_description = TextAreaField(lazy_gettext('Long Description'), [validators.Required()]) description = TextAreaField(lazy_gettext('Description'), [validators.Length(max=255)]) password = TextField(lazy_gettext('Password'), [ validators.Required(), pb_validator.CheckPasswordStrength(min_len=PROJECT_PWD_MIN_LEN, special=False) ])
class RegisterForm(Form): """Register Form Class for creating an account in PYBOSSA.""" err_msg = lazy_gettext( "Full name must be between 3 and %(fullname)s " "characters long", fullname=USER_FULLNAME_MAX_LENGTH) fullname = TextField(lazy_gettext('Full name'), [ validators.Length(min=3, max=USER_FULLNAME_MAX_LENGTH, message=err_msg) ]) err_msg = lazy_gettext( "User name must be between 3 and %(username_length)s " "characters long", username_length=USER_NAME_MAX_LENGTH) err_msg_2 = lazy_gettext("The user name is already taken") name = TextField(lazy_gettext('User name'), [ validators.Length(min=3, max=USER_NAME_MAX_LENGTH, message=err_msg), pb_validator.NotAllowedChars(), pb_validator.Unique(user_repo.get_by, 'name', err_msg_2), pb_validator.ReservedName('account', current_app) ]) err_msg = lazy_gettext( "Email must be between 3 and %(email_length)s " "characters long", email_length=EMAIL_MAX_LENGTH) err_msg_2 = lazy_gettext("Email is already taken") email_addr = EmailField(lazy_gettext('Email Address'), [ validators.Length(min=3, max=EMAIL_MAX_LENGTH, message=err_msg), validators.Email(), pb_validator.UniqueCaseInsensitive(user_repo.search_by_email, 'email_addr', err_msg_2) ]) err_msg = lazy_gettext("Password cannot be empty") err_msg_2 = lazy_gettext("Passwords must match") if enable_strong_password: password = PasswordField(lazy_gettext('New Password'), [ validators.Required(err_msg), validators.EqualTo('confirm', err_msg_2), pb_validator.CheckPasswordStrength() ]) else: password = PasswordField(lazy_gettext('New Password'), [ validators.Required(err_msg), validators.EqualTo('confirm', err_msg_2) ]) confirm = PasswordField(lazy_gettext('Repeat Password')) project_slug = SelectMultipleField(lazy_gettext('Project'), choices=[]) consent = BooleanField(default='checked', false_values=("False", "false", '', '0', 0)) def generate_password(self): if self.data['password']: return password = util.generate_password() self.password.data = password self.confirm.data = password
class RegisterForm(Form): """Register Form Class for creating an account in PYBOSSA.""" err_msg = lazy_gettext("Full name must be between 3 and %(fullname)s " "characters long", fullname=USER_FULLNAME_MAX_LENGTH) fullname = TextField(lazy_gettext('Full name'), [validators.Length(min=3, max=USER_FULLNAME_MAX_LENGTH, message=err_msg)]) err_msg = lazy_gettext("User name must be between 3 and %(username_length)s " "characters long", username_length=USER_NAME_MAX_LENGTH) err_msg_2 = lazy_gettext("The user name is already taken") name = TextField(lazy_gettext('User name'), [validators.Length(min=3, max=USER_NAME_MAX_LENGTH, message=err_msg), pb_validator.NotAllowedChars(), pb_validator.Unique(user_repo.get_by, 'name', err_msg_2), pb_validator.ReservedName('account', current_app)]) err_msg = lazy_gettext("Email must be between 3 and %(email_length)s " "characters long", email_length=EMAIL_MAX_LENGTH) err_msg_2 = lazy_gettext("Email is already taken") email_addr = EmailField(lazy_gettext('Email Address'), [validators.Length(min=3, max=EMAIL_MAX_LENGTH, message=err_msg), validators.Email(), pb_validator.Unique(user_repo.get_by, 'email_addr', err_msg_2)]) err_msg = lazy_gettext("Password cannot be empty") err_msg_2 = lazy_gettext("Passwords must match") password = PasswordField(lazy_gettext('New Password'), [validators.Required(err_msg), validators.EqualTo('confirm', err_msg_2)]) confirm = PasswordField(lazy_gettext('Repeat Password'))
class ProjectCommonForm(Form): name = TextField(lazy_gettext('Name'), [validators.Required(), pb_validator.Unique(project_repo.get_by, 'name', message=lazy_gettext("Name is already taken."))]) short_name = TextField(lazy_gettext('Short Name'), [validators.Required(), pb_validator.NotAllowedChars(), pb_validator.Unique(project_repo.get_by, 'short_name', message=lazy_gettext( "Short Name is already taken.")), pb_validator.ReservedName('project', current_app)]) password = PasswordField( lazy_gettext('Password'), [validators.Required(), pb_validator.CheckPasswordStrength( min_len=PROJECT_PWD_MIN_LEN, special=False)], render_kw={'placeholder': 'Minimum length {} characters, 1 uppercase, 1 lowercase and 1 numeric.'.format(PROJECT_PWD_MIN_LEN)}) input_data_class = SelectFieldWithProps(lazy_gettext('Input Data Classification'), 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 UpdateProfileForm(Form): """Form Class for updating PyBossa's user Profile.""" id = IntegerField(label=None, widget=HiddenInput()) err_msg = lazy_gettext( "Full name must be between 3 and %(fullname)s " "characters long", fullname=USER_FULLNAME_MAX_LENGTH) fullname = TextField(lazy_gettext('Full name'), [ validators.Length(min=3, max=USER_FULLNAME_MAX_LENGTH, message=err_msg) ]) country = SelectField(lazy_gettext('Country'), choices=[(cnt, cnt) for cnt in COUNTRY_LIST]) newsletter_subscribe = BooleanField( lazy_gettext( 'I would like to receive email updates about Amnesty Decoders and other projects.' )) err_msg = lazy_gettext( "User name must be between 3 and %(username_length)s " "characters long", username_length=USER_NAME_MAX_LENGTH) err_msg_2 = lazy_gettext("The user name is already taken") name = TextField(lazy_gettext('Username'), [ validators.Length(min=3, max=USER_NAME_MAX_LENGTH, message=err_msg), pb_validator.NotAllowedChars(), pb_validator.Unique(user_repo.get_by, 'name', err_msg_2), pb_validator.ReservedName('account', current_app) ]) err_msg = lazy_gettext( "Email must be between 3 and %(email_length)s " "characters long", email_length=EMAIL_MAX_LENGTH) err_msg_2 = lazy_gettext("Email is already taken") email_addr = EmailField(lazy_gettext('Email Address'), [ validators.Length(min=3, max=EMAIL_MAX_LENGTH, message=err_msg), validators.Email(), pb_validator.Unique(user_repo.get_by, 'email_addr', err_msg_2) ]) subscribed = BooleanField(lazy_gettext('Get email notifications')) locale = SelectField(lazy_gettext('Language')) ckan_api = TextField(lazy_gettext('CKAN API Key')) privacy_mode = BooleanField(lazy_gettext('Privacy Mode')) def set_locales(self, locales): """Fill the locale.choices.""" choices = [] for locale in locales: choices.append(locale) self.locale.choices = choices
class UpdateProfileForm(Form): """Form Class for updating PyBossa's user Profile.""" id = IntegerField(label=None, widget=HiddenInput()) err_msg = lazy_gettext("Full name must be between 3 and %s " "characters long" % USER_FULLNAME_MAX_LENGTH) fullname = TextField(lazy_gettext('Full name'), [validators.Length(min=3, max=USER_FULLNAME_MAX_LENGTH, message=err_msg)]) err_msg = lazy_gettext("User name must be between 3 and %s " "characters long" % USER_NAME_MAX_LENGTH) err_msg_2 = lazy_gettext("The user name is already taken") name = TextField(lazy_gettext('Username'), [validators.Length(min=3, max=USER_NAME_MAX_LENGTH, message=err_msg), pb_validator.NotAllowedChars(), pb_validator.Unique(user_repo.get_by, 'name', err_msg_2), pb_validator.ReservedName('account', current_app)]) err_msg = lazy_gettext("Email must be between 3 and %s " "characters long" % EMAIL_MAX_LENGTH) err_msg_2 = lazy_gettext("Email is already taken") email_addr = EmailField(lazy_gettext('Email Address'), [validators.Length(min=3, max=EMAIL_MAX_LENGTH, message=err_msg), validators.Email(), pb_validator.Unique(user_repo.get_by, 'email_addr', err_msg_2)]) subscribed = BooleanField(lazy_gettext('Get email notifications')) locale = SelectField(lazy_gettext('Language')) ckan_api = TextField(lazy_gettext('CKAN API Key')) privacy_mode = BooleanField(lazy_gettext('Privacy Mode')) def set_locales(self, locales): """Fill the locale.choices.""" choices = [] for locale in locales: if locale == 'en': lang = gettext("English") if locale == 'es': lang = gettext("Spanish") if locale == 'fr': lang = gettext("French") if locale == 'de': lang = gettext("German") if locale == 'it': lang = gettext("Italian") choices.append((locale, lang)) self.locale.choices = choices
class ProjectForm(Form): name = TextField(lazy_gettext('Name'), [validators.Required(), pb_validator.Unique(project_repo.get_by, 'name', message=lazy_gettext("Name is already taken."))]) short_name = TextField(lazy_gettext('Short Name'), [validators.Required(), pb_validator.NotAllowedChars(), pb_validator.Unique(project_repo.get_by, 'short_name', message=lazy_gettext( "Short Name is already taken.")), pb_validator.ReservedName('project', current_app)]) long_description = TextAreaField(lazy_gettext('Long Description'), [validators.Required()])
class AppForm(Form): name = TextField(lazy_gettext('Name'), [validators.Required(), pb_validator.Unique(db.session, App, App.name, message=lazy_gettext("Name is already taken."))]) short_name = TextField(lazy_gettext('Short Name'), [validators.Required(), pb_validator.NotAllowedChars(), pb_validator.Unique( db.session, App, App.short_name, message=lazy_gettext( "Short Name is already taken."))]) long_description = TextAreaField(lazy_gettext('Long Description'), [validators.Required()])
class RegisterForm(Form): """Register Form Class for creating an account in PyBossa.""" err_msg = lazy_gettext( "Full name must be between 3 and %(fullname)s " "characters long", fullname=USER_FULLNAME_MAX_LENGTH) fullname = TextField(lazy_gettext('Full name'), [ validators.Length(min=3, max=USER_FULLNAME_MAX_LENGTH, message=err_msg) ]) err_msg = lazy_gettext( "User name must be between 3 and %(username_length)s " "characters long", username_length=USER_NAME_MAX_LENGTH) err_msg_2 = lazy_gettext("The user name is already taken") name = TextField(lazy_gettext('User name'), [ validators.Length(min=3, max=USER_NAME_MAX_LENGTH, message=err_msg), pb_validator.NotAllowedChars(), pb_validator.Unique(user_repo.get_by, 'name', err_msg_2), pb_validator.ReservedName('account', current_app) ]) err_msg = lazy_gettext( "Email must be between 3 and %(email_length)s " "characters long", email_length=EMAIL_MAX_LENGTH) err_msg_2 = lazy_gettext("Email is already taken") email_addr = EmailField(lazy_gettext('Email Address'), [ validators.Length(min=3, max=EMAIL_MAX_LENGTH, message=err_msg), validators.Email(), pb_validator.Unique(user_repo.get_by, 'email_addr', err_msg_2) ]) err_msg = lazy_gettext("Password cannot be empty") err_msg_2 = lazy_gettext("Passwords must match") password = PasswordField(lazy_gettext('New Password'), [ validators.Required(err_msg), validators.EqualTo('confirm', err_msg_2) ]) confirm = PasswordField(lazy_gettext('Repeat Password')) country = SelectField(lazy_gettext('Country'), choices=[(cnt, cnt) for cnt in COUNTRY_LIST]) newsletter_subscribe = BooleanField( lazy_gettext( 'I would like to receive email updates about Amnesty Decoders and other projects.' ))
class UpdateProfileForm(Form): """Form Class for updating PyBossa's user Profile.""" id = IntegerField(label=None, widget=HiddenInput()) err_msg = lazy_gettext("Full name must be between 3 and 35 " "characters long") fullname = TextField(lazy_gettext('Full name'), [validators.Length(min=3, max=35, message=err_msg)]) err_msg = lazy_gettext("User name must be between 3 and 35 " "characters long") err_msg_2 = lazy_gettext("The user name is already taken") name = TextField(lazy_gettext('Username'), [validators.Length(min=3, max=35, message=err_msg), pb_validator.NotAllowedChars(), pb_validator.Unique( db.session, User, User.name, err_msg_2)]) err_msg = lazy_gettext("Email must be between 3 and 35 characters long") err_msg_2 = lazy_gettext("Email is already taken") email_addr = TextField(lazy_gettext('Email Address'), [validators.Length(min=3, max=35, message=err_msg), validators.Email(), pb_validator.Unique( db.session, User, User.email_addr, err_msg_2)]) locale = SelectField(lazy_gettext('Language')) ckan_api = TextField(lazy_gettext('CKAN API Key')) privacy_mode = BooleanField(lazy_gettext('Privacy Mode')) def set_locales(self, locales): """Fill the locale.choices.""" choices = [] for locale in locales: if locale == 'en': lang = gettext("English") if locale == 'es': lang = gettext("Spanish") if locale == 'fr': lang = gettext("French") if locale == 'pt': lang = gettext("Portuguese") choices.append((locale, lang)) self.locale.choices = choices
class ProjectForm(Form): name = TextField(lazy_gettext('Name'), [ validators.Required(), pb_validator.Unique(project_repo.get_by, 'name', message=lazy_gettext("Name is already taken.")) ]) short_name = TextField(lazy_gettext('Short Name'), [ validators.Required(), pb_validator.NotAllowedChars(), pb_validator.Unique( project_repo.get_by, 'short_name', message=lazy_gettext("Short Name is already taken.")), pb_validator.ReservedName('project', current_app) ]) long_description = TextAreaField(lazy_gettext('Long Description'), [validators.Required()]) description = TextAreaField(lazy_gettext('Description'), [validators.Length(max=255)]) password = TextField(lazy_gettext('Password'), [ validators.Required(), pb_validator.CheckPasswordStrength(min_len=PROJECT_PWD_MIN_LEN, special=False) ]) product = SelectField(lazy_gettext('Product'), [validators.Required()], choices=[("", "")], default="") subproduct = SelectField(lazy_gettext('Subproduct'), [validators.Required()], choices=[("", "")], default="") kpi = DecimalField(lazy_gettext( 'KPI - Estimate of amount of minutes to complete one task (0.1-120)'), places=2, validators=[ validators.Required(), NumberRange(Decimal('0.1'), 120) ]) def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs)
class RegisterForm(Form): """Register Form Class for creating an account in PyBossa.""" err_msg = lazy_gettext("Full name must be between 3 and %s " "characters long" % USER_FULLNAME_MAX_LENGTH) fullname = TextField(lazy_gettext('Full name'), [validators.Length(min=3, max=USER_FULLNAME_MAX_LENGTH, message=err_msg)]) err_msg = lazy_gettext("User name must be between 3 and %s " "characters long" % USER_NAME_MAX_LENGTH) err_msg_2 = lazy_gettext("The user name is already taken") name = TextField(lazy_gettext('User name'), [validators.Length(min=3, max=USER_NAME_MAX_LENGTH, message=err_msg), pb_validator.NotAllowedChars(), pb_validator.Unique(user_repo.get_by, 'name', err_msg_2), pb_validator.ReservedName('account', current_app)]) err_msg = lazy_gettext("Email must be between 3 and %s " "characters long" % EMAIL_MAX_LENGTH) err_msg_2 = lazy_gettext("Email is already taken") email_addr = EmailField(lazy_gettext('Email Address'), [validators.Length(min=3, max=EMAIL_MAX_LENGTH, message=err_msg), validators.Email(), pb_validator.Unique(user_repo.get_by, 'email_addr', err_msg_2)]) err_msg = lazy_gettext("Password cannot be empty") err_msg_2 = lazy_gettext("Passwords must match") err_msg_3 = lazy_gettext("Password must be between 8 to 15 characters") password = PasswordField(lazy_gettext('New Password'), [validators.Required(err_msg), validators.EqualTo('confirm', err_msg_2), validators.Required(), check_password_strenght]) #validators.Length(min=8, max=15, message=err_msg_3)]) #status, err_msg_3 = check_password_strenght(password.data) #if not status: # raise ValidationError(err_msg_3) confirm = PasswordField(lazy_gettext('Repeat Password'))
class RegisterForm(Form): """Register Form Class for creating an account in PyBossa.""" """ apply strong password policy """ def check_password_strength(form, field): pwd = field.data range_pwdlen = range(8, 16) pwdlen = len(pwd) if not pwdlen in range_pwdlen: raise ValidationError( 'Password must be between 8 and 15 characters') std_scores = { 0: 'Bad', 1: 'Weak', 2: 'Medium', 3: 'Average', 4: 'Strong' } strength = dict.fromkeys( ['has_upper', 'has_lower', 'has_num', 'has_special'], False) if re.search(r'[A-Z]', pwd): strength['has_upper'] = True if re.search(r'[a-z]', pwd): strength['has_lower'] = True if re.search(r'[0-9]', pwd): strength['has_num'] = True if re.search(r'[!@$%^&*\#]', pwd): strength['has_special'] = True score = len([b for b in strength.values() if b]) if score < 4: raise ValidationError( 'Password must contain atleast one uppercase alpha, numeric and special character !@$%^&*#\n' ) err_msg = lazy_gettext( "Full name must be between 3 and %(fullname)s " "characters long", fullname=USER_FULLNAME_MAX_LENGTH) fullname = TextField(lazy_gettext('Full name'), [ validators.Length(min=3, max=USER_FULLNAME_MAX_LENGTH, message=err_msg) ]) err_msg = lazy_gettext( "User name must be between 3 and %(username_length)s " "characters long", username_length=USER_NAME_MAX_LENGTH) err_msg_2 = lazy_gettext("The user name is already taken") name = TextField(lazy_gettext('User name'), [ validators.Length(min=3, max=USER_NAME_MAX_LENGTH, message=err_msg), pb_validator.NotAllowedChars(), pb_validator.Unique(user_repo.get_by, 'name', err_msg_2), pb_validator.ReservedName('account', current_app) ]) err_msg = lazy_gettext( "Email must be between 3 and %(email_length)s " "characters long", email_length=EMAIL_MAX_LENGTH) err_msg_2 = lazy_gettext("Email is already taken") email_addr = EmailField(lazy_gettext('Email Address'), [ validators.Length(min=3, max=EMAIL_MAX_LENGTH, message=err_msg), validators.Email(), pb_validator.Unique(user_repo.get_by, 'email_addr', err_msg_2) ]) err_msg = lazy_gettext("Password cannot be empty") err_msg_2 = lazy_gettext("Passwords must match") password = PasswordField(lazy_gettext('New Password'), [ validators.Required(err_msg), validators.EqualTo('confirm', err_msg_2), validators.Required(), check_password_strength ]) confirm = PasswordField(lazy_gettext('Repeat Password'))