Check email and password from custom database tables in django
I am creating a website for my college where a student can register and login , the data will be stored in my custom table 'studentlogin'.
I am already collecting and storing user data in my database table but now I am stuck on how to compare this data to check if the email and password is correct or not
I found this solution from somewhere
add "django.core.context_processors.request" in your context processors in settings.py
def loginView(request):
# after checking if the user is active, exists and passwword matches
request.session["isLoggedIn"] = True
request.session["username"] = request.POST.get("username")
and
{% if request.session.isLoggedIn %}
{{request.session.username}}
{% else if not request.session.isLoggedIn %}
<p>User not in session or logged off</p>
{% endif %}
but I am confused where to put this code !?
I suppose the first code block is to be add in my studentlogin view in views.py?
Is this what you want?:
from django.contrib import auth
user = auth.authenticate(email=email, password=password)
if user is not None:
auth.login(request, user)
# do whatever you want here
else:
# when credentials are not right...