0

Well, I have written the following code to make a login functionality at backend using django 1.10 and mongoengine 0.9.0 (MongoDB),here is the code:

@csrf_exempt
def check_auth(request):
   csrf_dict = {}
   csrf_dict.update(csrf(request))
   username = json.loads(request.body)['username']
   password = json.loads(request.body)['pwd']
   try:
     user = User.objects.get(username=username)
     if user.check_password(password):
        user.backend = 'mongoengine.django.auth.MongoEngineBackend'
        user = authenticate(username=username, password=password)
        login(request, user)
        request.session.set_expiry(60 * 60 * 1)
        user_id = str(user.pk)
        print HttpResponse.status_code
        if request.POST.has_key('next'):
            return redirect(request.POST['next'])
        else:
            return redirect('/dashboard/home')
    else:
        return redirect('/dashboard/login')
except DoesNotExist:
    return redirect('/dashboard/login')

response code is 200, but it is not redirecting page to home, instead it is giving me the error:

[04/Feb/2017 06:00:05] "POST /dashboard/check_auth HTTP/1.1" 302 0
[2017-02-04 06:00:05,223] - Broken pipe from ('127.0.0.1', 57124)

Please suggest to resolve this issue.

Ripundeep Gill
  • 231
  • 5
  • 18
  • Have a look at this related question: https://stackoverflow.com/questions/7912672/django-broken-pipe-in-debug-mode – Pierz Dec 08 '17 at 15:51

1 Answers1

0

Can you debug the code line by line,

"import pdb; pdb.set_trace()"
Cadmus
  • 665
  • 7
  • 13