def login(request): form = AuthenticationForm(request, data=request.data) if form.is_valid(): auth.login(request, form.user_cache) return Response(AuthenticatedUserSerializer(form.user_cache).data) else: return Response(form.get_errors_dict(), status=status.HTTP_400_BAD_REQUEST)
def login(request): """ POST /auth/ with CSRF, username and password will attempt to authenticate new user """ serializer = LoginSerializer(request, data=request.data) serializer.is_valid(raise_exception=True) user = serializer.validated_data['user'] auth.login(request, user) return Response(AuthenticatedUserSerializer(user).data, )
def preload_user_json(request): request.frontend_context.update({ 'isAuthenticated': request.user.is_authenticated(), }) if request.user.is_authenticated(): request.frontend_context.update( {'user': AuthenticatedUserSerializer(request.user).data}) else: request.frontend_context.update( {'user': AnonymousUserSerializer(request.user).data}) return {}
def login(request): """ POST /auth/ with CSRF, username and password will attempt to authenticate new user """ form = AuthenticationForm(request, data=request.data) if form.is_valid(): auth.login(request, form.user_cache) return Response(AuthenticatedUserSerializer(form.user_cache).data, ) else: return Response( form.get_errors_dict(), status=status.HTTP_400_BAD_REQUEST, )