def clean_username(self):
     if not alnum_re.search(self.cleaned_data["username"]):
         raise forms.ValidationError(_("Usernames can only contain letters, numbers and underscores."))
     User = get_user_model()
     lookup_kwargs = get_user_lookup_kwargs({
         "{username}__iexact": self.cleaned_data["username"]
     })
     qs = User.objects.filter(**lookup_kwargs)
     if not qs.exists():
         return self.cleaned_data["username"]
     raise forms.ValidationError(_("This username is already taken. Please choose another."))
Exemple #2
0
 def clean_username(self):
     if not alnum_re.search(self.cleaned_data["username"]):
         raise forms.ValidationError(_("Usernames can only contain letters, numbers and underscores."))
     User = get_user_model()
     lookup_kwargs = get_user_lookup_kwargs({
         "{username}__iexact": self.cleaned_data["username"]
     })
     qs = User.objects.filter(**lookup_kwargs)
     if not qs.exists():
         return self.cleaned_data["username"]
     raise forms.ValidationError(_("This username is already taken. Please choose another."))
 def clean_username(self):
     if not alnum_re.search(self.cleaned_data["username"]):
         raise forms.ValidationError(_("Usernames can only contain letters, numbers and underscores."))
     User = get_user_model()
     lookup_kwargs = get_user_lookup_kwargs({
         "{username}__iexact": self.cleaned_data["username"]
     })
     qs = User.objects.filter(**lookup_kwargs)
     if not qs.exists():
         return self.cleaned_data["username"]
     raise forms.ValidationError(_("Este nome de usuário já está sendo utilizado. Por favor escolha um outro."))
Exemple #4
0
 def clean_username(self):
     #if not alnum_re.search(self.cleaned_data["username"]):
     #    raise forms.ValidationError(_("Usernames can only contain letters, numbers and underscores."))
     if not re.match('^[89]\d{7}$',self.cleaned_data["username"]):
         raise forms.ValidationError(_("Invalide Singaore Mobile Number. (8 digits starting with 8 or 9)"))
     User = get_user_model()
     lookup_kwargs = get_user_lookup_kwargs({
         "{username}__iexact": self.cleaned_data["username"]
     })
     qs = User.objects.filter(**lookup_kwargs)
     if not qs.exists():
         return self.cleaned_data["username"]
     raise forms.ValidationError(_("This Mobile Number was already registered. Please verify."))
 def authenticate(self, **credentials):
     User = get_user_model()
     lookup_kwargs = get_user_lookup_kwargs({"{username}__iexact": credentials["username"]})
     try:
         user = User.objects.get(**lookup_kwargs)
     except (User.DoesNotExist, KeyError):
         return None
     else:
         try:
             if user.check_password(credentials["password"]):
                 return user
         except KeyError:
             return None
Exemple #6
0
 def clean_username(self):
     if not alnum_re.search(self.cleaned_data["username"]):
         raise forms.ValidationError(
             _('Enter a valid username. This value may contain only letters, '
               'numbers, and @/./+/-/_ characters.'))
     User = get_user_model()
     lookup_kwargs = get_user_lookup_kwargs(
         {"{username}__iexact": self.cleaned_data["username"]})
     qs = User.objects.filter(**lookup_kwargs)
     if not qs.exists():
         return self.cleaned_data["username"]
     raise forms.ValidationError(
         _("This username is already taken. Please choose another."))
 def authenticate(self, **credentials):
     User = get_user_model()
     try:
         lookup_kwargs = get_user_lookup_kwargs(
             {"{username}__iexact": credentials["username"]})
         user = User.objects.get(**lookup_kwargs)
     except (User.DoesNotExist, KeyError):
         return None
     else:
         try:
             if user.check_password(credentials["password"]):
                 return user
         except KeyError:
             return None
    def authenticate(self, request, username=None, password=None, **kwargs):
        if username is None or password is None:
            return None

        User = get_user_model()
        try:
            lookup_kwargs = get_user_lookup_kwargs(
                {"{username}__iexact": username})
            user = User.objects.get(**lookup_kwargs)
        except User.DoesNotExist:
            return None

        if user.check_password(password):
            return user
