Advertisement
Guest User

Untitled

a guest
Mar 4th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. def AuthentificationPost(request):
  2. form = AuthentificationForm(request.POST)
  3. if form.is_valid():
  4. email = form.cleaned_data['email']
  5. password = form.cleaned_data['password']
  6.  
  7. user = authenticate(username=email, password=password)
  8. if user is None:
  9. response = u'Не верный логин или пароль.'
  10. return HttpResponse(json.dumps({'error': response, 'result': 'error'}))
  11. else:
  12. login(request, user)
  13. user.save()
  14. return HttpResponse(json.dumps({'result': 'success'}))
  15. else:
  16. errors = {}
  17. for i in form.errors:
  18. errors[i] = form.errors[i][0]
  19. return HttpResponse(json.dumps({'errors': errors, 'result': 'error'}))
  20.  
  21. def AuthentificationPost(request):
  22. if request.method == 'GET':
  23. return HttpResponse(get_token(request))
  24. else:
  25. form = AuthentificationForm(request.POST)
  26. if form.is_valid():
  27. email = form.cleaned_data['email']
  28. password = form.cleaned_data['password']
  29.  
  30. user = authenticate(username=email, password=password)
  31. if user is None:
  32. response = u'Не верный логин или пароль.'
  33. return HttpResponse(json.dumps({'error': response, 'result': 'error'}))
  34. else:
  35. login(request, user)
  36. user.save()
  37. return HttpResponse(json.dumps({'result': 'success'}))
  38. else:
  39. errors = {}
  40. for i in form.errors:
  41. errors[i] = form.errors[i][0]
  42. return HttpResponse(json.dumps({'errors': errors, 'result': 'error'}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement