Login Session

7 views
Skip to first unread message

Denis Bahati

unread,
Nov 6, 2009, 6:29:37 AM11/6/09
to django...@googlegroups.com
Hi All
Am using my own table to let users login to my django site. I don like to use django admin page, there fore i have created my model and a model form to register users so that they can login using their username and password.

How can i utilize my function below so that every page is authenticated using this file?

def mlogin(request):
    m = User.objects.get(username=request.POST['username'])
    if m.password == request.POST['password']:
        request.session['member_id'] = m.id
        #return HttpResponse("You're logged in.")
        return HttpResponseRedirect("/commTrack/")
    else:
        return HttpResponse("Your username and password didn't match.")


Or is there any script i can use? I have tried authenticating using the AUTHENTICATION_BACKENDS but i didn't get it working. May be if there is one to guide me on how i can set it.
Thanks in advance.
Regards
Denis

Rama Vadakattu

unread,
Nov 7, 2009, 7:26:20 AM11/7/09
to Django users
You can simple use inbuilt user authentication provided by django.
What problem are you facing with it?


Any way if you are interested in building your own authentication
engine you need to do the following:
you can do this in several way one way is
1) Store cookie in user browser (you can store the user id (or) you
can give unique session id to this user and store relevant information
in the backend database)
like :
userid ============> sessionid
2) write down your middleware to check whether the request is bringing
any cookie associated with it or not.
if yes pull the sessionid and associate the request with this user
if no means no user has logged in.


--rama
Reply all
Reply to author
Forward
0 new messages