Opened 9 years ago

Closed 9 years ago

#25770 closed Bug (invalid)

authenticate and login can not write cookie 'sessionid'

Reported by: mrgaolei Owned by: nobody
Component: contrib.auth Version: 1.8
Severity: Normal Keywords: authenticate login session
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If I use 'django.contrib.auth.urls' login, everything are OK, cookie 'sessionid' writes to Browser.

But, when I login Manually, like:

from django.contrib.auth import authenticate, login, logout
def some_view(request):
    user = authenticate(username="mrgaolei", password="123456")
    if user is not None:
        login(request, user)

No any exceptions, but user not loginged, and no cookie 'sessionid' writes to Browser.
My settings.py is generated by manage.py startproject.

I tried capture login status like:

from django.contrib.auth import authenticate, login, logout
def some_view(request):
    print request.user.is_authenticated()
    user = authenticate(username="mrgaolei", password="123456")
    if user is not None:
        login(request, user)
        print request.user.is_authenticated()

When I refresh this url, terminal output:

False
True

It seems the 'login' method writes the 'sessionid` cookie expire only 1 second.
Is this a bug? Or my fault?

Change History (2)

comment:1 by mrgaolei, 9 years ago

Is my fault!
I don't return any HttpResponse, so the status of HTTP is not 2xx or 3xx, so any session operation are rollback.

comment:2 by mrgaolei, 9 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top