示例#1
0
def auth(request):
    if (request.method == 'GET') and request.user.is_authenticated:
        # If the user is already authenticated we want to return the user data (required for oauth).
        return HttpResponse(JSONRenderer().render(
            UserDataSerializer(request.user, context={
                'request': request
            }).data),
                            content_type="application/json",
                            status=200)
    elif getattr(settings, "LDAP_SERVER_URI",
                 getattr(settings, "DJANGO_MODEL_LOGIN")):
        if request.method == 'POST':
            """Logs out user"""
            auth_logout(request)
            username = request.POST.get('username')
            password = request.POST.get('password')
            user_data = authenticate(username=username, password=password)
            if user_data is None:
                return HttpResponse(status=401)
            else:
                login(request, user_data)
                set_session_user_last_active_at(request)
                return HttpResponse(JSONRenderer().render(
                    UserDataSerializer(user_data, context={
                        'request': request
                    }).data),
                                    content_type="application/json",
                                    status=200)
        if request.method == 'GET':
            # We want to return a 200 so that the frontend can decide if the auth endpoint is valid for displaying the
            # the login form.
            return HttpResponse(status=200)
    else:
        return HttpResponse(status=400)
示例#2
0
def get_invalid_licenses(job, user=None):
    """
    :param user: A user to verify licenses against.
    :param job: The job containing the licensed datasets.
    :return: A list of invalid licenses.
    """
    from eventkit_cloud.api.serializers import UserDataSerializer
    user = user or job.user
    licenses = UserDataSerializer.get_user_accepted_licenses(user)
    invalid_licenses = []
    for provider_tasks in job.provider_tasks.all():
        license = provider_tasks.provider.license
        if license and not licenses.get(license.slug):
            invalid_licenses += [license.name]
    return invalid_licenses
示例#3
0
def get_invalid_licenses(job, user=None):
    """
    :param user: A user to verify licenses against.
    :param job: The job containing the licensed datasets.
    :return: A list of invalid licenses.
    """
    from eventkit_cloud.api.serializers import UserDataSerializer
    user = user or job.user
    licenses = UserDataSerializer.get_user_accepted_licenses(user)
    invalid_licenses = []
    for provider_tasks in job.provider_tasks.all():
        license = provider_tasks.provider.license
        if license and not licenses.get(license.slug):
            invalid_licenses += [license.name]
    return invalid_licenses