I'm trying to log users in with django authenticate. It returns nothing even when the email and password are correct. It just reloads the page and doesn't do anything. I have checked and the email and password I used are stored in the database, so the account exist but login doesn't do anything. I am using django 2.
Views.py
def signup(request):
if request.method == "POST":
firstname = request.POST.get('firstname')
lastname = request.POST.get('lastname')
email = request.POST.get('email')
password = request.POST.get('password')
passwordagain = request.POST.get('passwordagain')
areacode = request.POST.get('areacode')
number = request.POST.get('number')
userdetails = CustomUser(firstname=firstname,lastname=lastname,email=email,password=password, areacode=areacode, number=number)
userdetails.save()
return render(request, 'main/accountconfirmationpage.html')
else:
return render(request,'main/signup.html')
def login(request):
email=request.POST.get('email')
password=request.POST.get('password')
user = authenticate(request, email=email, password=password)
if user is not None:
if user.is_active:
login(request, user)
return render(request,'main/dashboard.html')
else:
return render(request, 'main/login.html')
from django.db import models
Models.py
# Create your models here.
class CustomUser(models.Model):
firstname = models.CharField(max_length=30)
lastname = models.CharField(max_length=30)
email = models.EmailField(max_length=30)
password = models.CharField(max_length=100)
areacode = models.CharField(max_length=4)
number = models.CharField(max_length=30)