hi, anyone help me with user authentication, i am unable to authenticate a user after signup, it let me login in admin site but as a normal user i am unable to login in website, sorry for the code i am unable to proper indent here.
if request.method == "POST":
fm = AuthenticationForm(request=request, data=request.POST)
if fm.is_valid():
username = fm.cleaned_data.get('username')
password = fm.cleaned_data.get('password')
user = authenticate(request,username=username, password=password)
if user is not None:
login(request, user)
return redirect('/jobseekersprofile/')
else:
fm = AuthenticationForm()
return render(request, 'jobglobel/userlogin.html', {'form': fm})```
done thanx, do you have any idea what problem could be ?, i am unable to authenticate any normal user in website, when do login in admin site it allows to do login in admin site.
from django.shortcuts import redirect, render
from .forms import jobglobeluserform
from .models import jobglobeluser
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import authenticate,login,logout,views
from django.contrib.auth.decorators import login_required
def userlogin(request):
if request.method == "POST":
fm = AuthenticationForm(request=request, data=request.POST)
if fm.is_valid():
username = fm.cleaned_data.get('username')
password = fm.cleaned_data.get('password')
user = authenticate(request,username=username, password=password)
if user is not None:
login(request, user)
return redirect('/jobseekersprofile/')
else:
fm = AuthenticationForm()
return render(request, 'jobglobel/userlogin.html', {'form': fm})```
FORM I HAVE USED INBUILT FORM DJANGO ' AuthenticationForm()' As you can see in views.py
FOR Template I have Posted Earlier. You Can check it above.
I would use the Django shell to try that authenticate function call with the username and password that you are trying, to verify that the password is valid.
password is same as i kept while creating user for testing purpose., as normal user it is not allowing me to do login, but if i create superuser and do login in admin site, it is working.