Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.contrib.auth.forms import AuthenticationForm as BaseAuthenticationForm
- from django.contrib.auth.models import User
- from inc.models import Account, UserProfile, Counter
- class AuthenticationForm(BaseAuthenticationForm):
- def clean(self):
- username = self.cleaned_data.get('username')
- user = User.objects.filter(username = username).first()
- if user != None:
- print(user)
- if not user.is_superuser and not user.is_staff:
- account = Account.objects.filter(num_account = UserProfile.objects.filter(user__username = username).first().num_account).first()
- have_counter = Counter.objects.filter(num_account = account).all()
- if not have_counter:
- raise forms.ValidationError('Some text...')
- return self.cleaned_data
- from django.contrib.auth import login, authenticate
- from .forms import AuthenticationForm
- def LogIn(request):
- if request.method == 'POST':
- form = AuthenticationForm(data=request.POST)
- if form.is_valid():
- username = form.cleaned_data.get('username')
- password = form.cleaned_data.get('password')
- user = authenticate(username=username, password=password)
- print(user)
- login(request, user)
- return redirect('/')
- else:
- print(form.errors)
- else:
- form = AuthenticationForm()
- return render(request, 'userprocessing/login.html', {'form': form})
- AnonymousUser' object has no attribute '_meta'
Add Comment
Please, Sign In to add comment