user is not getting authenticated when i try to login.
this my register code
def register(request):
if request.method == "POST":
username = request.POST["name"]
email = request.POST["email"]
password = request.POST["password"]
password2 = request.POST["password2"]
try:
if password2 != password:
messages.error(request, "password did'nt match")
elif User.objects.get(email=email):
messages.error(request, "user already exists")
except:
if email and username:
user = User.objects.create_user(username=username, email=email)
user.set_password(password)
user.save()
messages.success(request, "user created")
else:
messages.error(request, "Looks like user already exists")
return render(request, 'register.html', {})
this if my login code if i am using user.object.get for email and check_password for password it,s working but when i am using authenticate it,s not working . printing authenticate is returning None
def login(request):
if request.method == "POST":
email = request.POST["email"]
password = request.POST["password"]
print email
print password
try:
user = authenticate(email=email , password=password)
if user is not None:
login(request, user)
return redirect('dashbord')
else:
messages.error(request, "password yesn't match")
except:
messages.error(request, "login fail plz check ur password or email again")
return render(request, 'login.html', {})
elif User.objects.get(email=email):
will raise an error in case theUser
does not yet exists. – Willem Van Onsemdid'nt,yesn't, plz
) in your error messages, this is getting out of hand. – scharette