def credentials_required(view_func):
@wraps(view_func, assigned=available_attrs(view_func))<EOL>def decorator(request, *args, **kwargs):<EOL><INDENT>if settings.LOCALSHOP_USE_PROXIED_IP:<EOL><INDENT>try:<EOL><INDENT>ip_addr = request.META['<STR_LIT>']<EOL><DEDENT>except KeyError:<EOL><INDENT>return HttpResponseForbidden('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>ip_addr = ip_addr.split("<STR_LIT:U+002C>")[<NUM_LIT:0>].strip()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>ip_addr = request.META['<STR_LIT>']<EOL><DEDENT>if CIDR.objects.has_access(ip_addr, with_credentials=False):<EOL><INDENT>return view_func(request, *args, **kwargs)<EOL><DEDENT>if not CIDR.objects.has_access(ip_addr, with_credentials=True):<EOL><INDENT>return HttpResponseForbidden('<STR_LIT>')<EOL><DEDENT>if request.user.is_authenticated():<EOL><INDENT>return view_func(request, *args, **kwargs)<EOL><DEDENT>user = authenticate_user(request)<EOL>if user is not None:<EOL><INDENT>login(request, user)<EOL>return view_func(request, *args, **kwargs)<EOL><DEDENT>return HttpResponseUnauthorized(content='<STR_LIT>')<EOL><DEDENT>return decorator<EOL>
This decorator should be used with views that need simple authentication
against Django's authentication framework.