Ejemplo n.º 1
0
 def clean_email_or_login(self):
     data = self.cleaned_data['email_or_login']
     try:
         if '@' in data:
             self.user = User.objects.get(email=data)
         else:
             self.user = User.objects.get(username=data)
     except Exception as e:
         raise forms.ValidationError(
             'A user with such email or username does not exist')
     return self.cleaned_data['email_or_login']
Ejemplo n.º 2
0
    def clean(self):
        if 'username' in self.cleaned_data and 'password' in self.cleaned_data:
            username = self.cleaned_data['username']
            if not '@' in username:
                user = authenticate(username=username,
                                    password=self.cleaned_data['password'])
            else:
                user = authenticate(email=username,
                                    password=self.cleaned_data['password'])
            if not user:
                raise forms.ValidationError('Email or password are incorrect')
        else:
            return None

        self.user = user
        return user
Ejemplo n.º 3
0
 def clean_email(self):
     if User.objects.filter(email=self.cleaned_data['email']).count() > 0:
         raise forms.ValidationError(
             'A user with such email is already registered')
     return self.cleaned_data['email']
Ejemplo n.º 4
0
 def clean_username(self):
     if User.objects.filter(
             username=self.cleaned_data['username']).count() > 0:
         raise forms.ValidationError(
             'A user with such username is already registered')
     return self.cleaned_data['username']