Example #1
0
File: forms.py Project: zlcken/hue
 def clean_password_old(self):
     if self.instance.id is not None:
         password1 = self.cleaned_data.get("password1", "")
         password_old = self.cleaned_data.get("password_old", "")
         if password1 != '' and not self.instance.check_password(
                 password_old):
             raise forms.ValidationError(self.GENERIC_VALIDATION_ERROR)
     return self.cleaned_data.get("password_old", "")
Example #2
0
 def clean_name(self):
     # Note that the superclass doesn't have a clean_name method.
     data = self.cleaned_data["name"]
     if not self.GROUPNAME.match(data):
         raise forms.ValidationError(
             _("Group name may only contain letters, " +
               "numbers, hyphens or underscores."))
     return data
Example #3
0
 def clean_password1(self):
     data = self.cleaned_data['password1']
     match = re.search(r'[\w]{8,}', data)
     if not match:
         raise forms.ValidationError(
             "Пароль должен содержать минимум 8 символов, а так же состоять только из букв, цифр и знака подчеркивани _"
         )
     return data
Example #4
0
 def clean_password_old(self):
     if self.instance.id is not None:
         password1 = self.cleaned_data.get("password1", "")
         password_old = self.cleaned_data.get("password_old", "")
         if password1 != '' and not self.instance.check_password(
                 password_old):
             raise forms.ValidationError(
                 _("The old password does not match the current password."))
     return self.cleaned_data.get("password_old", "")
Example #5
0
    def clean(self):
        data = self.cleaned_data
        username, password, email = (data["username"], data["password"],
                                     data["email"])
        self.user = authenticate(username=username, password=password)

        if self.user is None:

            raise forms.ValidationError("Enter a valid email or password")
Example #6
0
 def clean_username(self):
     # Since User.username is unique, this check is redundant,
     # but it sets a nicer error message than the ORM. See #13147.
     username = self.cleaned_data["username"]
     try:
         User._default_manager.get(username=username)
     except User.DoesNotExist:
         return username
     raise forms.ValidationError(self.error_messages['duplicate_username'])
Example #7
0
File: forms.py Project: onimsha/hue
  def clean(self):
    cleaned_data = super(AddLdapUsersForm, self).clean()
    username_pattern = cleaned_data.get("username_pattern")
    dn = cleaned_data.get("dn")

    if dn:
      if username_pattern is not None and len(username_pattern) > 64:
        msg = _('Too long: 64 characters or fewer and not %s.') % username_pattern
        errors = self._errors.setdefault('username_pattern', ErrorList())
        errors.append(msg)
        raise forms.ValidationError(msg)
    else:
      if username_pattern is not None and len(username_pattern) > 30:
        msg = _('Too long: 30 characters or fewer and not %s.') % username_pattern
        errors = self._errors.setdefault('username_pattern', ErrorList())
        errors.append(msg)
        raise forms.ValidationError(msg)

    return cleaned_data
Example #8
0
File: forms.py Project: ztwu/hue
  def clean_username(self):
    username = self.cleaned_data["username"]
    if self.instance.username == username:
      return username

    try:
      User._default_manager.get(username=username)
    except User.DoesNotExist:
      return username
    raise forms.ValidationError(self.GENERIC_VALIDATION_ERROR, code='duplicate_username')
Example #9
0
 def clean_username(self):
     username = self.cleaned_data["username"]
     if self.instance.username == username:
         return username
     try:
         User._default_manager.get(username=username)
     except User.DoesNotExist:
         return username
     raise forms.ValidationError(_("Username already exists."),
                                 code='duplicate_username')
Example #10
0
 def clean_email(self):
     data = self.cleaned_data['email']
     users = ShopUser.objects.all()
     uniqueEmails = set()
     for user in users:
         uniqueEmails.add(user.__dict__['email'])
     if data in uniqueEmails and data != '':
         raise forms.ValidationError(
             "Эта почта уже используется. Укажите другую")
     return data
Example #11
0
 def clean_password2(self):
     """Ensure the passwords match."""
     pass1 = self.cleaned_data.get("password1")
     pass2 = self.cleaned_data.get("password2")
     if pass1 and pass2 and pass1 != pass2:
         raise forms.ValidationError(
             "The two password fields didn't match.",
             code="password_mismatch")
     if password_validation is not None:
         password_validation.validate_password(pass1, self.instance)
     return pass1
Example #12
0
 def clean_email(self):
     """
     Validate that the supplied email address is unique for the
     site.
     """
     email = self.cleaned_data.get("email")
     user = User.objects.filter(email=email)
     if user.exists():
         raise forms.ValidationError(
             "This email address is already in use. Please supply a different email address."
         )
     return self.cleaned_data['email']
Example #13
0
File: forms.py Project: onimsha/hue
  def clean(self):
    cleaned_data = super(AddLdapGroupsForm, self).clean()
    groupname_pattern = cleaned_data.get("groupname_pattern")
    dn = cleaned_data.get("dn")

    if not dn:
      if groupname_pattern is not None and len(groupname_pattern) > 80:
        msg = _('Too long: 80 characters or fewer and not %s') % groupname_pattern
        errors = self._errors.setdefault('groupname_pattern', ErrorList())
        errors.append(msg)
        raise forms.ValidationError(msg)

    return cleaned_data
