def __init__(self): self.fields = ( forms.TextField(field_name='username', length=30, maxlength=30, is_required=True, validator_list=[ validators.isAlphaNumeric, self.isValidUsername ]), forms.EmailField(field_name='email', length=30, maxlength=30, is_required=True, validator_list=[self.isValidUsername]), forms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True), forms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True, validator_list=[ validators.AlwaysMatchesOtherField( 'password1', 'Passwords must match.') ]), forms.TextField(field_name='first_name', length=20, maxlength=20, is_required=True), forms.TextField(field_name='last_name', length=20, maxlength=20, is_required=True), )
def __init__(self): self.fields = ( oldforms.TextField(field_name='username', length=30, max_length=30, is_required=True, validator_list=[ validators.isAlphaNumeric, self.isValidUsername ]), oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), oldforms.PasswordField( field_name='password2', length=30, max_length=60, is_required=True, validator_list=[ validators.AlwaysMatchesOtherField( 'password1', _("The two password fields didn't match.")) ]), )
def __init__(self): choices = [[hour, "%s hours" % hour] for hour in ["2", "4", "6", "8", "10"]] # TODO: Do this properly. choices.append(["500", "No limit"]) self.fields = [ # Admin password forms.PasswordField(field_name="password1", length=PASSWORD_LENGTH, maxlength=PASSWORD_LENGTH), forms.PasswordField( field_name="password2", length=PASSWORD_LENGTH, maxlength=PASSWORD_LENGTH, validator_list=[ validators.AlwaysMatchesOtherField( "password1", error_message="This must match the field above.") ]), # Network forms.TextField(field_name="hostname", maxlength=40, validator_list=[]), forms.TextField(field_name="domain", maxlength=40, validator_list=[isValidWorkgroup]), forms.SelectField(field_name="networkconfig", choices=[(x, x) for x in smartbox.network.configurations ]), forms.TextField(field_name="address", maxlength=40), forms.TextField(field_name="netmask", maxlength=40), forms.TextField(field_name="gateway", maxlength=40), # Remote backup forms.TextField(field_name="peerHost", maxlength=40, validator_list=[self.validateBackupPeer]), forms.TextField(field_name="peerUsername", maxlength=40), forms.PasswordField(field_name="peerPassword", maxlength=40), forms.PasswordField(field_name="peerEncryptionKey", maxlength=40, validator_list=[isValidEncryptionKey]), forms.LargeTextField(field_name="peerNotes", maxlength=40), forms.TimeField(field_name="backupTime"), forms.SelectField(field_name="backupDuration", choices=choices), ]
def __init__(self, user): self.user = user self.fields = ( oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), oldforms.PasswordField( field_name='password2', length=30, max_length=60, is_required=True, validator_list=[ validators.AlwaysMatchesOtherField( 'password1', _("The two password fields didn't match.")) ]), )
def __init__(self): self.fields = ( forms.PasswordField(field_name='old_password', length=30, maxlength=30, is_required=True), forms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True), forms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True, validator_list=[ validators.AlwaysMatchesOtherField( 'password1', 'Passwords must match.') ]), )
def __init__(self, user=None, create=False, groups=None, systemOnly=False): debugOutput("Creating") self.user = user self.create = create self.groups = groups self.systemOnly = systemOnly self.fields = [ forms.TextField(field_name="name", maxlength=100, is_required=True), forms.PasswordField(field_name="password1", length=PASSWORD_LENGTH, maxlength=PASSWORD_LENGTH, is_required=self.create), forms.PasswordField( field_name="password2", length=PASSWORD_LENGTH, maxlength=PASSWORD_LENGTH, is_required=self.create, validator_list=[ validators.AlwaysMatchesOtherField( "password1", error_message="This must match the field above.") ]), ] if self.create: self.fields[0:0] = [ forms.TextField(field_name="username", length=USER_LENGTH, maxlength=USER_LENGTH, is_required=True, validator_list=[isValidUsername]) ] else: self.fields[0:0] = [ forms.HiddenField(field_name="username", is_required=True) ]
def __init__(self, user): self.user = user self.fields = ( oldforms.PasswordField(field_name="old_password", length=30, max_length=30, is_required=True, validator_list=[self.isValidOldPassword]), oldforms.PasswordField( field_name="new_password1", length=30, max_length=30, is_required=True, validator_list=[ validators.AlwaysMatchesOtherField( 'new_password2', _("The two 'new password' fields didn't match.")) ]), oldforms.PasswordField(field_name="new_password2", length=30, max_length=30, is_required=True), )
class RegisterValidator(valid.Validator): username = valid.CharField(max_length=30, min_length=4) password = valid.CharField(max_length=30, min_length=4, validator_list=[validators.AlwaysMatchesOtherField('password1', _("Password is not matched!"))]) password1 = valid.CharField(max_length=30) email = valid.EmailField(max_length=30) def __init__(self, request): self.fields['username'].add_validator(self.isValidUser) self.fields['email'].add_validator(self.isValidEmail) def isValidUser(self, field_data, all_data): for c in field_data: if c in '~`!@#$%^&*();:\'",./<>?\|+= ': raise valid.ValidationError, _("There cannot be invalidate character in user name") try: User.objects.get(username=field_data) except User.DoesNotExist: return else: raise valid.ValidationError, _("The username has been registered, please try another one.") def isValidEmail(self, field_data, all_data): try: User.objects.get(email=field_data) except User.DoesNotExist: return else: raise valid.ValidationError, "This email has been used." def save(self, data): u = User.objects.create_user(data["username"], data["email"], data["password"]) u.is_staff = True u.is_active = True u.is_superuser = False u.save() return u