Example #1
0
File: forms.py Project: ccosse/gimu
 def clean_username(self):
     if not alnum_re.search(self.cleaned_data["username"].replace('.', '')):
         raise forms.ValidationError(_("Usernames can only contain letters, numbers, dots 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."))
Example #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 the following special 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."))
Example #3
0
 def clean_username(self):
     if not alnum_re.search(self.cleaned_data["username"].replace('.', '')):
         raise forms.ValidationError(_("Usernames can only contain letters, numbers, dots 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."))
Example #4
0
 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
 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 
 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