Example #14
0
  def clean(self):
    cleaned_data = super(AddLdapGroupForm, self).clean()
    name = cleaned_data.get("name")
    dn = cleaned_data.get("dn")

    if not dn:
      if name is not None and len(name) > 30:
        msg = _('Too long: 30 characters or fewer and not %(name)s') % dict(name=(len(name),))
        errors = self._errors.setdefault('name', ErrorList())
        errors.append(msg)
        raise forms.ValidationError(msg)

    return cleaned_data
Example #15
0
        def clean_email(self):
            # Get the email
            email = self.cleaned_data.get('email')

            # Check to see if any users already exist with this email as a username.
            try:
                match = User.objects.get(email=email)
            except User.DoesNotExist:
                # Unable to find a user, this is fine
                return email

            # A user was found with this as a username, raise an error.
            raise forms.ValidationError(
                'This email address is already in use.')
Example #16
0
    def clean(self):
        cleaned_data = super(AddLdapUsersForm, self).clean()
        username_pattern = cleaned_data.get("username_pattern")
        dn = cleaned_data.get("dn")

        try:
            if dn:
                validate_dn(username_pattern)
            else:
                validate_username(username_pattern)
        except AssertionError, e:
            errors = self._errors.setdefault('username_pattern', ErrorList())
            errors.append(e.message)
            raise forms.ValidationError(e.message)
Example #17
0
    def clean(self):
        cleaned_data = super(AddLdapGroupsForm, self).clean()
        groupname_pattern = cleaned_data.get("groupname_pattern")
        dn = cleaned_data.get("dn")

        try:
            if dn:
                validate_dn(groupname_pattern)
            else:
                validate_groupname(groupname_pattern)
        except ValidationError, e:
            errors = self._errors.setdefault('groupname_pattern', ErrorList())
            errors.append(e.message)
            raise forms.ValidationError(e.message)
Example #18
0
    def clean_email(self):
        # Get the email
        email = self.cleaned_data.get('email')

        # Check to see if any users already exist with this email as a username.
        try:
            match = Account.objects.get(email=email)
        except Account.DoesNotExist:
            # Unable to find a user, this is fine
            return email

        # A user was found with this as a username, raise an error.
        raise forms.ValidationError(
            'O email informado já se encontra cadastrado em nosso sistema.. Contate o administrador para mais informações.'
        )
Example #19
0
    def clean(self):
        user = self.cleaned_data.get('user')

        if not user:
            # let django handle the form error
            return self.cleaned_data

        for backend in settings.AUTHENTICATION_BACKENDS:
            auth_user = load_backend(backend).get_user(user.pk)

            if user == auth_user:
                user.backend = backend
                break

        if not hasattr(user, 'backend'):
            message = ugettext('Unable to login as %(username)s')
            raise forms.ValidationError(message % {'username': user.username})
        return self.cleaned_data
Example #20
0
    def _validate_unique_username(self, username):
        """(Re)-implement username uniqueness validation.

        Disallow --

            * confusion
            * trickery
            * *attempted* (but unlikely) hacking of username/email-flexible log-in
            * mistakes

        -- reject a username:

            * equal to any existing username (*case-insensitive*)
            * equal to any registered email address (case-insensitive)

        """
        if (User.objects.filter(username__iexact=username).exists()
                or User.objects.filter(email__iexact=username).exists() or
                EmailAddress.objects.filter(email__iexact=username).exists()):
            raise forms.ValidationError(
                "A user with that username already exists.")
Example #21
0
 def clean_password2(self):
     password1 = self.cleaned_data.get("password1", "")
     password2 = self.cleaned_data["password2"]
     if password1 != password2:
         raise forms.ValidationError(_t("Passwords do not match."))
     return password2
Example #22
0
 def clean_email(self):
     email = self.cleaned_data['email']
     if User.objects.filter(email=email):
         raise forms.ValidationError('Ya existe un email igual registrado.')
     return email
Example #23
0
 def clean_password2(self):
     password1 = self.cleaned_data.get("password1")
     password2 = super(UserCreationForm, self).clean_password2()
     if bool(password1) ^ bool(password2):
         raise forms.ValidationError("Fill out both fields")
     return password2
Example #24
0
 def clean_password2(self):
     password = self.cleaned_data['contrasena']
     password2 = self.cleaned_data['contrasena']
     if password != password2:
         raise forms.ValidationError('Las claves no coinciden')
     return password2
Example #25
0
 def clean_username(self):
     username = self.cleaned_data['username']
     if not User.objects.filter(username=username):
         raise forms.ValidationError('Nombre de usuario no existe.')
     return username
Example #26
0
 def clean_password1(self):
     password = self.cleaned_data.get("password1", "")
     if self.instance.id is None and password == "":
         raise forms.ValidationError(
             _("You must specify a password when creating a new user."))
     return self.cleaned_data.get("password1", "")
Example #27
0
 def clean_password2(self):
     cd = self.cleaned_data
     if cd['password1'] != cd['password2']:
         raise forms.ValidationError('Password didn\'t match!')
     return cd['password2']
Example #28
0
 def clean_contractorcode(self):
     contractorcode = self.cleaned_data["contractorcode"]
     if not Contractor.objects.get(id=contractorcode):
         raise forms.ValidationError("You have forgotten about Fred!")
     return contractorcode
Example #29
0
 def clean_dealercode(self):
     dealercode = self.cleaned_data["dealercode"]
     if not Dealer.objects.get(id=dealercode):
         raise forms.ValidationError("You have forgotten about Fred!")
     return dealercode
Example #30
0
    def clean_age(self):
        data = self.cleaned_data['age']
        if data < 18:
            raise forms.ValidationError('Вам нет 18 лет!')

        return data