I have written the following class for Auth Back end and placed it inside a file "authentication.py" inside the app directory:
from events.models import User
class authBackend():
def authenticate(self, request, username, passwprd):
try:
user = User.objects.get(rollNo=username)
success = user.check_password(password)
if success:
return user
except User.DoesNotExist:
pass
return None
def get_user(self, uid):
try:
return User.objects.get(pk=Uid)
except:
return None
then i added (or at least i thought i did) it to settings.py:
AUTHENTICATION_BACKENDS = [
'events.authentication'
]
this is how i am logging in the user:
def login_view(request):
if request.method == "POST":
# Attempt to sign user in
rollno = request.POST["rollno"]
password = request.POST["password"]
user = authenticate(request, username=rollno, password=password)
# Check if authentication successful
if user is not None:
login(request, user)
return HttpResponseRedirect(reverse("events:index"))
else:
return render(request, "events/login.html", {
"message": "Invalid roll number and/or password."
})
else:
return render(request, "events/login.html")
But i am getting the following trace back:
ImportError at /login Module "events" does not define a "authentication" attribute/class
I am a noob and i am pretty sure i am doing something wrong, i just don't understand what it is.
Can someone please tell me how to do it right?