Exemple #9
0
 def clean_username(self):
     if not alnum_re.search(self.cleaned_data["username"]):
         raise forms.ValidationError(
             _("Usernames can only contain letters, numbers and underscores."
               ))
     User = get_user_model()
     lookup_kwargs = get_user_lookup_kwargs(
         {"{username}__iexact": self.cleaned_data["username"]})
     qs = User.objects.filter(**lookup_kwargs)
     if not qs.exists():
         return self.cleaned_data["username"]
     raise forms.ValidationError(
         _("Este nome de usuário já está sendo utilizado. Por favor escolha um outro."
           ))
Exemple #10
0
    def clean_username(self):
        alnum_re = re.compile(r"^\w+$")
        if not alnum_re.search(self.cleaned_data["username"]):
            raise forms.ValidationError(_("Usernames can only contain letters, numbers and underscores."))
        User = get_user_model()
        lookup_kwargs = get_user_lookup_kwargs({
            "{username}__iexact": self.cleaned_data["username"]
        })
        qs = User.objects.filter(**lookup_kwargs)

        # TODO: Uncomment below lines when unique constraint on auth_user.username is resolved
        # ids = [user['id'] for user in qs.values()]
        # site = get_current_site(self.request)
        # prof = Profile.objects.filter(id__in=ids, site_id=site.id)

        if not qs.exists():
            return self.cleaned_data["username"]
        raise forms.ValidationError(_("This username is already taken. Please choose another."))
Exemple #11
0
    def clean_username(self):
        alnum_re = re.compile(r"^\w+$")
        if not alnum_re.search(self.cleaned_data["username"]):
            raise forms.ValidationError(
                _("Usernames can only contain letters, numbers and underscores."
                  ))
        User = get_user_model()
        lookup_kwargs = get_user_lookup_kwargs(
            {"{username}__iexact": self.cleaned_data["username"]})
        qs = User.objects.filter(**lookup_kwargs)

        # TODO: Uncomment below lines when unique constraint on auth_user.username is resolved
        # ids = [user['id'] for user in qs.values()]
        # site = get_current_site(self.request)
        # prof = Profile.objects.filter(id__in=ids, site_id=site.id)

        if not qs.exists():
            return self.cleaned_data["username"]
        raise forms.ValidationError(
            _("This username is already taken. Please choose another."))
Exemple #12
0
 def authenticate(self, request, **credentials):
     User = get_user_model()
     print "user:"******"{username}__iexact": credentials["username"]
         })
         user = User.objects.get(**lookup_kwargs)
     except (User.DoesNotExist, KeyError):
         return None
     else:
         try:
             profile = Profile.objects.get(user=user.id)
             print "profile:"
             print profile
             if user.check_password(credentials["password"]) and profile.site_id == current_site.id:
                 return user
         except KeyError:
             return None
 def authenticate(self, **credentials):
     User = get_user_model()
     if email_re.search(credentials["username"]):
         qs = EmailAddress.objects.filter(Q(primary=True) | Q(verified=True))
         try:
             email_address = qs.get(email__iexact=credentials["username"])
         except (EmailAddress.DoesNotExist, KeyError):
             return None
         else:
             user = email_address.user
     else:
         lookup_kwargs = get_user_lookup_kwargs({"{username}__iexact": credentials["username"]})
         try:
             user = User.objects.get(**lookup_kwargs)
         except (User.DoesNotExist, KeyError):
             return None
     try:
         if user.check_password(credentials["password"]):
             return user
     except KeyError:
         return None
Exemple #14
0
 def authenticate(self, request, **credentials):
     User = get_user_model()
     print "user:"******"{username}__iexact": credentials["username"]})
         user = User.objects.get(**lookup_kwargs)
     except (User.DoesNotExist, KeyError):
         return None
     else:
         try:
             profile = Profile.objects.get(user=user.id)
             print "profile:"
             print profile
             if user.check_password(
                     credentials["password"]
             ) and profile.site_id == current_site.id:
                 return user
         except KeyError:
             return None