예제 #1
0
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)
예제 #2
0
파일: auth.py 프로젝트: Laksh02/supportkid
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, )
예제 #3
0
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 {}
예제 #4
0
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,
        )