custom User model and login()

42 views
Skip to first unread message

Anil Jangity

unread,
Nov 11, 2012, 1:08:47 PM11/11/12
to django...@googlegroups.com
I am trying to build a User model with a dedicated LDAP backend. I have no SQL database.

def login(request):
...
login(request, user)
request.user.is_authenticated() ---> return True
return HttpResponseRedirect("/manage")

def manage(request):
print request.user.is_authenticated() --> returns False

Shouldn't the manage() show the user being authenticated?
What exactly happens when I do a login() call? Does it store some sessions somewhere? If so, what can I do in my custom User model to make it save this session?

Thanks,
Anil



Russell Keith-Magee

unread,
Nov 11, 2012, 6:53:23 PM11/11/12
to django...@googlegroups.com
Django logins are handled by a session, and sessions are saved by the Session middleware when the response is passed back to the client. Django's builtin login call returns a response that sets the new session for the logged in user; however, you're throwing away that information and returning your own response, so the session isn't being saved.

If you want to persist the session, you'll need to pull the relevant session keys over from the response returned by the login call, and attach them to the redirect response (or find some other sequence of events that will let you get to the manage view).

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages